diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c index e45b132881f..034a55d8d1f 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 dbb9d50d2df..ffb5e2ec28f 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