[PATCH v4 2/4] jscript: Lookup host global object on demand instead of storing it in script context.
Gabriel Ivăncescu
gabrielopcode at gmail.com
Mon Mar 2 07:38:59 CST 2020
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
dlls/jscript/engine.c | 21 +++++++++++++++++----
dlls/jscript/engine.h | 1 +
dlls/jscript/function.c | 4 +---
dlls/jscript/jscript.c | 10 ----------
dlls/jscript/jscript.h | 2 --
5 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 7da8f70..9a87b9f 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);
@@ -2700,7 +2715,7 @@ static void print_backtrace(script_ctx_t *ctx)
WARN("%u\t", depth);
depth++;
- if(frame->this_obj && frame->this_obj != to_disp(ctx->global) && frame->this_obj != ctx->host_global)
+ if(frame->this_obj && frame->this_obj != to_disp(ctx->global) && frame->this_obj != lookup_global_host(ctx))
WARN("%p->", frame->this_obj);
WARN("%s(", frame->function->name ? debugstr_w(frame->function->name) : "[unnamed]");
if(frame->base_scope && frame->base_scope->frame) {
@@ -3057,10 +3072,8 @@ HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, functi
frame->stack_base = ctx->stack_top;
if(this_obj)
frame->this_obj = this_obj;
- else if(ctx->host_global)
- frame->this_obj = ctx->host_global;
else
- frame->this_obj = to_disp(ctx->global);
+ frame->this_obj = lookup_global_host(ctx);
IDispatch_AddRef(frame->this_obj);
if(function_instance)
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;
--
2.21.0
More information about the wine-devel
mailing list