jscript: Factor local_ref_scopes_t structure out of function_code_t.

Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Paul Gofman 2021-06-18 15:50:16 +03:00 committed by Alexandre Julliard
parent 7c9f372480
commit 2a368c45ae
3 changed files with 21 additions and 12 deletions

View File

@ -2379,10 +2379,14 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
if(FAILED(hres))
return hres;
func->locals = compiler_alloc(ctx->code, ctx->locals_cnt * sizeof(*func->locals));
if(!func->locals)
func->local_scope_count = 1;
func->local_scopes = compiler_alloc(ctx->code, func->local_scope_count * sizeof(*func->local_scopes));
if(!func->local_scopes)
return E_OUTOFMEMORY;
func->locals_cnt = ctx->locals_cnt;
func->local_scopes[0].locals = compiler_alloc(ctx->code, ctx->locals_cnt * sizeof(*func->local_scopes[0].locals));
if(!func->local_scopes[0].locals)
return E_OUTOFMEMORY;
func->local_scopes[0].locals_cnt = ctx->locals_cnt;
func->variables = compiler_alloc(ctx->code, func->var_cnt * sizeof(*func->variables));
if(!func->variables)
@ -2390,8 +2394,8 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
i = 0;
WINE_RB_FOR_EACH_ENTRY(local, &ctx->locals, function_local_t, entry) {
func->locals[i].name = local->name;
func->locals[i].ref = local->ref;
func->local_scopes[0].locals[i].name = local->name;
func->local_scopes[0].locals[i].ref = local->ref;
if(local->ref >= 0) {
func->variables[local->ref].name = local->name;
func->variables[local->ref].func_id = -1;

View File

@ -578,13 +578,12 @@ static HRESULT detach_variable_object(script_ctx_t *ctx, call_frame_t *frame, BO
frame->base_scope->frame = NULL;
for(i = 0; i < frame->function->locals_cnt; i++) {
hres = jsdisp_propput_name(frame->variable_obj, frame->function->locals[i].name,
ctx->stack[local_off(frame, frame->function->locals[i].ref)]);
for(i = 0; i < frame->function->local_scopes[0].locals_cnt; i++) {
hres = jsdisp_propput_name(frame->variable_obj, frame->function->local_scopes[0].locals[i].name,
ctx->stack[local_off(frame, frame->function->local_scopes[0].locals[i].ref)]);
if(FAILED(hres))
return hres;
}
return S_OK;
}
@ -630,7 +629,8 @@ static int __cdecl local_ref_cmp(const void *key, const void *ref)
local_ref_t *lookup_local(const function_code_t *function, const WCHAR *identifier)
{
return bsearch(identifier, function->locals, function->locals_cnt, sizeof(*function->locals), local_ref_cmp);
return bsearch(identifier, function->local_scopes[0].locals, function->local_scopes[0].locals_cnt,
sizeof(*function->local_scopes[0].locals), local_ref_cmp);
}
/* ECMA-262 3rd Edition 10.1.4 */

View File

@ -147,6 +147,11 @@ typedef struct {
#define INVALID_LOCAL_REF 0x7fffffff
typedef struct {
unsigned locals_cnt;
local_ref_t *locals;
} local_ref_scopes_t;
typedef struct _function_code_t {
BSTR name;
int local_ref;
@ -168,8 +173,8 @@ typedef struct _function_code_t {
unsigned param_cnt;
BSTR *params;
unsigned locals_cnt;
local_ref_t *locals;
local_ref_scopes_t *local_scopes;
unsigned local_scope_count;
bytecode_t *bytecode;
} function_code_t;