diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c index e2d33907ae9..3f6a2b67aa8 100644 --- a/dlls/jscript/compile.c +++ b/dlls/jscript/compile.c @@ -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; diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index 7baa8c65411..929be802662 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -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; diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h index 3234ed9a1cb..ce7ff8cd4c6 100644 --- a/dlls/jscript/engine.h +++ b/dlls/jscript/engine.h @@ -167,6 +167,7 @@ typedef struct { } instr_t; typedef struct _function_code_t { + BSTR name; unsigned instr_off; function_expression_t *expr; /* FIXME */