From c2402a92ae1cb068ae871d5224b5b44381ccdd81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Iv=C4=83ncescu?= Date: Wed, 11 Mar 2020 15:06:30 +0200 Subject: [PATCH] jscript: Retrieve the proper 'this' object for bytecodes with named items. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gabriel Ivăncescu Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/jscript/engine.c | 10 ++++++++-- dlls/jscript/tests/jscript.c | 3 --- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index 5a627ea2bef..db0863c9024 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -1237,8 +1237,14 @@ static HRESULT interp_this(script_ctx_t *ctx) TRACE("\n"); - if(!this_obj) - this_obj = lookup_global_host(ctx); + if(!this_obj) { + named_item_t *item = ctx->call_ctx->bytecode->named_item; + + if(item) + this_obj = (item->flags & SCRIPTITEM_CODEONLY) ? to_disp(item->script_obj) : item->disp; + else + this_obj = lookup_global_host(ctx); + } IDispatch_AddRef(this_obj); return stack_push(ctx, jsval_disp(this_obj)); diff --git a/dlls/jscript/tests/jscript.c b/dlls/jscript/tests/jscript.c index ed56f8ce11b..284390b8604 100644 --- a/dlls/jscript/tests/jscript.c +++ b/dlls/jscript/tests/jscript.c @@ -1252,7 +1252,6 @@ static void test_named_items(void) SET_EXPECT(OnLeaveScript); hr = IActiveScriptParse_ParseScriptText(parse, L"this", L"visibleCodeItem", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr); - todo_wine ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == disp, "Unexpected 'this': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var)); VariantClear(&var); @@ -1413,7 +1412,6 @@ static void test_named_items(void) SET_EXPECT(OnLeaveScript); hr = IActiveScriptParse_ParseScriptText(parse, L"this", L"visibleItem", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr); - todo_wine ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == &visible_named_item, "Unexpected 'this': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var)); VariantClear(&var); @@ -1424,7 +1422,6 @@ static void test_named_items(void) SET_EXPECT(OnLeaveScript); hr = IActiveScriptParse_ParseScriptText(parse, L"this", L"codeOnlyItem", NULL, NULL, 0, 0, SCRIPTTEXT_ISEXPRESSION, &var, NULL); ok(hr == S_OK, "ParseScriptText failed: %08x\n", hr); - todo_wine ok(V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) == (IDispatch*)dispex2, "Unexpected 'this': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var)); VariantClear(&var);