jscipt: Use passed copy of arguments if they are alread at the top of the stack.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2016-07-28 18:44:57 +02:00 committed by Alexandre Julliard
parent 5e4d3826ec
commit b0dcbbdbee

View File

@ -2591,12 +2591,17 @@ static HRESULT bind_event_target(script_ctx_t *ctx, function_code_t *func, jsdis
static HRESULT setup_scope(script_ctx_t *ctx, call_frame_t *frame, unsigned argc, jsval_t *argv)
{
const unsigned orig_stack = ctx->stack_top;
unsigned i;
jsval_t v;
HRESULT hres;
/* If arguments are already on the stack, we may use them. */
if(argv + argc == ctx->stack + ctx->stack_top) {
frame->arguments_off = argv - ctx->stack;
i = argc;
}else {
frame->arguments_off = ctx->stack_top;
for(i = 0; i < argc; i++) {
hres = jsval_copy(argv[i], &v);
if(SUCCEEDED(hres))
@ -2606,17 +2611,18 @@ static HRESULT setup_scope(script_ctx_t *ctx, call_frame_t *frame, unsigned argc
return hres;
}
}
}
/* If fewer than declared arguments were passed, fill remaining with undefined value. */
for(; i < frame->function->param_cnt; i++) {
hres = stack_push(ctx, jsval_undefined());
if(FAILED(hres)) {
stack_popn(ctx, i);
stack_popn(ctx, ctx->stack_top - orig_stack);
return hres;
}
}
frame->pop_locals = i;
frame->pop_locals = ctx->stack_top - orig_stack;
frame->base_scope->frame = frame;
return S_OK;
}