Jacek Caban : jscript: Clear stack outside OP_new handler.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Mar 29 08:53:21 CDT 2016


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Mar 28 17:49:10 2016 +0200

jscript: Clear stack outside OP_new handler.

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

---

 dlls/jscript/compile.c | 10 +++++++++-
 dlls/jscript/engine.c  | 31 +++++++++++++++++++++++--------
 dlls/jscript/engine.h  |  1 +
 3 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index 9d135f8..03a9bdc 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -558,7 +558,15 @@ static HRESULT compile_new_expression(compiler_ctx_t *ctx, call_expression_t *ex
         arg_cnt++;
     }
 
-    return push_instr_uint(ctx, OP_new, arg_cnt);
+    hres = push_instr_uint(ctx, OP_new, arg_cnt);
+    if(FAILED(hres))
+        return hres;
+
+    hres = push_instr_uint(ctx, OP_pop, arg_cnt+1);
+    if(FAILED(hres))
+        return hres;
+
+    return push_instr(ctx, OP_push_ret) ? S_OK : E_OUTOFMEMORY;
 }
 
 static HRESULT compile_call_expression(compiler_ctx_t *ctx, call_expression_t *expr, BOOL emit_ret)
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index a4e8de6..314a35b 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -201,6 +201,11 @@ static inline jsval_t steal_ret(call_frame_t *frame)
     return r;
 }
 
+static inline void clear_ret(call_frame_t *frame)
+{
+    jsval_release(steal_ret(frame));
+}
+
 static void exprval_release(exprval_t *val)
 {
     switch(val->type) {
@@ -941,8 +946,8 @@ static HRESULT interp_refval(script_ctx_t *ctx)
 static HRESULT interp_new(script_ctx_t *ctx)
 {
     const unsigned argc = get_op_uint(ctx, 0);
-    jsval_t r, constr;
-    HRESULT hres;
+    call_frame_t *frame = ctx->call_ctx;
+    jsval_t constr;
 
     TRACE("%d\n", argc);
 
@@ -957,12 +962,9 @@ static HRESULT interp_new(script_ctx_t *ctx)
     else if(!get_object(constr))
         return throw_type_error(ctx, JS_E_INVALID_PROPERTY, NULL);
 
-    hres = disp_call_value(ctx, get_object(constr), NULL, DISPATCH_CONSTRUCT, argc, stack_args(ctx, argc), &r);
-    if(FAILED(hres))
-        return hres;
-
-    stack_popn(ctx, argc+1);
-    return stack_push(ctx, r);
+    clear_ret(frame);
+    return disp_call_value(ctx, get_object(constr), NULL, DISPATCH_CONSTRUCT,
+                           argc, stack_args(ctx, argc), &frame->ret);
 }
 
 /* ECMA-262 3rd Edition    11.2.3 */
@@ -2353,6 +2355,19 @@ static HRESULT interp_setret(script_ctx_t *ctx)
     return S_OK;
 }
 
+static HRESULT interp_push_ret(script_ctx_t *ctx)
+{
+    call_frame_t *frame = ctx->call_ctx;
+    HRESULT hres;
+
+    TRACE("\n");
+
+    hres = stack_push(ctx, frame->ret);
+    if(SUCCEEDED(hres))
+        frame->ret = jsval_undefined();
+    return hres;
+}
+
 typedef HRESULT (*op_func_t)(script_ctx_t*);
 
 static const op_func_t op_funcs[] = {
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index 3af3eac..7c26667 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -70,6 +70,7 @@
     X(postinc,    1, ARG_INT,    0)        \
     X(preinc,     1, ARG_INT,    0)        \
     X(push_except,1, ARG_ADDR,   ARG_BSTR) \
+    X(push_ret,   1, 0,0)                  \
     X(push_scope, 1, 0,0)                  \
     X(regexp,     1, ARG_STR,    ARG_UINT) \
     X(rshift,     1, 0,0)                  \




More information about the wine-cvs mailing list