Jacek Caban : jscript: Don' t leave current scope in return statement before evaluating the expression.

Alexandre Julliard julliard at winehq.org
Thu Sep 13 14:39:22 CDT 2012


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Sep 13 14:34:11 2012 +0200

jscript: Don't leave current scope in return statement before evaluating the expression.

---

 dlls/jscript/compile.c     |   33 +++++++++++++++++++++------------
 dlls/jscript/tests/lang.js |    7 +++++++
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index e45b132..034a55d 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -1287,25 +1287,30 @@ static HRESULT compile_forin_statement(compiler_ctx_t *ctx, forin_statement_t *s
     return S_OK;
 }
 
-static HRESULT pop_to_stat(compiler_ctx_t *ctx, statement_ctx_t *stat_ctx)
+static HRESULT pop_to_stat(compiler_ctx_t *ctx, BOOL var_stack, BOOL scope_stack, statement_ctx_t *stat_ctx)
 {
     unsigned stack_pop = 0;
     statement_ctx_t *iter;
 
     for(iter = ctx->stat_ctx; iter != stat_ctx; iter = iter->next) {
-        if(iter->using_scope && !push_instr(ctx, OP_pop_scope))
-            return E_OUTOFMEMORY;
-        if(iter->using_except && !push_instr(ctx, OP_pop_except))
-            return E_OUTOFMEMORY;
+        if(scope_stack) {
+            if(iter->using_scope && !push_instr(ctx, OP_pop_scope))
+                return E_OUTOFMEMORY;
+            if(iter->using_except && !push_instr(ctx, OP_pop_except))
+                return E_OUTOFMEMORY;
+        }
         stack_pop += iter->stack_use;
     }
 
-    /* FIXME: optimize */
-    while(stack_pop--) {
-        if(!push_instr(ctx, OP_pop))
-            return E_OUTOFMEMORY;
+    if(var_stack) {
+        /* FIXME: optimize */
+        while(stack_pop--) {
+            if(!push_instr(ctx, OP_pop))
+                return E_OUTOFMEMORY;
+        }
     }
 
+
     return S_OK;
 }
 
@@ -1353,7 +1358,7 @@ static HRESULT compile_continue_statement(compiler_ctx_t *ctx, branch_statement_
         }
     }
 
-    hres = pop_to_stat(ctx, pop_ctx);
+    hres = pop_to_stat(ctx, TRUE, TRUE, pop_ctx);
     if(FAILED(hres))
         return hres;
 
@@ -1393,7 +1398,7 @@ static HRESULT compile_break_statement(compiler_ctx_t *ctx, branch_statement_t *
         }
     }
 
-    hres = pop_to_stat(ctx, pop_ctx->next);
+    hres = pop_to_stat(ctx, TRUE, TRUE, pop_ctx->next);
     if(FAILED(hres))
         return hres;
 
@@ -1408,7 +1413,7 @@ static HRESULT compile_return_statement(compiler_ctx_t *ctx, expression_statemen
 {
     HRESULT hres;
 
-    hres = pop_to_stat(ctx, NULL);
+    hres = pop_to_stat(ctx, TRUE, FALSE, NULL);
     if(FAILED(hres))
         return hres;
 
@@ -1418,6 +1423,10 @@ static HRESULT compile_return_statement(compiler_ctx_t *ctx, expression_statemen
             return hres;
     }
 
+    hres = pop_to_stat(ctx, FALSE, TRUE, NULL);
+    if(FAILED(hres))
+        return hres;
+
     return push_instr(ctx, OP_ret) ? S_OK : E_OUTOFMEMORY;
 }
 
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index dbb9d50..ffb5e2e 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -1355,6 +1355,13 @@ ok(name_override_func === 3, "name_override_func = " + name_override_func);
 function name_override_func() {};
 ok(name_override_func === 3, "name_override_func = " + name_override_func);
 
+tmp = (function() {
+    var ret = false;
+    with({ret: true})
+        return ret;
+})();
+ok(tmp, "tmp = " + tmp);
+
 /* NoNewline rule parser tests */
 while(true) {
     if(true) break




More information about the wine-cvs mailing list