Gabriel Ivăncescu : jscript: Get rid of the variable_obj parameter to exec_source.

Alexandre Julliard julliard at winehq.org
Tue Mar 17 17:21:11 CDT 2020


Module: wine
Branch: master
Commit: 7ad740cd29c6bd87238df6231689b861058bc5a8
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=7ad740cd29c6bd87238df6231689b861058bc5a8

Author: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Date:   Tue Mar 17 19:19:25 2020 +0100

jscript: Get rid of the variable_obj parameter to exec_source.

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   | 32 ++++++++++++++++++++++++--------
 dlls/jscript/engine.h   |  2 +-
 dlls/jscript/function.c | 11 +++--------
 dlls/jscript/global.c   |  2 +-
 dlls/jscript/jscript.c  |  6 +++---
 5 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index db0863c902..8914e760ed 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -2990,8 +2990,9 @@ static HRESULT setup_scope(script_ctx_t *ctx, call_frame_t *frame, scope_chain_t
 }
 
 HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, function_code_t *function, scope_chain_t *scope,
-        IDispatch *this_obj, jsdisp_t *function_instance, jsdisp_t *variable_obj, unsigned argc, jsval_t *argv, jsval_t *r)
+        IDispatch *this_obj, jsdisp_t *function_instance, unsigned argc, jsval_t *argv, jsval_t *r)
 {
+    jsdisp_t *variable_obj;
     call_frame_t *frame;
     unsigned i;
     HRESULT hres;
@@ -3024,6 +3025,15 @@ HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, functi
             return hres;
     }
 
+    if((flags & EXEC_EVAL) && ctx->call_ctx) {
+        variable_obj = jsdisp_addref(ctx->call_ctx->variable_obj);
+    }else if(!(flags & (EXEC_GLOBAL | EXEC_EVAL))) {
+        hres = create_dispex(ctx, NULL, NULL, &variable_obj);
+        if(FAILED(hres)) return hres;
+    }else {
+        variable_obj = jsdisp_addref(ctx->global);
+    }
+
     if(flags & (EXEC_GLOBAL | EXEC_EVAL)) {
         BOOL lookup_globals = (flags & EXEC_GLOBAL) && !bytecode->named_item;
 
@@ -3034,7 +3044,7 @@ HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, functi
 
                 hres = create_source_function(ctx, bytecode, function->funcs+function->variables[i].func_id, scope, &func_obj);
                 if(FAILED(hres))
-                    return hres;
+                    goto fail;
 
                 hres = jsdisp_propput_name(variable_obj, function->variables[i].name, jsval_obj(func_obj));
                 jsdisp_release(func_obj);
@@ -3043,7 +3053,7 @@ HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, functi
 
                 hres = jsdisp_get_id(variable_obj, function->variables[i].name, fdexNameEnsure, &id);
                 if(FAILED(hres))
-                    return hres;
+                    goto fail;
             }
         }
     }
@@ -3063,12 +3073,14 @@ HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, functi
     if(ctx->call_ctx && (flags & EXEC_EVAL)) {
         hres = detach_variable_object(ctx, ctx->call_ctx, FALSE);
         if(FAILED(hres))
-            return hres;
+            goto fail;
     }
 
     frame = heap_alloc_zero(sizeof(*frame));
-    if(!frame)
-        return E_OUTOFMEMORY;
+    if(!frame) {
+        hres = E_OUTOFMEMORY;
+        goto fail;
+    }
 
     frame->function = function;
     frame->ret = jsval_undefined();
@@ -3080,7 +3092,7 @@ HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, functi
         if(FAILED(hres)) {
             release_bytecode(frame->bytecode);
             heap_free(frame);
-            return hres;
+            goto fail;
         }
     }else if(scope) {
         frame->base_scope = frame->scope = scope_addref(scope);
@@ -3097,7 +3109,7 @@ HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, functi
         frame->function_instance = jsdisp_addref(function_instance);
 
     frame->flags = flags;
-    frame->variable_obj = jsdisp_addref(variable_obj);
+    frame->variable_obj = variable_obj;
 
     frame->prev_frame = ctx->call_ctx;
     ctx->call_ctx = frame;
@@ -3113,4 +3125,8 @@ HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, functi
     }
 
     return enter_bytecode(ctx, r);
