From: Jacek Caban Subject: jscript: Fixed empty cases in the end of switch statement Message-Id: <5046079B.5030602@codeweavers.com> Date: Tue, 04 Sep 2012 15:52:27 +0200 --- 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;