Commit b7bb1667 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Simplify pop_to_stat implementation.

We no longer need to do stack pops before return expression evaluation. Signed-off-by: 's avatarJacek Caban <jacek@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent e705dfc2
...@@ -1383,22 +1383,20 @@ static HRESULT compile_forin_statement(compiler_ctx_t *ctx, forin_statement_t *s ...@@ -1383,22 +1383,20 @@ static HRESULT compile_forin_statement(compiler_ctx_t *ctx, forin_statement_t *s
return S_OK; return S_OK;
} }
static HRESULT pop_to_stat(compiler_ctx_t *ctx, BOOL var_stack, BOOL scope_stack, statement_ctx_t *stat_ctx) static HRESULT pop_to_stat(compiler_ctx_t *ctx, statement_ctx_t *stat_ctx)
{ {
unsigned stack_pop = 0; unsigned stack_pop = 0;
statement_ctx_t *iter; statement_ctx_t *iter;
for(iter = ctx->stat_ctx; iter != stat_ctx; iter = iter->next) { for(iter = ctx->stat_ctx; iter != stat_ctx; iter = iter->next) {
if(scope_stack) {
if(iter->using_scope && !push_instr(ctx, OP_pop_scope)) if(iter->using_scope && !push_instr(ctx, OP_pop_scope))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
if(iter->using_except && !push_instr(ctx, OP_pop_except)) if(iter->using_except && !push_instr(ctx, OP_pop_except))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
}
stack_pop += iter->stack_use; stack_pop += iter->stack_use;
} }
if(var_stack && stack_pop) { if(stack_pop) {
HRESULT hres; HRESULT hres;
hres = push_instr_uint(ctx, OP_pop, stack_pop); hres = push_instr_uint(ctx, OP_pop, stack_pop);
...@@ -1455,7 +1453,7 @@ static HRESULT compile_continue_statement(compiler_ctx_t *ctx, branch_statement_ ...@@ -1455,7 +1453,7 @@ static HRESULT compile_continue_statement(compiler_ctx_t *ctx, branch_statement_
} }
} }
hres = pop_to_stat(ctx, TRUE, TRUE, pop_ctx); hres = pop_to_stat(ctx, pop_ctx);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
...@@ -1492,7 +1490,7 @@ static HRESULT compile_break_statement(compiler_ctx_t *ctx, branch_statement_t * ...@@ -1492,7 +1490,7 @@ static HRESULT compile_break_statement(compiler_ctx_t *ctx, branch_statement_t *
} }
} }
hres = pop_to_stat(ctx, TRUE, TRUE, pop_ctx->next); hres = pop_to_stat(ctx, pop_ctx->next);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
...@@ -1509,10 +1507,6 @@ static HRESULT compile_return_statement(compiler_ctx_t *ctx, expression_statemen ...@@ -1509,10 +1507,6 @@ static HRESULT compile_return_statement(compiler_ctx_t *ctx, expression_statemen
return JS_E_MISPLACED_RETURN; return JS_E_MISPLACED_RETURN;
} }
hres = pop_to_stat(ctx, TRUE, FALSE, NULL);
if(FAILED(hres))
return hres;
if(stat->expr) { if(stat->expr) {
hres = compile_expression(ctx, stat->expr, TRUE); hres = compile_expression(ctx, stat->expr, TRUE);
if(FAILED(hres)) if(FAILED(hres))
...@@ -1521,7 +1515,7 @@ static HRESULT compile_return_statement(compiler_ctx_t *ctx, expression_statemen ...@@ -1521,7 +1515,7 @@ static HRESULT compile_return_statement(compiler_ctx_t *ctx, expression_statemen
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
hres = pop_to_stat(ctx, FALSE, TRUE, NULL); hres = pop_to_stat(ctx, NULL);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
......
...@@ -264,6 +264,8 @@ ok(tmp === 3, "tmp = " + tmp); ...@@ -264,6 +264,8 @@ ok(tmp === 3, "tmp = " + tmp);
eval("testRes(); testRes()"); eval("testRes(); testRes()");
tmp = eval("3; if(false) {4;} else {};;;") tmp = eval("3; if(false) {4;} else {};;;")
ok(tmp === 3, "tmp = " + tmp); ok(tmp === 3, "tmp = " + tmp);
tmp = eval("try { 1; } finally { 2; }")
ok(tmp === 2, "tmp = " + tmp);
testNoRes(); testNoRes();
testRes() && testRes(); testRes() && testRes();
...@@ -1597,6 +1599,15 @@ tmp = (function() { ...@@ -1597,6 +1599,15 @@ tmp = (function() {
})(); })();
ok(tmp, "tmp = " + tmp); ok(tmp, "tmp = " + tmp);
tmp = (function() {
for(var iter in [1,2,3,4]) {
var ret = false;
with({ret: true})
return ret;
}
})();
ok(tmp, "tmp = " + tmp);
(function() { (function() {
ok(typeof(func) === "function", "typeof(func) = " + typeof(func)); ok(typeof(func) === "function", "typeof(func) = " + typeof(func));
with(new Object()) { with(new Object()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment