Commit 64a3f507 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Store variable names in function_code_t.

parent e2b59a87
...@@ -1775,6 +1775,7 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source, ...@@ -1775,6 +1775,7 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
BOOL from_eval, function_code_t *func) BOOL from_eval, function_code_t *func)
{ {
function_declaration_t *iter; function_declaration_t *iter;
var_list_t *var_iter;
unsigned off, i; unsigned off, i;
HRESULT hres; HRESULT hres;
...@@ -1809,7 +1810,6 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source, ...@@ -1809,7 +1810,6 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
func->source_len = func_expr->src_len; func->source_len = func_expr->src_len;
} }
func->source_elements = source;
func->expr = func_expr; func->expr = func_expr;
func->funcs = heap_alloc_zero(func->func_cnt * sizeof(*func->funcs)); func->funcs = heap_alloc_zero(func->func_cnt * sizeof(*func->funcs));
...@@ -1823,6 +1823,20 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source, ...@@ -1823,6 +1823,20 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
} }
assert(i == func->func_cnt); assert(i == func->func_cnt);
for(var_iter = source->variables; var_iter; var_iter = var_iter->next)
func->var_cnt++;
func->variables = compiler_alloc(ctx->code, func->var_cnt * sizeof(*func->variables));
if(!func->variables)
return E_OUTOFMEMORY;
for(var_iter = source->variables, i=0; var_iter; var_iter = var_iter->next, i++) {
func->variables[i] = compiler_alloc_bstr(ctx, var_iter->identifier);
if(!func->variables[i])
return E_OUTOFMEMORY;
}
return S_OK; return S_OK;
} }
......
...@@ -2614,7 +2614,6 @@ HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, BO ...@@ -2614,7 +2614,6 @@ HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, BO
jsexcept_t *ei, VARIANT *retv) jsexcept_t *ei, VARIANT *retv)
{ {
exec_ctx_t *prev_ctx; exec_ctx_t *prev_ctx;
var_list_t *var;
VARIANT val; VARIANT val;
unsigned i; unsigned i;
HRESULT hres = S_OK; HRESULT hres = S_OK;
...@@ -2640,20 +2639,15 @@ HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, BO ...@@ -2640,20 +2639,15 @@ HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, BO
return hres; return hres;
} }
for(var = func->source_elements->variables; var; var = var->next) { for(i=0; i < func->var_cnt; i++) {
if(!ctx->is_global || !lookup_global_members(ctx->script, func->variables[i], NULL)) {
DISPID id = 0; DISPID id = 0;
BSTR name;
name = SysAllocString(var->identifier);
if(!name)
return E_OUTOFMEMORY;
if(!ctx->is_global || !lookup_global_members(ctx->script, name, NULL)) hres = jsdisp_get_id(ctx->var_disp, func->variables[i], fdexNameEnsure, &id);
hres = jsdisp_get_id(ctx->var_disp, var->identifier, fdexNameEnsure, &id);
SysFreeString(name);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
} }
}
prev_ctx = ctx->script->exec_ctx; prev_ctx = ctx->script->exec_ctx;
ctx->script->exec_ctx = ctx; ctx->script->exec_ctx = ctx;
......
...@@ -171,13 +171,15 @@ typedef struct _function_code_t { ...@@ -171,13 +171,15 @@ typedef struct _function_code_t {
unsigned instr_off; unsigned instr_off;
function_expression_t *expr; /* FIXME */ function_expression_t *expr; /* FIXME */
source_elements_t *source_elements; /* FIXME */
const WCHAR *source; const WCHAR *source;
unsigned source_len; unsigned source_len;
unsigned func_cnt; unsigned func_cnt;
struct _function_code_t *funcs; struct _function_code_t *funcs;
unsigned var_cnt;
BSTR *variables;
} function_code_t; } function_code_t;
typedef struct _bytecode_t { typedef struct _bytecode_t {
......
...@@ -774,7 +774,7 @@ static HRESULT construct_function(script_ctx_t *ctx, DISPPARAMS *dp, jsexcept_t ...@@ -774,7 +774,7 @@ static HRESULT construct_function(script_ctx_t *ctx, DISPPARAMS *dp, jsexcept_t
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
if(code->global_code.func_cnt != 1 || code->parser->source->variables) { if(code->global_code.func_cnt != 1 || code->global_code.var_cnt) {
ERR("Invalid parser result!\n"); ERR("Invalid parser result!\n");
release_bytecode(code); release_bytecode(code);
return E_UNEXPECTED; return E_UNEXPECTED;
......
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