jscript: Lookup host global object on demand instead of storing it in script context.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Gabriel Ivăncescu 2020-03-06 15:48:39 +02:00 committed by Alexandre Julliard
parent fcba99c52e
commit acb076c820
6 changed files with 18 additions and 18 deletions

View file

@ -605,6 +605,21 @@ static BOOL lookup_global_members(script_ctx_t *ctx, BSTR identifier, exprval_t
return FALSE;
}
IDispatch *lookup_global_host(script_ctx_t *ctx)
{
IDispatch *disp = NULL;
named_item_t *item;
LIST_FOR_EACH_ENTRY(item, &ctx->named_items, named_item_t, entry) {
if(!(item->flags & SCRIPTITEM_GLOBALMEMBERS)) continue;
disp = item->disp;
break;
}
if(!disp) disp = to_disp(ctx->global);
return disp;
}
static int __cdecl local_ref_cmp(const void *key, const void *ref)
{
return wcscmp((const WCHAR*)key, ((const local_ref_t*)ref)->name);
@ -1223,7 +1238,7 @@ static HRESULT interp_this(script_ctx_t *ctx)
TRACE("\n");
if(!this_obj)
this_obj = ctx->host_global ? ctx->host_global : to_disp(ctx->global);
this_obj = lookup_global_host(ctx);
IDispatch_AddRef(this_obj);
return stack_push(ctx, jsval_disp(this_obj));

View file

@ -170,6 +170,7 @@ typedef struct _function_code_t {
bytecode_t *bytecode;
} function_code_t;
IDispatch *lookup_global_host(script_ctx_t*) DECLSPEC_HIDDEN;
local_ref_t *lookup_local(const function_code_t*,const WCHAR*) DECLSPEC_HIDDEN;
struct _bytecode_t {

View file

@ -612,10 +612,8 @@ static HRESULT NativeFunction_call(script_ctx_t *ctx, FunctionInstance *func, ID
if(this_disp)
set_disp(&vthis, this_disp);
else if(ctx->host_global)
set_disp(&vthis, ctx->host_global);
else
set_jsdisp(&vthis, ctx->global);
set_disp(&vthis, lookup_global_host(ctx));
hres = function->proc(ctx, &vthis, flags & ~DISPATCH_JSCRIPT_INTERNAL_MASK, argc, argv, r);

View file

@ -409,11 +409,6 @@ static void decrease_state(JScript *This, SCRIPTSTATE state)
case SCRIPTSTATE_INITIALIZED:
clear_script_queue(This);
if(This->ctx->host_global) {
IDispatch_Release(This->ctx->host_global);
This->ctx->host_global = NULL;
}
while(!list_empty(&This->ctx->named_items)) {
named_item_t *iter = LIST_ENTRY(list_head(&This->ctx->named_items), named_item_t, entry);
@ -820,11 +815,6 @@ static HRESULT WINAPI JScript_AddNamedItem(IActiveScript *iface,
WARN("object does not implement IDispatch\n");
return hres;
}
if(This->ctx->host_global)
IDispatch_Release(This->ctx->host_global);
IDispatch_AddRef(disp);
This->ctx->host_global = disp;
}
item = heap_alloc(sizeof(*item));

View file

@ -422,8 +422,6 @@ struct _script_ctx_t {
heap_pool_t tmp_heap;
IDispatch *host_global;
jsval_t *stack;
unsigned stack_size;
unsigned stack_top;

View file

@ -1394,7 +1394,6 @@ static void test_named_items(void)
SET_EXPECT(OnLeaveScript);
hr = IActiveScriptParse_ParseScriptText(parse, L"this", NULL, 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) == &global_named_item,
"Unexpected 'this': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var));
VariantClear(&var);
@ -1427,7 +1426,6 @@ static void test_named_items(void)
SET_EXPECT(OnLeaveScript);
hr = IActiveScriptParse_ParseScriptText(parse, L"globalCode_this", NULL, 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) == &global_named_item,
"Unexpected 'this': V_VT = %d, V_DISPATCH = %p\n", V_VT(&var), V_DISPATCH(&var));
VariantClear(&var);