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,
BOOL from_eval, function_code_t *func)
{
function_declaration_t *iter;
var_list_t *var_iter;
unsigned off, i;
HRESULT hres;
......@@ -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_elements = source;
func->expr = func_expr;
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,
}
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;
}
......
......@@ -2614,7 +2614,6 @@ HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, BO
jsexcept_t *ei, VARIANT *retv)
{
exec_ctx_t *prev_ctx;
var_list_t *var;
VARIANT val;
unsigned i;
HRESULT hres = S_OK;
......@@ -2640,19 +2639,14 @@ HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, BO
return hres;
}
for(var = func->source_elements->variables; var; var = var->next) {
DISPID id = 0;
BSTR name;
for(i=0; i < func->var_cnt; i++) {
if(!ctx->is_global || !lookup_global_members(ctx->script, func->variables[i], NULL)) {
DISPID id = 0;
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, var->identifier, fdexNameEnsure, &id);
SysFreeString(name);
if(FAILED(hres))
return hres;
hres = jsdisp_get_id(ctx->var_disp, func->variables[i], fdexNameEnsure, &id);
if(FAILED(hres))
return hres;
}
}
prev_ctx = ctx->script->exec_ctx;
......
......@@ -171,13 +171,15 @@ typedef struct _function_code_t {
unsigned instr_off;
function_expression_t *expr; /* FIXME */
source_elements_t *source_elements; /* FIXME */
const WCHAR *source;
unsigned source_len;
unsigned func_cnt;
struct _function_code_t *funcs;
unsigned var_cnt;
BSTR *variables;
} function_code_t;
typedef struct _bytecode_t {
......
......@@ -774,7 +774,7 @@ static HRESULT construct_function(script_ctx_t *ctx, DISPPARAMS *dp, jsexcept_t
if(FAILED(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");
release_bytecode(code);
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