jscript: Delay arguments object until it's accessed and properly detach it after function exits.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2016-08-03 16:28:26 +02:00 committed by Alexandre Julliard
parent 5a7327d21d
commit 2f63a1e009
3 changed files with 29 additions and 8 deletions

View file

@ -558,6 +558,12 @@ static HRESULT detach_variable_object(script_ctx_t *ctx, call_frame_t *frame)
assert(frame == frame->base_scope->frame);
assert(frame->variable_obj == frame->base_scope->jsobj);
if(!frame->arguments_obj) {
hres = setup_arguments_object(ctx, frame);
if(FAILED(hres))
return hres;
}
frame->base_scope->frame = NULL;
for(i = 0; i < frame->function->param_cnt; i++) {
@ -609,12 +615,19 @@ static HRESULT identifier_eval(script_ctx_t *ctx, BSTR identifier, exprval_t *re
if(scope->frame) {
function_code_t *func = scope->frame->function;
local_ref_t *ref = bsearch(identifier, func->locals, func->locals_cnt, sizeof(*func->locals), local_ref_cmp);
static const WCHAR argumentsW[] = {'a','r','g','u','m','e','n','t','s',0};
if(ref) {
ret->type = EXPRVAL_STACK_REF;
ret->u.off = scope->frame->arguments_off - ref->ref - 1;
return S_OK;
}
if(!strcmpW(identifier, argumentsW)) {
hres = detach_variable_object(ctx, scope->frame);
if(FAILED(hres))
return hres;
}
}
if(scope->jsobj)
hres = jsdisp_get_id(scope->jsobj, identifier, fdexNameImplicit, &id);
@ -2701,7 +2714,7 @@ static HRESULT bind_event_target(script_ctx_t *ctx, function_code_t *func, jsdis
return hres;
}
static HRESULT setup_scope(script_ctx_t *ctx, call_frame_t *frame, unsigned argc, jsval_t *argv, jsdisp_t *function_instance)
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;
@ -2736,7 +2749,7 @@ static HRESULT setup_scope(script_ctx_t *ctx, call_frame_t *frame, unsigned argc
frame->pop_locals = ctx->stack_top - orig_stack;
frame->base_scope->frame = frame;
return setup_arguments_object(ctx, frame, argc, function_instance);
return S_OK;
}
HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, function_code_t *function, scope_chain_t *scope,
@ -2799,12 +2812,13 @@ HRESULT exec_source(script_ctx_t *ctx, DWORD flags, bytecode_t *bytecode, functi
frame->function = function;
frame->ret = jsval_undefined();
frame->argc = argc;
if(scope) {
frame->base_scope = frame->scope = scope_addref(scope);
if(!(flags & (EXEC_GLOBAL|EXEC_EVAL))) {
hres = setup_scope(ctx, frame, argc, argv, function_instance);
hres = setup_scope(ctx, frame, argc, argv);
if(FAILED(hres)) {
heap_free(frame);
return hres;

View file

@ -217,6 +217,7 @@ typedef struct _call_frame_t {
jsdisp_t *arguments_obj;
DWORD flags;
unsigned argc;
unsigned pop_locals;
unsigned arguments_off;
@ -235,5 +236,5 @@ HRESULT exec_source(script_ctx_t*,DWORD,bytecode_t*,function_code_t*,scope_chain
jsdisp_t*,jsdisp_t*,unsigned,jsval_t*,jsval_t*) DECLSPEC_HIDDEN;
HRESULT create_source_function(script_ctx_t*,bytecode_t*,function_code_t*,scope_chain_t*,jsdisp_t**) DECLSPEC_HIDDEN;
HRESULT setup_arguments_object(script_ctx_t*,call_frame_t*,unsigned,jsdisp_t*) DECLSPEC_HIDDEN;
HRESULT setup_arguments_object(script_ctx_t*,call_frame_t*) DECLSPEC_HIDDEN;
void detach_arguments_object(jsdisp_t*) DECLSPEC_HIDDEN;

View file

@ -159,7 +159,7 @@ static const builtin_info_t Arguments_info = {
Arguments_idx_put
};
HRESULT setup_arguments_object(script_ctx_t *ctx, call_frame_t *frame, unsigned argc, jsdisp_t *function_instance)
HRESULT setup_arguments_object(script_ctx_t *ctx, call_frame_t *frame)
{
ArgumentsInstance *args;
HRESULT hres;
@ -176,11 +176,11 @@ HRESULT setup_arguments_object(script_ctx_t *ctx, call_frame_t *frame, unsigned
return hres;
}
args->function = function_from_jsdisp(jsdisp_addref(function_instance));
args->argc = argc;
args->function = function_from_jsdisp(jsdisp_addref(frame->function_instance));
args->argc = frame->argc;
args->frame = frame;
hres = jsdisp_propput_dontenum(&args->jsdisp, lengthW, jsval_number(argc));
hres = jsdisp_propput_dontenum(&args->jsdisp, lengthW, jsval_number(args->argc));
if(SUCCEEDED(hres))
hres = jsdisp_propput_dontenum(&args->jsdisp, caleeW, jsval_disp(to_disp(&args->function->dispex)));
if(SUCCEEDED(hres))
@ -561,11 +561,17 @@ static HRESULT Function_get_arguments(script_ctx_t *ctx, jsdisp_t *jsthis, jsval
{
FunctionInstance *function = function_from_jsdisp(jsthis);
call_frame_t *frame;
HRESULT hres;
TRACE("\n");
for(frame = ctx->call_ctx; frame; frame = frame->prev_frame) {
if(frame->function_instance == &function->dispex) {
if(!frame->arguments_obj) {
hres = setup_arguments_object(ctx, frame);
if(FAILED(hres))
return hres;
}
*r = jsval_obj(jsdisp_addref(frame->arguments_obj));
return S_OK;
}