diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index c74aa75a744..15f71bd3f50 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -295,7 +295,7 @@ void scope_release(scope_chain_t *scope) heap_free(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, jsdisp_t *var_disp, BOOL is_global, exec_ctx_t **ret) { exec_ctx_t *ctx; @@ -308,26 +308,6 @@ HRESULT create_exec_ctx(script_ctx_t *script_ctx, IDispatch *this_obj, jsdisp_t ctx->is_global = is_global; ctx->ret = jsval_undefined(); - /* ECMA-262 3rd Edition 11.2.3.7 */ - if(this_obj) { - jsdisp_t *jsthis; - - jsthis = iface_to_jsdisp((IUnknown*)this_obj); - if(jsthis) { - if(jsthis->builtin_info->class == JSCLASS_GLOBAL || jsthis->builtin_info->class == JSCLASS_NONE) - this_obj = NULL; - jsdisp_release(jsthis); - } - } - - if(this_obj) - ctx->this_obj = this_obj; - else if(script_ctx->host_global) - ctx->this_obj = script_ctx->host_global; - else - ctx->this_obj = to_disp(script_ctx->global); - IDispatch_AddRef(ctx->this_obj); - jsdisp_addref(var_disp); ctx->var_disp = var_disp; @@ -345,8 +325,6 @@ void exec_release(exec_ctx_t *ctx) if(ctx->var_disp) jsdisp_release(ctx->var_disp); - if(ctx->this_obj) - IDispatch_Release(ctx->this_obj); if(ctx->script) script_release(ctx->script); jsval_release(ctx->ret); @@ -1067,13 +1045,12 @@ static HRESULT interp_call_member(script_ctx_t *ctx) /* ECMA-262 3rd Edition 11.1.1 */ static HRESULT interp_this(script_ctx_t *ctx) { - IDispatch *this_obj; + call_frame_t *frame = ctx->call_ctx; TRACE("\n"); - this_obj = ctx->call_ctx->exec_ctx->this_obj; - IDispatch_AddRef(this_obj); - return stack_push(ctx, jsval_disp(this_obj)); + IDispatch_AddRef(frame->this_obj); + return stack_push(ctx, jsval_disp(frame->this_obj)); } /* ECMA-262 3rd Edition 10.1.4 */ @@ -2413,6 +2390,8 @@ OP_LIST static void release_call_frame(call_frame_t *frame) { + if(frame->this_obj) + IDispatch_Release(frame->this_obj); if(frame->scope) scope_release(frame->scope); heap_free(frame); @@ -2556,10 +2535,23 @@ static HRESULT bind_event_target(script_ctx_t *ctx, function_code_t *func, jsdis return hres; } -static HRESULT setup_call_frame(exec_ctx_t *ctx, bytecode_t *bytecode, function_code_t *function, scope_chain_t *scope) +static HRESULT setup_call_frame(exec_ctx_t *ctx, bytecode_t *bytecode, function_code_t *function, scope_chain_t *scope, + IDispatch *this_obj) { call_frame_t *frame; + /* ECMA-262 3rd Edition 11.2.3.7 */ + if(this_obj) { + jsdisp_t *jsthis; + + jsthis = iface_to_jsdisp((IUnknown*)this_obj); + if(jsthis) { + if(jsthis->builtin_info->class == JSCLASS_GLOBAL || jsthis->builtin_info->class == JSCLASS_NONE) + this_obj = NULL; + jsdisp_release(jsthis); + } + } + frame = heap_alloc_zero(sizeof(*frame)); if(!frame) return E_OUTOFMEMORY; @@ -2572,6 +2564,14 @@ static HRESULT setup_call_frame(exec_ctx_t *ctx, bytecode_t *bytecode, function_ if(scope) frame->base_scope = frame->scope = scope_addref(scope); + if(this_obj) + frame->this_obj = this_obj; + else if(ctx->script->host_global) + frame->this_obj = ctx->script->host_global; + else + frame->this_obj = to_disp(ctx->script->global); + IDispatch_AddRef(frame->this_obj); + frame->exec_ctx = ctx; frame->prev_frame = ctx->script->call_ctx; @@ -2579,7 +2579,8 @@ static HRESULT setup_call_frame(exec_ctx_t *ctx, bytecode_t *bytecode, function_ return S_OK; } -HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, scope_chain_t *scope, jsval_t *ret) +HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, scope_chain_t *scope, + IDispatch *this_obj, jsval_t *ret) { jsval_t val; unsigned i; @@ -2614,7 +2615,7 @@ HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, sc } } - hres = setup_call_frame(ctx, code, func, scope); + hres = setup_call_frame(ctx, code, func, scope, this_obj); if(FAILED(hres)) return hres; diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h index 6c738ebe888..cd4051f26be 100644 --- a/dlls/jscript/engine.h +++ b/dlls/jscript/engine.h @@ -198,6 +198,8 @@ typedef struct _call_frame_t { scope_chain_t *scope; scope_chain_t *base_scope; + IDispatch *this_obj; + bytecode_t *bytecode; function_code_t *function; @@ -210,7 +212,6 @@ struct _exec_ctx_t { script_ctx_t *script; jsdisp_t *var_disp; - IDispatch *this_obj; BOOL is_global; jsval_t ret; @@ -222,6 +223,6 @@ static inline void exec_addref(exec_ctx_t *ctx) } void exec_release(exec_ctx_t*) DECLSPEC_HIDDEN; -HRESULT create_exec_ctx(script_ctx_t*,IDispatch*,jsdisp_t*,BOOL,exec_ctx_t**) DECLSPEC_HIDDEN; -HRESULT exec_source(exec_ctx_t*,bytecode_t*,function_code_t*,scope_chain_t*,jsval_t*) DECLSPEC_HIDDEN; +HRESULT create_exec_ctx(script_ctx_t*,jsdisp_t*,BOOL,exec_ctx_t**) DECLSPEC_HIDDEN; +HRESULT exec_source(exec_ctx_t*,bytecode_t*,function_code_t*,scope_chain_t*,IDispatch*,jsval_t*) DECLSPEC_HIDDEN; HRESULT create_source_function(script_ctx_t*,bytecode_t*,function_code_t*,scope_chain_t*,jsdisp_t**) DECLSPEC_HIDDEN; diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c index 2c378b3fb84..05792bd29d0 100644 --- a/dlls/jscript/function.c +++ b/dlls/jscript/function.c @@ -239,13 +239,13 @@ static HRESULT invoke_source(script_ctx_t *ctx, FunctionInstance *function, IDis hres = scope_push(function->scope_chain, var_disp, to_disp(var_disp), &scope); if(SUCCEEDED(hres)) { - hres = create_exec_ctx(ctx, this_obj, var_disp, FALSE, &exec_ctx); + hres = create_exec_ctx(ctx, var_disp, FALSE, &exec_ctx); if(SUCCEEDED(hres)) { jsdisp_t *prev_args; prev_args = function->arguments; function->arguments = arg_disp; - hres = exec_source(exec_ctx, function->code, function->func_code, scope, r); + hres = exec_source(exec_ctx, function->code, function->func_code, scope, this_obj, r); function->arguments = prev_args; exec_release(exec_ctx); diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c index ec3e355e42a..5574f504f5e 100644 --- a/dlls/jscript/global.c +++ b/dlls/jscript/global.c @@ -223,7 +223,7 @@ static HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns return throw_syntax_error(ctx, hres, NULL); } - hres = exec_source(ctx->call_ctx->exec_ctx, code, &code->global_code, frame->scope, r); + hres = exec_source(ctx->call_ctx->exec_ctx, code, &code->global_code, frame->scope, frame->this_obj, r); release_bytecode(code); return hres; } diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c index c5c7705ee74..3dda22c17f1 100644 --- a/dlls/jscript/jscript.c +++ b/dlls/jscript/jscript.c @@ -105,14 +105,14 @@ static HRESULT exec_global_code(JScript *This, bytecode_t *code) exec_ctx_t *exec_ctx; HRESULT hres; - hres = create_exec_ctx(This->ctx, NULL, This->ctx->global, TRUE, &exec_ctx); + hres = create_exec_ctx(This->ctx, This->ctx->global, TRUE, &exec_ctx); if(FAILED(hres)) return hres; IActiveScriptSite_OnEnterScript(This->site); clear_ei(This->ctx); - hres = exec_source(exec_ctx, code, &code->global_code, NULL, NULL); + hres = exec_source(exec_ctx, code, &code->global_code, NULL, NULL, NULL); exec_release(exec_ctx); IActiveScriptSite_OnLeaveScript(This->site); @@ -776,14 +776,14 @@ static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface, if(dwFlags & SCRIPTTEXT_ISEXPRESSION) { exec_ctx_t *exec_ctx; - hres = create_exec_ctx(This->ctx, NULL, This->ctx->global, TRUE, &exec_ctx); + hres = create_exec_ctx(This->ctx, This->ctx->global, TRUE, &exec_ctx); if(SUCCEEDED(hres)) { jsval_t r; IActiveScriptSite_OnEnterScript(This->site); clear_ei(This->ctx); - hres = exec_source(exec_ctx, code, &code->global_code, NULL, &r); + hres = exec_source(exec_ctx, code, &code->global_code, NULL, NULL, &r); if(SUCCEEDED(hres)) { if(pvarResult) hres = jsval_to_variant(r, pvarResult);