Module: wine Branch: master Commit: 97b44da7466f089a25b03ed2785c8a12237f34e9 URL: http://source.winehq.org/git/wine.git/?a=commit;h=97b44da7466f089a25b03ed278...
Author: Jacek Caban jacek@codeweavers.com Date: Wed Apr 25 11:25:57 2012 +0200
jscript: Store function parameters in function_code_t.
---
dlls/jscript/compile.c | 17 +++++++++++++++-- dlls/jscript/engine.c | 10 ++-------- dlls/jscript/engine.h | 16 ++++++---------- dlls/jscript/function.c | 25 ++++++------------------- dlls/jscript/jscript.c | 2 +- 5 files changed, 30 insertions(+), 40 deletions(-)
diff --git a/dlls/jscript/compile.c b/dlls/jscript/compile.c index 8bb397d..6afef2c 100644 --- a/dlls/jscript/compile.c +++ b/dlls/jscript/compile.c @@ -1806,11 +1806,24 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source, }
if(func_expr) { + parameter_t *param_iter; + func->source = func_expr->src_str; func->source_len = func_expr->src_len; - }
- func->expr = func_expr; + for(param_iter = func_expr->parameter_list; param_iter; param_iter = param_iter->next) + func->param_cnt++; + + func->params = compiler_alloc(ctx->code, func->param_cnt * sizeof(*func->params)); + if(!func->params) + return E_OUTOFMEMORY; + + for(param_iter = func_expr->parameter_list, i=0; param_iter; param_iter = param_iter->next, i++) { + func->params[i] = compiler_alloc_bstr(ctx, param_iter->identifier); + if(!func->params[i]) + return E_OUTOFMEMORY; + } + }
func->funcs = compiler_alloc(ctx->code, func->func_cnt * sizeof(*func->funcs)); if(!func->funcs) diff --git a/dlls/jscript/engine.c b/dlls/jscript/engine.c index 189e19b..35339c8 100644 --- a/dlls/jscript/engine.c +++ b/dlls/jscript/engine.c @@ -804,16 +804,13 @@ static HRESULT interp_end_finally(exec_ctx_t *ctx) static HRESULT interp_func(exec_ctx_t *ctx) { unsigned func_idx = ctx->code->instrs[ctx->ip].arg1.uint; - function_expression_t *expr; jsdisp_t *dispex; VARIANT v; HRESULT hres;
TRACE("%d\n", func_idx);
- expr = ctx->func_code->funcs[func_idx].expr; - - hres = create_source_function(ctx->script, ctx->code, expr->parameter_list, ctx->func_code->funcs+func_idx, + hres = create_source_function(ctx->script, ctx->code, ctx->func_code->funcs+func_idx, ctx->scope_chain, &dispex); if(FAILED(hres)) return hres; @@ -2619,16 +2616,13 @@ HRESULT exec_source(exec_ctx_t *ctx, bytecode_t *code, function_code_t *func, BO HRESULT hres = S_OK;
for(i = 0; i < func->func_cnt; i++) { - function_expression_t *expr; jsdisp_t *func_obj; VARIANT var;
if(!func->funcs[i].name) continue;
- expr = func->funcs[i].expr; - hres = create_source_function(ctx->script, code, expr->parameter_list, func->funcs+i, - ctx->scope_chain, &func_obj); + hres = create_source_function(ctx->script, code, func->funcs+i, ctx->scope_chain, &func_obj); if(FAILED(hres)) return hres;
diff --git a/dlls/jscript/engine.h b/dlls/jscript/engine.h index cc58aa8..c57b89e 100644 --- a/dlls/jscript/engine.h +++ b/dlls/jscript/engine.h @@ -170,8 +170,6 @@ typedef struct _function_code_t { BSTR name; unsigned instr_off;
- function_expression_t *expr; /* FIXME */ - const WCHAR *source; unsigned source_len;
@@ -180,6 +178,9 @@ typedef struct _function_code_t {
unsigned var_cnt; BSTR *variables; + + unsigned param_cnt; + BSTR *params; } function_code_t;
typedef struct _bytecode_t { @@ -269,11 +270,7 @@ static inline void exec_addref(exec_ctx_t *ctx) void exec_release(exec_ctx_t*) DECLSPEC_HIDDEN; HRESULT create_exec_ctx(script_ctx_t*,IDispatch*,jsdisp_t*,scope_chain_t*,BOOL,exec_ctx_t**) DECLSPEC_HIDDEN; HRESULT exec_source(exec_ctx_t*,bytecode_t*,function_code_t*,BOOL,jsexcept_t*,VARIANT*) DECLSPEC_HIDDEN; - -typedef struct _parameter_t parameter_t; - -HRESULT create_source_function(script_ctx_t*,bytecode_t*,parameter_t*,function_code_t*,scope_chain_t*, - jsdisp_t**) DECLSPEC_HIDDEN; +HRESULT create_source_function(script_ctx_t*,bytecode_t*,function_code_t*,scope_chain_t*,jsdisp_t**) DECLSPEC_HIDDEN;
typedef enum { LT_INT, @@ -501,11 +498,10 @@ struct _expression_t { expression_type_t type; };
-struct _parameter_t { +typedef struct _parameter_t { const WCHAR *identifier; - struct _parameter_t *next; -}; +} parameter_t;
struct _source_elements_t { statement_t *statement; diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c index 0377138..31d3be3 100644 --- a/dlls/jscript/function.c +++ b/dlls/jscript/function.c @@ -28,7 +28,6 @@ typedef struct { builtin_invoke_t value_proc; const WCHAR *name; DWORD flags; - parameter_t *parameters; scope_chain_t *scope_chain; bytecode_t *code; function_code_t *func_code; @@ -75,7 +74,6 @@ static IDispatch *get_this(DISPPARAMS *dp) static HRESULT init_parameters(jsdisp_t *var_disp, FunctionInstance *function, DISPPARAMS *dp, jsexcept_t *ei) { - parameter_t *param; VARIANT var_empty; DWORD cargs, i=0; HRESULT hres; @@ -83,13 +81,11 @@ static HRESULT init_parameters(jsdisp_t *var_disp, FunctionInstance *function, D V_VT(&var_empty) = VT_EMPTY; cargs = arg_cnt(dp);
- for(param = function->parameters; param; param = param->next) { - hres = jsdisp_propput_name(var_disp, param->identifier, + for(i=0; i < function->func_code->param_cnt; i++) { + hres = jsdisp_propput_name(var_disp, function->func_code->params[i], i < cargs ? get_arg(dp,i) : &var_empty, ei); if(FAILED(hres)) return hres; - - i++; }
return S_OK; @@ -658,13 +654,11 @@ HRESULT create_builtin_function(script_ctx_t *ctx, builtin_invoke_t value_proc, return S_OK; }
-HRESULT create_source_function(script_ctx_t *ctx, bytecode_t *code, parameter_t *parameters, function_code_t *func_code, +HRESULT create_source_function(script_ctx_t *ctx, bytecode_t *code, function_code_t *func_code, scope_chain_t *scope_chain, jsdisp_t **ret) { FunctionInstance *function; jsdisp_t *prototype; - parameter_t *iter; - DWORD length = 0; HRESULT hres;
hres = create_object(ctx, NULL, &prototype); @@ -681,9 +675,6 @@ HRESULT create_source_function(script_ctx_t *ctx, bytecode_t *code, parameter_t if(FAILED(hres)) return hres;
- function->func_code = func_code; - function->parameters = parameters; - if(scope_chain) { scope_addref(scope_chain); function->scope_chain = scope_chain; @@ -691,10 +682,8 @@ HRESULT create_source_function(script_ctx_t *ctx, bytecode_t *code, parameter_t
bytecode_addref(code); function->code = code; - - for(iter = parameters; iter; iter = iter->next) - length++; - function->length = length; + function->func_code = func_code; + function->length = function->func_code->param_cnt;
*ret = &function->dispex; return S_OK; @@ -702,7 +691,6 @@ HRESULT create_source_function(script_ctx_t *ctx, bytecode_t *code, parameter_t
static HRESULT construct_function(script_ctx_t *ctx, DISPPARAMS *dp, jsexcept_t *ei, IDispatch **ret) { - function_expression_t *expr; WCHAR *str = NULL, *ptr; DWORD argc, len = 0, l; bytecode_t *code; @@ -779,9 +767,8 @@ static HRESULT construct_function(script_ctx_t *ctx, DISPPARAMS *dp, jsexcept_t release_bytecode(code); return E_UNEXPECTED; } - expr = code->global_code.funcs[0].expr;
- hres = create_source_function(ctx, code, expr->parameter_list, code->global_code.funcs, NULL, &function); + hres = create_source_function(ctx, code, code->global_code.funcs, NULL, &function); release_bytecode(code); if(FAILED(hres)) return hres; diff --git a/dlls/jscript/jscript.c b/dlls/jscript/jscript.c index da34c11..bf6710b 100644 --- a/dlls/jscript/jscript.c +++ b/dlls/jscript/jscript.c @@ -836,7 +836,7 @@ static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptPars return hres; }
- hres = create_source_function(This->ctx, code, NULL, &code->global_code, NULL, &dispex); + hres = create_source_function(This->ctx, code, &code->global_code, NULL, &dispex); release_bytecode(code); if(FAILED(hres)) return hres;