+
+fail:
+    jsdisp_release(variable_obj);
+    return hres;
 }
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index fe6b2a06d0..2a8e405a28 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -281,7 +281,7 @@ typedef struct _call_frame_t {
 #define EXEC_EVAL              0x0008
 
 HRESULT exec_source(script_ctx_t*,DWORD,bytecode_t*,function_code_t*,scope_chain_t*,IDispatch*,
-        jsdisp_t*,jsdisp_t*,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
+        jsdisp_t*,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
 
 HRESULT create_source_function(script_ctx_t*,bytecode_t*,function_code_t*,scope_chain_t*,jsdisp_t**) DECLSPEC_HIDDEN;
 HRESULT setup_arguments_object(script_ctx_t*,call_frame_t*) DECLSPEC_HIDDEN;
diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c
index 007aec0370..caca274a49 100644
--- a/dlls/jscript/function.c
+++ b/dlls/jscript/function.c
@@ -722,7 +722,7 @@ static HRESULT InterpretedFunction_call(script_ctx_t *ctx, FunctionInstance *fun
          unsigned argc, jsval_t *argv, jsval_t *r)
 {
     InterpretedFunction *function = (InterpretedFunction*)func;
-    jsdisp_t *var_disp, *new_obj = NULL;
+    jsdisp_t *new_obj = NULL;
     DWORD exec_flags = 0;
     HRESULT hres;
 
@@ -744,15 +744,10 @@ static HRESULT InterpretedFunction_call(script_ctx_t *ctx, FunctionInstance *fun
         exec_flags |= EXEC_RETURN_TO_INTERP;
     if(flags & DISPATCH_CONSTRUCT)
         exec_flags |= EXEC_CONSTRUCTOR;
-
-    hres = create_dispex(ctx, NULL, NULL, &var_disp);
-    if(SUCCEEDED(hres))
-        hres = exec_source(ctx, exec_flags, function->code, function->func_code, function->scope_chain, this_obj,
-                           &function->function.dispex, var_disp, argc, argv, r);
+    hres = exec_source(ctx, exec_flags, function->code, function->func_code, function->scope_chain, this_obj,
+                       &function->function.dispex, argc, argv, r);
     if(new_obj)
         jsdisp_release(new_obj);
-
-    jsdisp_release(var_disp);
     return hres;
 }
 
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index 2a1dcb2b84..64b910faa7 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -215,7 +215,7 @@ HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned a
     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, 0, NULL, r);
     release_bytecode(code);
     return hres;
 }
diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c
index aabad7ef8b..f54c34ab5a 100644
--- a/dlls/jscript/jscript.c
+++ b/dlls/jscript/jscript.c
@@ -408,7 +408,7 @@ static void exec_queued_code(JScript *This)
 
     LIST_FOR_EACH_ENTRY(iter, &This->queued_code, bytecode_t, entry) {
         enter_script(This->ctx, &ei);
-        hres = exec_source(This->ctx, EXEC_GLOBAL, iter, &iter->global_code, NULL, NULL, NULL, This->ctx->global, 0, NULL, NULL);
+        hres = exec_source(This->ctx, EXEC_GLOBAL, iter, &iter->global_code, NULL, NULL, NULL, 0, NULL, NULL);
         leave_script(This->ctx, hres);
         if(FAILED(hres))
             break;
@@ -1053,7 +1053,7 @@ static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface,
     if(dwFlags & SCRIPTTEXT_ISEXPRESSION) {
         jsval_t r;
 
-        hres = exec_source(This->ctx, EXEC_GLOBAL, code, &code->global_code, NULL, NULL, NULL, This->ctx->global, 0, NULL, &r);
+        hres = exec_source(This->ctx, EXEC_GLOBAL, code, &code->global_code, NULL, NULL, NULL, 0, NULL, &r);
         if(SUCCEEDED(hres)) {
             if(pvarResult)
                 hres = jsval_to_variant(r, pvarResult);
@@ -1072,7 +1072,7 @@ static HRESULT WINAPI JScriptParse_ParseScriptText(IActiveScriptParse *iface,
     if(!pvarResult && !is_started(This->ctx)) {
         list_add_tail(&This->queued_code, &code->entry);
     }else {
-        hres = exec_source(This->ctx, EXEC_GLOBAL, code, &code->global_code, NULL, NULL, NULL, This->ctx->global, 0, NULL, NULL);
+        hres = exec_source(This->ctx, EXEC_GLOBAL, code, &code->global_code, NULL, NULL, NULL, 0, NULL, NULL);
         if(code->is_persistent)
             list_add_tail(&This->persistent_code, &code->entry);
         else




More information about the wine-cvs mailing list