Jacek Caban : jscript: Store variable names in function_code_t.
Alexandre Julliard
julliard at winehq.org
Wed Apr 25 13:40:25 CDT 2012
Module: wine
Branch: master
Commit: 64a3f5077f719adbad2b2a1668856f113db68fa0
URL: http://source.winehq.org/git/wine.git/?a=commit;h=64a3f5077f719adbad2b2a1668856f113db68fa0
Author: Jacek Caban <jacek at codeweavers.com>
Date: Wed Apr 25 10:47:56 2012 +0200
jscript: Store variable names in function_code_t.
---
dlls/jscript/compile.c | 16 +++++++++++++++-
dlls/jscript/engine.c | 20 +++++++-------------
dlls/jscript/engine.h | 4 +++-
dlls/jscript/function.c | 2 +-
4 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c
index f8aaa41..5d162ea 100644
--- a/dlls/jscript/compile.c
+++ b/dlls/jscript/compile.c
@@ -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;
}
diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c
index ec906a1..189e19b 100644
--- a/dlls/jscript/engine.c
+++ b/dlls/jscript/engine.c
@@ -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;
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h
index a2be6ee..cc58aa8 100644
--- a/dlls/jscript/engine.h
+++ b/dlls/jscript/engine.h
@@ -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 {
diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c
index dc4c5e8..0377138 100644
--- a/dlls/jscript/function.c
+++ b/dlls/jscript/function.c
@@ -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;
More information about the wine-cvs
mailing list