jscript: Store function name in function_code_t.

This commit is contained in:
Jacek Caban 2012-04-24 17:39:25 +02:00 committed by Alexandre Julliard
parent d76b675ea8
commit 8c533d10d6
3 changed files with 15 additions and 6 deletions

View File

@ -1771,7 +1771,8 @@ static HRESULT init_code(compiler_ctx_t *compiler, const WCHAR *source)
return S_OK;
}
static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source, BOOL from_eval, function_code_t *func)
static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source, function_expression_t *func_expr,
BOOL from_eval, function_code_t *func)
{
function_declaration_t *iter;
unsigned off, i;
@ -1796,17 +1797,24 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
dump_code(ctx, off);
func->instr_off = off;
if(func_expr && func_expr->identifier) {
func->name = compiler_alloc_bstr(ctx, func_expr->identifier);
if(!func->name)
return E_OUTOFMEMORY;
}
func->source_elements = source;
func->expr = func_expr;
func->funcs = heap_alloc_zero(func->func_cnt * sizeof(*func->funcs));
if(!func->funcs)
return E_OUTOFMEMORY;
for(iter = source->functions, i=0; iter; iter = iter->next, i++) {
hres = compile_function(ctx, iter->expr->source_elements, FALSE, func->funcs+i);
hres = compile_function(ctx, iter->expr->source_elements, iter->expr, FALSE, func->funcs+i);
if(FAILED(hres))
return hres;
func->funcs[i].expr = iter->expr;
}
assert(i == func->func_cnt);
@ -1839,7 +1847,7 @@ HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimi
compiler.code->parser = compiler.parser;
hres = compile_function(&compiler, compiler.parser->source, from_eval, &compiler.code->global_code);
hres = compile_function(&compiler, compiler.parser->source, NULL, from_eval, &compiler.code->global_code);
if(FAILED(hres)) {
release_bytecode(compiler.code);
return hres;

View File

@ -2624,7 +2624,7 @@ HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, BO
jsdisp_t *func_obj;
VARIANT var;
if(!func->funcs[i].expr->identifier)
if(!func->funcs[i].name)
continue;
expr = func->funcs[i].expr;
@ -2634,7 +2634,7 @@ HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, BO
return hres;
var_set_jsdisp(&var, func_obj);
hres = jsdisp_propput_name(ctx->var_disp, expr->identifier, &var, ei);
hres = jsdisp_propput_name(ctx->var_disp, func->funcs[i].name, &var, ei);
jsdisp_release(func_obj);
if(FAILED(hres))
return hres;

View File

@ -167,6 +167,7 @@ typedef struct {
} instr_t;
typedef struct _function_code_t {
BSTR name;
unsigned instr_off;
function_expression_t *expr; /* FIXME */