Gabriel Ivăncescu : jscript: Lookup host global object on demand instead of storing it in script context.
Alexandre Julliard
julliard at winehq.org
Fri Mar 6 16:38:41 CST 2020
Module: wine
Branch: master
Commit: acb076c820dcacd41126f75373ec6019768e42e7
URL: https://source.winehq.org/git/wine.git/?a=commit;h=acb076c820dcacd41126f75373ec6019768e42e7
Author: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Date: Fri Mar 6 15:48:39 2020 +0200
jscript: Lookup host global object on demand instead of storing it in script context.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/jscript/engine.c | 17 ++++++++++++++++-
dlls/jscript/engine.h | 1 +
dlls/jscript/function.c | 4 +---
dlls/jscript/jscript.c | 10 ----------
dlls/jscript/jscript.h | 2 --
dlls/jscript/tests/jscript.c | 2 --
6 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 3946d02da2..ce7fbbc572 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -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));
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index cad46e12c5..7be98c51db 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -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 {
diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c
index baa5eb10d7..ef0de960ff 100644
--- a/dlls/jscript/function.c
+++ b/dlls/jscript/function.c
@@ -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);
diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c
index b878aa5e2d..36d9f84d32 100644
--- a/dlls/jscript/jscript.c
+++ b/dlls/jscript/jscript.c
@@ -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));
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 7f34b55973..f9d6992704 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -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;
diff --git a/dlls/jscript/tests/jscript.c b/dlls/jscript/tests/jscript.c
index a7dfd11347..8d4f6e1673 100644
--- a/dlls/jscript/tests/jscript.c
+++ b/dlls/jscript/tests/jscript.c
@@ -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);
More information about the wine-cvs
mailing list