jscript: Don't lookup global variables on function invocation.
This commit is contained in:
parent
95469309d6
commit
35968b9755
|
@ -179,7 +179,7 @@ void scope_release(scope_chain_t *scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT create_exec_ctx(script_ctx_t *script_ctx, IDispatch *this_obj, jsdisp_t *var_disp,
|
HRESULT create_exec_ctx(script_ctx_t *script_ctx, IDispatch *this_obj, jsdisp_t *var_disp,
|
||||||
scope_chain_t *scope, exec_ctx_t **ret)
|
scope_chain_t *scope, BOOL is_global, exec_ctx_t **ret)
|
||||||
{
|
{
|
||||||
exec_ctx_t *ctx;
|
exec_ctx_t *ctx;
|
||||||
|
|
||||||
|
@ -188,6 +188,7 @@ HRESULT create_exec_ctx(script_ctx_t *script_ctx, IDispatch *this_obj, jsdisp_t
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
ctx->ref = 1;
|
ctx->ref = 1;
|
||||||
|
ctx->is_global = is_global;
|
||||||
|
|
||||||
if(this_obj)
|
if(this_obj)
|
||||||
ctx->this_obj = this_obj;
|
ctx->this_obj = this_obj;
|
||||||
|
@ -410,7 +411,7 @@ static BOOL lookup_global_members(script_ctx_t *ctx, BSTR identifier, exprval_t
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *source, exec_type_t exec_type,
|
HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *source, BOOL from_eval,
|
||||||
jsexcept_t *ei, VARIANT *retv)
|
jsexcept_t *ei, VARIANT *retv)
|
||||||
{
|
{
|
||||||
script_ctx_t *script = parser->script;
|
script_ctx_t *script = parser->script;
|
||||||
|
@ -447,7 +448,7 @@ HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *so
|
||||||
if(!name)
|
if(!name)
|
||||||
return E_OUTOFMEMORY;
|
return E_OUTOFMEMORY;
|
||||||
|
|
||||||
if(!lookup_global_members(parser->script, name, NULL))
|
if(!ctx->is_global || !lookup_global_members(parser->script, name, NULL))
|
||||||
hres = jsdisp_get_id(ctx->var_disp, var->identifier, fdexNameEnsure, &id);
|
hres = jsdisp_get_id(ctx->var_disp, var->identifier, fdexNameEnsure, &id);
|
||||||
SysFreeString(name);
|
SysFreeString(name);
|
||||||
if(FAILED(hres))
|
if(FAILED(hres))
|
||||||
|
@ -489,14 +490,10 @@ HRESULT exec_source(exec_ctx_t *ctx, parser_ctx_t *parser, source_elements_t *so
|
||||||
return hres;
|
return hres;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(retv && (exec_type == EXECT_EVAL || rt.type == RT_RETURN))
|
if(!retv || (!from_eval && rt.type != RT_RETURN))
|
||||||
*retv = val;
|
|
||||||
else {
|
|
||||||
if (retv) {
|
|
||||||
VariantInit(retv);
|
|
||||||
}
|
|
||||||
VariantClear(&val);
|
VariantClear(&val);
|
||||||
}
|
if(retv)
|
||||||
|
*retv = val;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,7 @@ struct _exec_ctx_t {
|
||||||
scope_chain_t *scope_chain;
|
scope_chain_t *scope_chain;
|
||||||
jsdisp_t *var_disp;
|
jsdisp_t *var_disp;
|
||||||
IDispatch *this_obj;
|
IDispatch *this_obj;
|
||||||
|
BOOL is_global;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void exec_addref(exec_ctx_t *ctx)
|
static inline void exec_addref(exec_ctx_t *ctx)
|
||||||
|
@ -109,15 +110,9 @@ static inline void exec_addref(exec_ctx_t *ctx)
|
||||||
ctx->ref++;
|
ctx->ref++;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
EXECT_PROGRAM,
|
|
||||||
EXECT_FUNCTION,
|
|
||||||
EXECT_EVAL
|
|
||||||
} exec_type_t;
|
|
||||||
|
|
||||||
void exec_release(exec_ctx_t*);
|
void exec_release(exec_ctx_t*);
|
||||||
HRESULT create_exec_ctx(script_ctx_t*,IDispatch*,jsdisp_t*,scope_chain_t*,exec_ctx_t**);
|
HRESULT create_exec_ctx(script_ctx_t*,IDispatch*,jsdisp_t*,scope_chain_t*,BOOL,exec_ctx_t**);
|
||||||
HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,exec_type_t,jsexcept_t*,VARIANT*);
|
HRESULT exec_source(exec_ctx_t*,parser_ctx_t*,source_elements_t*,BOOL,jsexcept_t*,VARIANT*);
|
||||||
|
|
||||||
typedef struct _statement_t statement_t;
|
typedef struct _statement_t statement_t;
|
||||||
typedef struct _expression_t expression_t;
|
typedef struct _expression_t expression_t;
|
||||||
|
|
|
@ -209,7 +209,7 @@ static HRESULT invoke_source(script_ctx_t *ctx, FunctionInstance *function, IDis
|
||||||
|
|
||||||
hres = scope_push(function->scope_chain, var_disp, &scope);
|
hres = scope_push(function->scope_chain, var_disp, &scope);
|
||||||
if(SUCCEEDED(hres)) {
|
if(SUCCEEDED(hres)) {
|
||||||
hres = create_exec_ctx(ctx, this_obj, var_disp, scope, &exec_ctx);
|
hres = create_exec_ctx(ctx, this_obj, var_disp, scope, FALSE, &exec_ctx);
|
||||||
scope_release(scope);
|
scope_release(scope);
|
||||||
}
|
}
|
||||||
jsdisp_release(var_disp);
|
jsdisp_release(var_disp);
|
||||||
|
@ -218,7 +218,7 @@ static HRESULT invoke_source(script_ctx_t *ctx, FunctionInstance *function, IDis
|
||||||
|
|
||||||
prev_args = function->arguments;
|
prev_args = function->arguments;
|
||||||
function->arguments = arg_disp;
|
function->arguments = arg_disp;
|
||||||
hres = exec_source(exec_ctx, function->parser, function->source, EXECT_FUNCTION, ei, retv);
|
hres = exec_source(exec_ctx, function->parser, function->source, FALSE, ei, retv);
|
||||||
function->arguments = prev_args;
|
function->arguments = prev_args;
|
||||||
|
|
||||||
jsdisp_release(arg_disp);
|
jsdisp_release(arg_disp);
|
||||||
|
|
|
@ -371,7 +371,7 @@ static HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DIS
|
||||||
return throw_syntax_error(ctx, ei, hres, NULL);
|
return throw_syntax_error(ctx, ei, hres, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
hres = exec_source(ctx->exec_ctx, parser_ctx, parser_ctx->source, EXECT_EVAL, ei, retv);
|
hres = exec_source(ctx->exec_ctx, parser_ctx, parser_ctx->source, TRUE, ei, retv);
|
||||||
parser_release(parser_ctx);
|
parser_release(parser_ctx);
|
||||||
|
|
||||||
return hres;
|
return hres;
|
||||||
|
|
|
@ -97,14 +97,14 @@ static HRESULT exec_global_code(JScript *This, parser_ctx_t *parser_ctx)
|
||||||
jsexcept_t jsexcept;
|
jsexcept_t jsexcept;
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
hres = create_exec_ctx(This->ctx, NULL, This->ctx->global, NULL, &exec_ctx);
|
hres = create_exec_ctx(This->ctx, NULL, This->ctx->global, NULL, TRUE, &exec_ctx);
|
||||||
if(FAILED(hres))
|
if(FAILED(hres))
|
||||||
return hres;
|
return hres;
|
||||||
|
|
||||||
IActiveScriptSite_OnEnterScript(This->site);
|
IActiveScriptSite_OnEnterScript(This->site);
|
||||||
|
|
||||||
memset(&jsexcept, 0, sizeof(jsexcept));
|
memset(&jsexcept, 0, sizeof(jsexcept));
|
||||||
hres = exec_source(exec_ctx, parser_ctx, parser_ctx->source, EXECT_PROGRAM, &jsexcept, NULL);
|
hres = exec_source(exec_ctx, parser_ctx, parser_ctx->source, FALSE, &jsexcept, NULL);
|
||||||
VariantClear(&jsexcept.var);
|
VariantClear(&jsexcept.var);
|
||||||
exec_release(exec_ctx);
|
exec_release(exec_ctx);
|
||||||
|
|
||||||
|
|
|
@ -1214,11 +1214,17 @@ static void run_tests(void)
|
||||||
parse_script_a("var testPropGet");
|
parse_script_a("var testPropGet");
|
||||||
CHECK_CALLED(global_propget_d);
|
CHECK_CALLED(global_propget_d);
|
||||||
|
|
||||||
|
SET_EXPECT(global_propget_d);
|
||||||
|
parse_script_a("eval('var testPropGet;');");
|
||||||
|
CHECK_CALLED(global_propget_d);
|
||||||
|
|
||||||
SET_EXPECT(global_notexists_d);
|
SET_EXPECT(global_notexists_d);
|
||||||
parse_script_a("var notExists; notExists = 1;");
|
parse_script_a("var notExists; notExists = 1;");
|
||||||
CHECK_CALLED(global_notexists_d);
|
CHECK_CALLED(global_notexists_d);
|
||||||
|
|
||||||
parse_script_a("function f() { var testPropGet; }");
|
parse_script_a("function f() { var testPropGet; }");
|
||||||
|
parse_script_a("(function () { var testPropGet; })();");
|
||||||
|
parse_script_a("(function () { eval('var testPropGet;'); })();");
|
||||||
|
|
||||||
parse_script_a("ok((testObj instanceof Object) === false, 'testObj is instance of Object');");
|
parse_script_a("ok((testObj instanceof Object) === false, 'testObj is instance of Object');");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue