/*
Js:
	setHeader(String,String): 	是一个通用的标头设定方法,您可以用它来设定任何「名称/值」的标头.
	setStatus(Number):			状态码
	write(String) : 			写入返回文本
*/
struct JsObject* JsCreateResponse(struct MHD_Connection *connection){
	struct JsObject* b = JsAllocObject(JS_RESPONSE_FLOOR);
	JsCreateStandardObject(b);
	b->Class = "Response";
	
	//初始化自己的Sb
	struct JsResponse* p = (struct JsResponse*)malloc(sizeof(struct JsResponse));
	p->connection = connection;
	p->code = 200;
	
	p->bUsed = 0;
	p->bTotal = 128;
	p->body = calloc(sizeof(char),p->bTotal);
	
	p->hTotal = 2;
	p->hUsed = 0;
	p->header = (struct JsHeader* )calloc(sizeof(struct JsHeader) ,p->hTotal);
	
	
	b->sb[JS_RESPONSE_FLOOR] = p;
	//初始化Object方法函数
	JsInitResponse(b);
	return b;

}
Пример #2
0
static struct JsObject* JsCreateStringObject(struct JsObject* prototype,char* str){
	struct JsObject* string = JsAllocObject(JS_STRING_FLOOR);
	JsCreateStandardObject(string);
	string->Class = "String";
	string->Get = &JsStringInstGet;
	if(str == NULL)
		str = "";
	//初始化自己的Sb
	char* p = (char*)JsMalloc(strlen(str)+4);
	strcpy(p,str);
	string->sb[JS_STRING_FLOOR] = p;
	
	
	//length
	struct JsValue* vLength = (struct JsValue*)JsMalloc(sizeof(struct JsValue));
	vLength->type = JS_NUMBER;
	vLength->u.number = strlen(str);
	(*string->Put)(string,"length",vLength,JS_OBJECT_ATTR_STRICT);
	//为了能把length Put进去, 把prototype延迟放入.
	if(prototype != NULL)
		string->Prototype = prototype;
	return string;
	
}