[PATCH v6 4/8] jscript: Lookup and ref the named item's dispatch first, during interpretion.

Gabriel Ivăncescu gabrielopcode at gmail.com
Sat Mar 7 07:40:34 CST 2020


Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
 dlls/jscript/dispex.c |  1 +
 dlls/jscript/engine.c | 19 +++++++++++++++++--
 dlls/jscript/engine.h |  1 +
 dlls/jscript/global.c |  4 +++-
 4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/dlls/jscript/dispex.c b/dlls/jscript/dispex.c
index e986de6..a0c8f38 100644
--- a/dlls/jscript/dispex.c
+++ b/dlls/jscript/dispex.c
@@ -1527,6 +1527,7 @@ static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lc
     }
 
     enter_script(This->ctx, &ei);
+    ei.script_obj = This;
 
     switch(wFlags) {
     case DISPATCH_METHOD|DISPATCH_PROPERTYGET:
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 5b96895..044e32c 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -669,6 +669,15 @@ static HRESULT identifier_eval(script_ctx_t *ctx, BSTR identifier, exprval_t *re
                 return S_OK;
             }
         }
+
+        if(ctx->call_ctx->bytecode->named_item) {
+            jsdisp_t *script_obj = ctx->call_ctx->bytecode->named_item->script_obj;
+            hres = jsdisp_get_id(script_obj, identifier, 0, &id);
+            if(SUCCEEDED(hres)) {
+                exprval_set_disp_ref(ret, to_disp(script_obj), id);
+                return S_OK;
+            }
+        }
     }
 
     hres = jsdisp_get_id(ctx->global, identifier, 0, &id);
@@ -1254,13 +1263,17 @@ static HRESULT interp_identifier_ref(script_ctx_t *ctx, BSTR identifier, unsigne
         return hres;
 
     if(exprval.type == EXPRVAL_INVALID && (flags & fdexNameEnsure)) {
+        jsdisp_t *script_obj = ctx->global;
         DISPID id;
 
-        hres = jsdisp_get_id(ctx->global, identifier, fdexNameEnsure, &id);
+        if(ctx->call_ctx->bytecode->named_item)
+            script_obj = ctx->call_ctx->bytecode->named_item->script_obj;
+
+        hres = jsdisp_get_id(script_obj, identifier, fdexNameEnsure, &id);
         if(FAILED(hres))
             return hres;
 
-        exprval_set_disp_ref(&exprval, to_disp(ctx->global), id);
+        exprval_set_disp_ref(&exprval, to_disp(script_obj), id);
     }
 
     if(exprval.type == EXPRVAL_JSVAL || exprval.type == EXPRVAL_INVALID) {
@@ -2995,6 +3008,8 @@ HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, functi
             hres = create_named_item_script_obj(ctx, bytecode->named_item);
             if(FAILED(hres)) return hres;
         }
+        if(variable_obj == ctx->global)
+            variable_obj = bytecode->named_item->script_obj;
     }
 
     if(!ctx->ei->enter_notified) {
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index fe6b2a0..4057f9c 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -233,6 +233,7 @@ struct _jsexcept_t {
     jsstr_t *message;
     jsstr_t *line;
 
+    jsdisp_t *script_obj;
     bytecode_t *code;
     unsigned loc;
 
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index 2a1dcb2..40fa951 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -181,6 +181,7 @@ HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned a
 {
     call_frame_t *frame = ctx->call_ctx;
     DWORD exec_flags = EXEC_EVAL;
+    jsdisp_t *context;
     bytecode_t *code;
     const WCHAR *src;
     HRESULT hres;
@@ -209,13 +210,14 @@ HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned a
         WARN("parse (%s) failed: %08x\n", debugstr_jsval(argv[0]), hres);
         return hres;
     }
+    context = frame ? frame->variable_obj : (ctx->ei->script_obj ? ctx->ei->script_obj : ctx->global);
 
     if(!frame || (frame->flags & EXEC_GLOBAL))
         exec_flags |= EXEC_GLOBAL;
     if(flags & DISPATCH_JSCRIPT_CALLEREXECSSOURCE)
         exec_flags |= EXEC_RETURN_TO_INTERP;
     hres = exec_source(ctx, exec_flags, code, &code->global_code, frame ? frame->scope : NULL,
-            frame ? frame->this_obj : NULL, NULL, frame ? frame->variable_obj : ctx->global, 0, NULL, r);
+            frame ? frame->this_obj : NULL, NULL, context, 0, NULL, r);
     release_bytecode(code);
     return hres;
 }
-- 
2.21.0




More information about the wine-devel mailing list