Jacek Caban : jscript: Keep track of active call in a separated structure.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Mar 25 10:00:38 CDT 2016


Module: wine
Branch: master
Commit: 8a17cf89fb0c78888855afd20cc2ebf05a1a351e
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=8a17cf89fb0c78888855afd20cc2ebf05a1a351e

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Mar 25 12:02:35 2016 +0100

jscript: Keep track of active call in a separated structure.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/jscript/engine.c  | 40 ++++++++++++++++++++++++++++++++--------
 dlls/jscript/engine.h  |  5 +++++
 dlls/jscript/global.c  |  4 ++--
 dlls/jscript/jscript.h |  2 +-
 4 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index 214d8fe..8d42962 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -511,8 +511,8 @@ static HRESULT identifier_eval(script_ctx_t *ctx, BSTR identifier, exprval_t *re
 
     TRACE("%s\n", debugstr_w(identifier));
 
-    if(ctx->exec_ctx) {
-        for(scope = ctx->exec_ctx->scope_chain; scope; scope = scope->next) {
+    if(ctx->call_ctx) {
+        for(scope = ctx->call_ctx->exec_ctx->scope_chain; scope; scope = scope->next) {
             if(scope->jsobj)
                 hres = jsdisp_get_id(scope->jsobj, identifier, fdexNameImplicit, &id);
             else
@@ -2393,6 +2393,11 @@ OP_LIST
 #undef X
 };
 
+static void release_call_frame(call_frame_t *frame)
+{
+    heap_free(frame);
+}
+
 static HRESULT unwind_exception(exec_ctx_t *ctx)
 {
     except_frame_t *except_frame;
@@ -2446,17 +2451,19 @@ static HRESULT unwind_exception(exec_ctx_t *ctx)
 
 static HRESULT enter_bytecode(script_ctx_t *ctx, bytecode_t *code, function_code_t *func, jsval_t *ret)
 {
-    exec_ctx_t *exec_ctx = ctx->exec_ctx;
+    exec_ctx_t *exec_ctx = ctx->call_ctx->exec_ctx;
     except_frame_t *prev_except_frame;
     function_code_t *prev_func;
     unsigned prev_ip, prev_top;
     scope_chain_t *prev_scope;
     bytecode_t *prev_code;
+    call_frame_t *frame;
     jsop_t op;
     HRESULT hres = S_OK;
 
     TRACE("\n");
 
+    frame = ctx->call_ctx;
     prev_top = exec_ctx->top;
     prev_scope = exec_ctx->scope_chain;
     prev_except_frame = exec_ctx->except_frame;
@@ -2490,6 +2497,10 @@ static HRESULT enter_bytecode(script_ctx_t *ctx, bytecode_t *code, function_code
     exec_ctx->code = prev_code;
     exec_ctx->func_code = prev_func;
 
+    assert(ctx->call_ctx == frame);
+    ctx->call_ctx = frame->prev_frame;
+    release_call_frame(frame);
+
     if(FAILED(hres)) {
         while(exec_ctx->scope_chain != prev_scope)
             scope_pop(&exec_ctx->scope_chain);
@@ -2543,9 +2554,23 @@ static HRESULT bind_event_target(script_ctx_t *ctx, function_code_t *func, jsdis
     return hres;
 }
 
+static HRESULT setup_call_frame(exec_ctx_t *ctx)
+{
+    call_frame_t *frame;
+
+    frame = heap_alloc_zero(sizeof(*frame));
+    if(!frame)
+        return E_OUTOFMEMORY;
+
+    frame->exec_ctx = ctx;
+
+    frame->prev_frame = ctx->script->call_ctx;
+    ctx->script->call_ctx = frame;
+    return S_OK;
+}
+
 HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, jsval_t *ret)
 {
-    exec_ctx_t *prev_ctx;
     jsval_t val;
     unsigned i;
     HRESULT hres = S_OK;
@@ -2579,12 +2604,11 @@ HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, js
         }
     }
 
-    prev_ctx = ctx->script->exec_ctx;
-    ctx->script->exec_ctx = ctx;
+    hres = setup_call_frame(ctx);
+    if(FAILED(hres))
+        return hres;
 
     hres = enter_bytecode(ctx->script, code, func, &val);
-    assert(ctx->script->exec_ctx == ctx);
-    ctx->script->exec_ctx = prev_ctx;
     if(FAILED(hres))
         return hres;
 
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index 3943c9a..81316f7 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -190,6 +190,11 @@ static inline void scope_addref(scope_chain_t *scope)
 typedef struct _except_frame_t except_frame_t;
 struct _parser_ctx_t;
 
+typedef struct _call_frame_t {
+    struct _call_frame_t *prev_frame;
+    exec_ctx_t *exec_ctx;
+} call_frame_t;
+
 struct _exec_ctx_t {
     LONG ref;
 
diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c
index 0755844..763868f 100644
--- a/dlls/jscript/global.c
+++ b/dlls/jscript/global.c
@@ -206,7 +206,7 @@ static HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
         return S_OK;
     }
 
-    if(!ctx->exec_ctx) {
+    if(!ctx->call_ctx) {
         FIXME("No active exec_ctx\n");
         return E_UNEXPECTED;
     }
@@ -222,7 +222,7 @@ static HRESULT JSGlobal_eval(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, uns
         return throw_syntax_error(ctx, hres, NULL);
     }
 
-    hres = exec_source(ctx->exec_ctx, code, &code->global_code, r);
+    hres = exec_source(ctx->call_ctx->exec_ctx, code, &code->global_code, r);
     release_bytecode(code);
     return hres;
 }
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 87f2e94..18be0c1 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -385,7 +385,7 @@ struct _script_ctx_t {
     SCRIPTSTATE state;
     IActiveScript *active_script;
 
-    exec_ctx_t *exec_ctx;
+    struct _call_frame_t *call_ctx;
     named_item_t *named_items;
     IActiveScriptSite *site;
     IInternetHostSecurityManager *secmgr;




More information about the wine-cvs mailing list