Commit 0e9d2215 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

jscript: Get rid of jsobj in scope_chain_t.

It was confusing and aliased to obj when it was a jsdisp (and shared ref), but we can obtain that already with helpers as needed (as_jsdisp and to_jsdisp), no reason to keep it so confusing and a separate field. Signed-off-by: 's avatarGabriel Ivăncescu <gabrielopcode@gmail.com>
parent 08e0ebee
......@@ -207,6 +207,7 @@ static BOOL stack_topn_exprval(script_ctx_t *ctx, unsigned n, exprval_t *r)
unsigned off = get_number(v);
if(!frame->base_scope->frame && off >= frame->arguments_off) {
jsdisp_t *jsobj;
DISPID id;
BSTR name;
HRESULT hres = E_FAIL;
......@@ -227,7 +228,7 @@ static BOOL stack_topn_exprval(script_ctx_t *ctx, unsigned n, exprval_t *r)
while (1)
{
if (scope->jsobj && SUCCEEDED(hres = jsdisp_get_id(scope->jsobj, name, 0, &id)))
if ((jsobj = to_jsdisp(scope->obj)) && SUCCEEDED(hres = jsdisp_get_id(jsobj, name, 0, &id)))
break;
if (scope == frame->base_scope)
{
......@@ -238,10 +239,10 @@ static BOOL stack_topn_exprval(script_ctx_t *ctx, unsigned n, exprval_t *r)
scope = scope->next;
}
*stack_top_ref(ctx, n+1) = jsval_obj(jsdisp_addref(scope->jsobj));
*stack_top_ref(ctx, n+1) = jsval_obj(jsdisp_addref(jsobj));
*stack_top_ref(ctx, n) = jsval_number(id);
r->type = EXPRVAL_IDREF;
r->u.idref.disp = scope->obj;
r->u.idref.disp = to_disp(jsobj);
r->u.idref.id = id;
return TRUE;
}
......@@ -437,6 +438,7 @@ static void scope_destructor(jsdisp_t *dispex)
static HRESULT scope_gc_traverse(struct gc_ctx *gc_ctx, enum gc_traverse_op op, jsdisp_t *dispex)
{
scope_chain_t *scope = CONTAINING_RECORD(dispex, scope_chain_t, dispex);
jsdisp_t *jsobj;
HRESULT hres;
if(scope->next) {
......@@ -454,7 +456,7 @@ static HRESULT scope_gc_traverse(struct gc_ctx *gc_ctx, enum gc_traverse_op op,
return S_OK;
}
return scope->jsobj ? gc_process_linked_obj(gc_ctx, op, dispex, scope->jsobj, (void**)&scope->obj) : S_OK;
return scope->obj && (jsobj = to_jsdisp(scope->obj)) ? gc_process_linked_obj(gc_ctx, op, dispex, jsobj, (void**)&scope->obj) : S_OK;
}
static const builtin_info_t scope_info = {
......@@ -470,7 +472,7 @@ static const builtin_info_t scope_info = {
scope_gc_traverse
};
static HRESULT scope_push(script_ctx_t *ctx, scope_chain_t *scope, jsdisp_t *jsobj, IDispatch *obj, scope_chain_t **ret)
static HRESULT scope_push(script_ctx_t *ctx, scope_chain_t *scope, IDispatch *obj, scope_chain_t **ret)
{
scope_chain_t *new_scope;
HRESULT hres;
......@@ -487,7 +489,6 @@ static HRESULT scope_push(script_ctx_t *ctx, scope_chain_t *scope, jsdisp_t *jso
if (obj)
IDispatch_AddRef(obj);
new_scope->jsobj = jsobj;
new_scope->obj = obj;
new_scope->frame = NULL;
new_scope->next = scope ? scope_addref(scope) : NULL;
......@@ -628,6 +629,7 @@ static HRESULT detach_scope(script_ctx_t *ctx, call_frame_t *frame, scope_chain_
{
function_code_t *func = frame->function;
unsigned int i, index;
jsdisp_t *jsobj;
HRESULT hres;
if (!scope->frame)
......@@ -636,18 +638,18 @@ static HRESULT detach_scope(script_ctx_t *ctx, call_frame_t *frame, scope_chain_
assert(scope->frame == frame);
scope->frame = NULL;
if (!scope->jsobj)
if (!scope->obj)
{
assert(!scope->obj);
if (FAILED(hres = create_object(ctx, NULL, &scope->jsobj)))
if (FAILED(hres = create_object(ctx, NULL, &jsobj)))
return hres;
scope->obj = to_disp(scope->jsobj);
scope->obj = to_disp(jsobj);
}
else
jsobj = as_jsdisp(scope->obj);
if (scope == frame->base_scope && func->name && func->local_ref == INVALID_LOCAL_REF &&
ctx->version >= SCRIPTLANGUAGEVERSION_ES5)
jsdisp_propput_name(scope->jsobj, func->name, jsval_obj(jsdisp_addref(frame->function_instance)));
jsdisp_propput_name(jsobj, func->name, jsval_obj(jsdisp_addref(frame->function_instance)));
index = scope->scope_index;
for(i = 0; i < frame->function->local_scopes[index].locals_cnt; i++)
......@@ -655,7 +657,7 @@ static HRESULT detach_scope(script_ctx_t *ctx, call_frame_t *frame, scope_chain_
WCHAR *name = frame->function->local_scopes[index].locals[i].name;
int ref = frame->function->local_scopes[index].locals[i].ref;
if (FAILED(hres = jsdisp_propput_name(scope->jsobj, name, ctx->stack[local_off(frame, ref)])))
if (FAILED(hres = jsdisp_propput_name(jsobj, name, ctx->stack[local_off(frame, ref)])))
return hres;
if (scope != frame->base_scope && frame->function->variables[ref].func_id != -1
&& FAILED(hres = jsdisp_propput_name(frame->variable_obj, name, ctx->stack[local_off(frame, ref)])))
......@@ -687,7 +689,7 @@ static HRESULT detach_variable_object(script_ctx_t *ctx, call_frame_t *frame, BO
TRACE("detaching %p\n", frame);
assert(frame == frame->base_scope->frame);
assert(frame->variable_obj == frame->base_scope->jsobj);
assert(to_disp(frame->variable_obj) == frame->base_scope->obj);
if(!from_release && !frame->arguments_obj) {
hres = setup_arguments_object(ctx, frame);
......@@ -784,12 +786,9 @@ static HRESULT identifier_eval(script_ctx_t *ctx, BSTR identifier, exprval_t *re
}
}
if (!scope->jsobj && !scope->obj)
if (!scope->obj)
continue;
if(scope->jsobj)
hres = jsdisp_get_id(scope->jsobj, identifier, fdexNameImplicit, &id);
else
hres = disp_get_id(ctx, scope->obj, identifier, identifier, fdexNameImplicit, &id);
if(SUCCEEDED(hres)) {
exprval_set_disp_ref(ret, scope->obj, id);
......@@ -943,6 +942,7 @@ static HRESULT scope_init_locals(script_ctx_t *ctx)
unsigned int i, off, index;
scope_chain_t *scope;
BOOL detached_vars;
jsdisp_t *jsobj;
HRESULT hres;
scope = frame->scope;
......@@ -954,13 +954,14 @@ static HRESULT scope_init_locals(script_ctx_t *ctx)
assert(frame->base_scope->frame == frame);
frame->scope->frame = ctx->call_ctx;
}
else if (!scope->jsobj)
else if (!scope->obj)
{
assert(!scope->obj);
if (FAILED(hres = create_object(ctx, NULL, &scope->jsobj)))
if (FAILED(hres = create_object(ctx, NULL, &jsobj)))
return hres;
scope->obj = to_disp(scope->jsobj);
scope->obj = to_disp(jsobj);
}
else
jsobj = as_jsdisp(scope->obj);
for(i = 0; i < frame->function->local_scopes[index].locals_cnt; i++)
{
......@@ -990,7 +991,7 @@ static HRESULT scope_init_locals(script_ctx_t *ctx)
if (detached_vars)
{
hres = jsdisp_propput_name(scope->jsobj, name, val);
hres = jsdisp_propput_name(jsobj, name, val);
jsval_release(val);
if (FAILED(hres))
return hres;
......@@ -1020,7 +1021,7 @@ static HRESULT interp_push_with_scope(script_ctx_t *ctx)
if(FAILED(hres))
return hres;
hres = scope_push(ctx, ctx->call_ctx->scope, to_jsdisp(disp), disp, &ctx->call_ctx->scope);
hres = scope_push(ctx, ctx->call_ctx->scope, disp, &ctx->call_ctx->scope);
IDispatch_Release(disp);
return hres;
}
......@@ -1034,7 +1035,7 @@ static HRESULT interp_push_block_scope(script_ctx_t *ctx)
TRACE("scope_index %u.\n", scope_index);
hres = scope_push(ctx, ctx->call_ctx->scope, NULL, NULL, &frame->scope);
hres = scope_push(ctx, ctx->call_ctx->scope, NULL, &frame->scope);
if (FAILED(hres) || !scope_index)
return hres;
......@@ -1246,7 +1247,7 @@ static HRESULT interp_enter_catch(script_ctx_t *ctx)
hres = jsdisp_propput_name(scope_obj, ident, v);
jsval_release(v);
if(SUCCEEDED(hres))
hres = scope_push(ctx, ctx->call_ctx->scope, scope_obj, to_disp(scope_obj), &ctx->call_ctx->scope);
hres = scope_push(ctx, ctx->call_ctx->scope, to_disp(scope_obj), &ctx->call_ctx->scope);
jsdisp_release(scope_obj);
return hres;
}
......@@ -3270,7 +3271,7 @@ static HRESULT setup_scope(script_ctx_t *ctx, call_frame_t *frame, scope_chain_t
frame->pop_variables = i;
hres = scope_push(ctx, scope_chain, variable_object, to_disp(variable_object), &scope);
hres = scope_push(ctx, scope_chain, to_disp(variable_object), &scope);
if(FAILED(hres)) {
stack_popn(ctx, ctx->stack_top - orig_stack);
return hres;
......
......@@ -224,7 +224,6 @@ static inline bytecode_t *bytecode_addref(bytecode_t *code)
typedef struct _scope_chain_t {
jsdisp_t dispex; /* FIXME: don't wrap it in a jsdisp (it holds ref and traverse for the garbage collector) */
jsdisp_t *jsobj;
IDispatch *obj;
unsigned int scope_index;
struct _call_frame_t *frame;
......
......@@ -145,7 +145,7 @@ static HRESULT Arguments_idx_get(jsdisp_t *jsdisp, unsigned idx, jsval_t *r)
return jsval_copy(*ref, r);
/* FIXME: Accessing by name won't work for duplicated argument names */
return jsdisp_propget_name(arguments->frame->base_scope->jsobj,
return jsdisp_propget_name(as_jsdisp(arguments->frame->base_scope->obj),
arguments->function->func_code->params[idx], r);
}
......@@ -169,7 +169,7 @@ static HRESULT Arguments_idx_put(jsdisp_t *jsdisp, unsigned idx, jsval_t val)
}
/* FIXME: Accessing by name won't work for duplicated argument names */
return jsdisp_propput_name(arguments->frame->base_scope->jsobj,
return jsdisp_propput_name(as_jsdisp(arguments->frame->base_scope->obj),
arguments->function->func_code->params[idx], val);
}
......@@ -227,7 +227,7 @@ HRESULT setup_arguments_object(script_ctx_t *ctx, call_frame_t *frame)
hres = jsdisp_define_data_property(&args->jsdisp, L"callee", PROPF_WRITABLE | PROPF_CONFIGURABLE,
jsval_obj(&args->function->function.dispex));
if(SUCCEEDED(hres))
hres = jsdisp_propput(frame->base_scope->jsobj, L"arguments", PROPF_WRITABLE, TRUE, jsval_obj(&args->jsdisp));
hres = jsdisp_propput(as_jsdisp(frame->base_scope->obj), L"arguments", PROPF_WRITABLE, TRUE, jsval_obj(&args->jsdisp));
if(FAILED(hres)) {
jsdisp_release(&args->jsdisp);
return hres;
......@@ -242,11 +242,12 @@ void detach_arguments_object(jsdisp_t *args_disp)
ArgumentsInstance *arguments = arguments_from_jsdisp(args_disp);
call_frame_t *frame = arguments->frame;
const BOOL on_stack = frame->base_scope->frame == frame;
jsdisp_t *jsobj = as_jsdisp(frame->base_scope->obj);
HRESULT hres;
/* Reset arguments value to cut the reference cycle. Note that since all activation contexts have
* their own arguments property, it's impossible to use prototype's one during name lookup */
jsdisp_propput_name(frame->base_scope->jsobj, L"arguments", jsval_undefined());
jsdisp_propput_name(jsobj, L"arguments", jsval_undefined());
arguments->frame = NULL;
/* Don't bother coppying arguments if call frame holds the last reference. */
......@@ -259,7 +260,7 @@ void detach_arguments_object(jsdisp_t *args_disp)
if(on_stack || i >= frame->function->param_cnt)
hres = jsval_copy(arguments->jsdisp.ctx->stack[frame->arguments_off + i], arguments->buf+i);
else
hres = jsdisp_propget_name(frame->base_scope->jsobj, frame->function->params[i], arguments->buf+i);
hres = jsdisp_propget_name(jsobj, frame->function->params[i], arguments->buf+i);
if(FAILED(hres))
arguments->buf[i] = jsval_undefined();
}
......
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