Пример #1
0
/*****************************Run First Task*********************************/
static void JsContextTask(struct JsEngine* e,void* data){

	struct JsAstNode* ast = NULL;
	struct JsValue v;
	ast = JsParseFile(JS_PARSER_DEBUG_ERROR,NULL);
	if(ast == NULL)
		printf("language error\n");
	else
		JsEval(e,ast,&v);
}
Пример #2
0
/*
	相当于把string字符串放置在当前环境下执行.
*/
static	void JsGlobalEval(struct JsObject *self, struct JsObject *thisobj, int argc, struct JsValue **argv, struct JsValue *res) {

    int saveVarattr;
    //检查参数是否正确
    if(argc <=0) {
        res->type =JS_UNDEFINED;
        return;
    } else  if( argv[0]->type != JS_STRING) {
        *res = *argv[0];
        return;
    }

    //从线程中获得JsEngine
    struct JsEngine* e = JsGetTlsEngine();

    //处理上下文
    /*Stack, Scope, This 都使用当前Context*/
    saveVarattr = e->exec->varattr;
    e->exec->varattr = JS_OBJECT_ATTR_DEFAULT;


    //执行函数
    res->type =JS_UNDEFINED;
    struct JsAstNode * ast;
    ast = JsParseString(e->vm->debug ? JS_PARSER_DEBUG_ERROR
                        : JS_PARSER_DEBUG_CLOSE,argv[0]->u.string);
    if(ast == NULL)
        JsThrowString("SytaxError");
    JsEval(e,ast,res);
    //还原环境
    e->exec->varattr = saveVarattr;

    //结果处理
    if(res->type == JS_COMPLETION) {

        if(res->u.completion.type == JS_COMPLETION_RETURN) {
            *res = *res->u.completion.value;
        } else if(res->u.completion.type == JS_COMPLETION_THROW) {
            //不处理
        } else {
            //JS_COMPLETION_NORMAL, JS_COMPLETION_BREAK, JS_COMPLETION_CONTINUE
            res->type = JS_UNDEFINED;
        }
    } else if(res->type == JS_REFERENCE) {
        res->type = JS_UNDEFINED;
    }//res->type = JS_OBJECT, JS_NULL, JS_BOOLEAN ...
    return;

}