[PATCH v5 2/9] jscript: Lookup host global object on demand instead of storing it in script context.

Gabriel Ivăncescu gabrielopcode at gmail.com
Fri Mar 6 07:48:39 CST 2020


Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
 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 3946d02..ce7fbbc 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 cad46e1..7be98c5 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 baa5eb1..ef0de96 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 b878aa5..36d9f84 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 7f34b55..f9d6992 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 a7dfd11..8d4f6e1 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);
-- 
2.21.0




More information about the wine-devel mailing list