Commit 5a90acf5 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Use global accumulator for storing function call results.

parent 4b72060f
...@@ -609,7 +609,7 @@ static HRESULT compile_new_expression(compiler_ctx_t *ctx, call_expression_t *ex ...@@ -609,7 +609,7 @@ static HRESULT compile_new_expression(compiler_ctx_t *ctx, call_expression_t *ex
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
return push_instr(ctx, OP_push_ret) ? S_OK : E_OUTOFMEMORY; return push_instr(ctx, OP_push_acc) ? S_OK : E_OUTOFMEMORY;
} }
static HRESULT compile_call_expression(compiler_ctx_t *ctx, call_expression_t *expr, BOOL emit_ret) static HRESULT compile_call_expression(compiler_ctx_t *ctx, call_expression_t *expr, BOOL emit_ret)
...@@ -651,7 +651,7 @@ static HRESULT compile_call_expression(compiler_ctx_t *ctx, call_expression_t *e ...@@ -651,7 +651,7 @@ static HRESULT compile_call_expression(compiler_ctx_t *ctx, call_expression_t *e
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
return !emit_ret || push_instr(ctx, OP_push_ret) ? S_OK : E_OUTOFMEMORY; return !emit_ret || push_instr(ctx, OP_push_acc) ? S_OK : E_OUTOFMEMORY;
} }
static HRESULT compile_delete_expression(compiler_ctx_t *ctx, unary_expression_t *expr) static HRESULT compile_delete_expression(compiler_ctx_t *ctx, unary_expression_t *expr)
......
...@@ -385,9 +385,10 @@ static inline jsval_t steal_ret(call_frame_t *frame) ...@@ -385,9 +385,10 @@ static inline jsval_t steal_ret(call_frame_t *frame)
return r; return r;
} }
static inline void clear_ret(call_frame_t *frame) static inline void clear_acc(script_ctx_t *ctx)
{ {
jsval_release(steal_ret(frame)); jsval_release(ctx->acc);
ctx->acc = jsval_undefined();
} }
static HRESULT scope_push(scope_chain_t *scope, jsdisp_t *jsobj, IDispatch *obj, scope_chain_t **ret) static HRESULT scope_push(scope_chain_t *scope, jsdisp_t *jsobj, IDispatch *obj, scope_chain_t **ret)
...@@ -1155,7 +1156,6 @@ static HRESULT interp_refval(script_ctx_t *ctx) ...@@ -1155,7 +1156,6 @@ static HRESULT interp_refval(script_ctx_t *ctx)
static HRESULT interp_new(script_ctx_t *ctx) static HRESULT interp_new(script_ctx_t *ctx)
{ {
const unsigned argc = get_op_uint(ctx, 0); const unsigned argc = get_op_uint(ctx, 0);
call_frame_t *frame = ctx->call_ctx;
jsval_t constr; jsval_t constr;
TRACE("%d\n", argc); TRACE("%d\n", argc);
...@@ -1171,9 +1171,9 @@ static HRESULT interp_new(script_ctx_t *ctx) ...@@ -1171,9 +1171,9 @@ static HRESULT interp_new(script_ctx_t *ctx)
else if(!get_object(constr)) else if(!get_object(constr))
return throw_type_error(ctx, JS_E_INVALID_PROPERTY, NULL); return throw_type_error(ctx, JS_E_INVALID_PROPERTY, NULL);
clear_ret(frame); clear_acc(ctx);
return disp_call_value(ctx, get_object(constr), NULL, DISPATCH_CONSTRUCT | DISPATCH_JSCRIPT_CALLEREXECSSOURCE, return disp_call_value(ctx, get_object(constr), NULL, DISPATCH_CONSTRUCT | DISPATCH_JSCRIPT_CALLEREXECSSOURCE,
argc, stack_args(ctx, argc), &frame->ret); argc, stack_args(ctx, argc), &ctx->acc);
} }
/* ECMA-262 3rd Edition 11.2.3 */ /* ECMA-262 3rd Edition 11.2.3 */
...@@ -1181,7 +1181,6 @@ static HRESULT interp_call(script_ctx_t *ctx) ...@@ -1181,7 +1181,6 @@ static HRESULT interp_call(script_ctx_t *ctx)
{ {
const unsigned argn = get_op_uint(ctx, 0); const unsigned argn = get_op_uint(ctx, 0);
const int do_ret = get_op_int(ctx, 1); const int do_ret = get_op_int(ctx, 1);
call_frame_t *frame = ctx->call_ctx;
jsval_t obj; jsval_t obj;
TRACE("%d %d\n", argn, do_ret); TRACE("%d %d\n", argn, do_ret);
...@@ -1190,9 +1189,9 @@ static HRESULT interp_call(script_ctx_t *ctx) ...@@ -1190,9 +1189,9 @@ static HRESULT interp_call(script_ctx_t *ctx)
if(!is_object_instance(obj)) if(!is_object_instance(obj))
return throw_type_error(ctx, JS_E_INVALID_PROPERTY, NULL); return throw_type_error(ctx, JS_E_INVALID_PROPERTY, NULL);
clear_ret(frame); clear_acc(ctx);
return disp_call_value(ctx, get_object(obj), NULL, DISPATCH_METHOD | DISPATCH_JSCRIPT_CALLEREXECSSOURCE, return disp_call_value(ctx, get_object(obj), NULL, DISPATCH_METHOD | DISPATCH_JSCRIPT_CALLEREXECSSOURCE,
argn, stack_args(ctx, argn), do_ret ? &frame->ret : NULL); argn, stack_args(ctx, argn), do_ret ? &ctx->acc : NULL);
} }
/* ECMA-262 3rd Edition 11.2.3 */ /* ECMA-262 3rd Edition 11.2.3 */
...@@ -1200,7 +1199,6 @@ static HRESULT interp_call_member(script_ctx_t *ctx) ...@@ -1200,7 +1199,6 @@ static HRESULT interp_call_member(script_ctx_t *ctx)
{ {
const unsigned argn = get_op_uint(ctx, 0); const unsigned argn = get_op_uint(ctx, 0);
const int do_ret = get_op_int(ctx, 1); const int do_ret = get_op_int(ctx, 1);
call_frame_t *frame = ctx->call_ctx;
exprval_t ref; exprval_t ref;
TRACE("%d %d\n", argn, do_ret); TRACE("%d %d\n", argn, do_ret);
...@@ -1208,9 +1206,9 @@ static HRESULT interp_call_member(script_ctx_t *ctx) ...@@ -1208,9 +1206,9 @@ static HRESULT interp_call_member(script_ctx_t *ctx)
if(!stack_topn_exprval(ctx, argn, &ref)) if(!stack_topn_exprval(ctx, argn, &ref))
return throw_type_error(ctx, ref.u.hres, NULL); return throw_type_error(ctx, ref.u.hres, NULL);
clear_ret(frame); clear_acc(ctx);
return exprval_call(ctx, &ref, DISPATCH_METHOD | DISPATCH_JSCRIPT_CALLEREXECSSOURCE, return exprval_call(ctx, &ref, DISPATCH_METHOD | DISPATCH_JSCRIPT_CALLEREXECSSOURCE,
argn, stack_args(ctx, argn), do_ret ? &frame->ret : NULL); argn, stack_args(ctx, argn), do_ret ? &ctx->acc : NULL);
} }
/* ECMA-262 3rd Edition 11.1.1 */ /* ECMA-262 3rd Edition 11.1.1 */
...@@ -2600,16 +2598,15 @@ static HRESULT interp_setret(script_ctx_t *ctx) ...@@ -2600,16 +2598,15 @@ static HRESULT interp_setret(script_ctx_t *ctx)
return S_OK; return S_OK;
} }
static HRESULT interp_push_ret(script_ctx_t *ctx) static HRESULT interp_push_acc(script_ctx_t *ctx)
{ {
call_frame_t *frame = ctx->call_ctx;
HRESULT hres; HRESULT hres;
TRACE("\n"); TRACE("\n");
hres = stack_push(ctx, frame->ret); hres = stack_push(ctx, ctx->acc);
if(SUCCEEDED(hres)) if(SUCCEEDED(hres))
frame->ret = jsval_undefined(); ctx->acc = jsval_undefined();
return hres; return hres;
} }
...@@ -2796,8 +2793,8 @@ static HRESULT enter_bytecode(script_ctx_t *ctx, jsval_t *r) ...@@ -2796,8 +2793,8 @@ static HRESULT enter_bytecode(script_ctx_t *ctx, jsval_t *r)
assert(frame->scope == frame->base_scope); assert(frame->scope == frame->base_scope);
if(return_to_interp) { if(return_to_interp) {
clear_ret(frame->prev_frame); jsval_release(ctx->acc);
frame->prev_frame->ret = steal_ret(frame); ctx->acc = steal_ret(frame);
}else if(r) { }else if(r) {
*r = steal_ret(frame); *r = steal_ret(frame);
} }
......
...@@ -73,8 +73,8 @@ ...@@ -73,8 +73,8 @@
X(pop_scope, 1, 0,0) \ X(pop_scope, 1, 0,0) \
X(postinc, 1, ARG_INT, 0) \ X(postinc, 1, ARG_INT, 0) \
X(preinc, 1, ARG_INT, 0) \ X(preinc, 1, ARG_INT, 0) \
X(push_acc, 1, 0,0) \
X(push_except,1, ARG_ADDR, ARG_UINT) \ X(push_except,1, ARG_ADDR, ARG_UINT) \
X(push_ret, 1, 0,0) \
X(push_scope, 1, 0,0) \ X(push_scope, 1, 0,0) \
X(regexp, 1, ARG_STR, ARG_UINT) \ X(regexp, 1, ARG_STR, ARG_UINT) \
X(rshift, 1, 0,0) \ X(rshift, 1, 0,0) \
......
...@@ -69,6 +69,7 @@ void script_release(script_ctx_t *ctx) ...@@ -69,6 +69,7 @@ void script_release(script_ctx_t *ctx)
if(--ctx->ref) if(--ctx->ref)
return; return;
jsval_release(ctx->acc);
clear_ei(ctx); clear_ei(ctx);
if(ctx->cc) if(ctx->cc)
release_cc(ctx->cc); release_cc(ctx->cc);
...@@ -715,6 +716,7 @@ static HRESULT WINAPI JScriptParse_InitNew(IActiveScriptParse *iface) ...@@ -715,6 +716,7 @@ static HRESULT WINAPI JScriptParse_InitNew(IActiveScriptParse *iface)
ctx->version = This->version; ctx->version = This->version;
ctx->html_mode = This->html_mode; ctx->html_mode = This->html_mode;
ctx->ei.val = jsval_undefined(); ctx->ei.val = jsval_undefined();
ctx->acc = jsval_undefined();
heap_pool_init(&ctx->tmp_heap); heap_pool_init(&ctx->tmp_heap);
hres = create_jscaller(ctx); hres = create_jscaller(ctx);
......
...@@ -424,6 +424,7 @@ struct _script_ctx_t { ...@@ -424,6 +424,7 @@ struct _script_ctx_t {
jsval_t *stack; jsval_t *stack;
unsigned stack_size; unsigned stack_size;
unsigned stack_top; unsigned stack_top;
jsval_t acc;
jsstr_t *last_match; jsstr_t *last_match;
match_result_t match_parens[9]; match_result_t match_parens[9];
......
...@@ -1146,6 +1146,27 @@ case 3: ...@@ -1146,6 +1146,27 @@ case 3:
})(); })();
expect(ret, "ret"); expect(ret, "ret");
expect(x, "try,try2,finally2,finally,ret"); expect(x, "try,try2,finally2,finally,ret");
ret = (function() {
try {
return "try";
unreachable();
}catch(e) {
unreachable();
}finally {
new Object();
var tmp = (function() {
var s = new String();
try {
s.length;
}finally {
return 1;
}
})();
}
unreachable();
})();
expect(ret, "try");
})(); })();
tmp = eval("1"); tmp = eval("1");
......
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