Jacek Caban : jscript: Fixed empty cases in the end of switch statement.

Alexandre Julliard julliard at winehq.org
Tue Sep 4 12:38:37 CDT 2012


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Tue Sep  4 15:52:27 2012 +0200

jscript: Fixed empty cases in the end of switch statement.

---

 dlls/jscript/compile.c     |   20 ++++++++++++++------
 dlls/jscript/tests/lang.js |   26 ++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index f3c1df1..e45b132 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -1540,18 +1540,26 @@ static HRESULT compile_switch_statement(compiler_ctx_t *ctx, switch_statement_t
 
         set_arg_uint(ctx, iter->expr ? case_jmps[i++] : default_jmp, ctx->code_off);
 
-        for(stat_iter = iter->stat; stat_iter && (!iter->next || iter->next->stat != stat_iter); stat_iter = stat_iter->next) {
-            hres = compile_statement(ctx, &stat_ctx, stat_iter);
+        if(iter->stat) {
+            for(stat_iter = iter->stat; stat_iter && (!iter->next || iter->next->stat != stat_iter);
+                stat_iter = stat_iter->next) {
+                hres = compile_statement(ctx, &stat_ctx, stat_iter);
+                if(FAILED(hres))
+                    break;
+
+                if(stat_iter->next && !push_instr(ctx, OP_pop)) {
+                    hres = E_OUTOFMEMORY;
+                    break;
+                }
+            }
             if(FAILED(hres))
                 break;
-
-            if(stat_iter->next && !push_instr(ctx, OP_pop)) {
+        }else {
+            if(!push_instr(ctx, OP_undefined)) {
                 hres = E_OUTOFMEMORY;
                 break;
             }
         }
-        if(FAILED(hres))
-            break;
     }
 
     heap_free(case_jmps);
diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js
index 26a28b8..cb127da 100644
--- a/dlls/jscript/tests/lang.js
+++ b/dlls/jscript/tests/lang.js
@@ -757,6 +757,32 @@ case 3:
     ok(false, "unexpected case 3");
 }
 
+switch(1) {
+case 2:
+    ok(false, "unexpected case 2");
+    break;
+default:
+    /* empty default */
+}
+
+switch(2) {
+default:
+    ok(false, "unexpected default");
+    break;
+case 2:
+    /* empty case */
+};
+
+switch(2) {
+default:
+    ok(false, "unexpected default");
+    break;
+case 1:
+case 2:
+case 3:
+    /* empty case */
+};
+
 (function() {
     var i=0;
 




More information about the wine-cvs mailing list