jscript: Store function parameters in function_code_t.

This commit is contained in:
Jacek Caban 2012-04-25 11:25:57 +02:00 committed by Alexandre Julliard
parent d1a4053953
commit 97b44da746
5 changed files with 30 additions and 40 deletions

View File

@ -1806,11 +1806,24 @@ static HRESULT compile_function(compiler_ctx_t *ctx, source_elements_t *source,
} }
if(func_expr) { if(func_expr) {
parameter_t *param_iter;
func->source = func_expr->src_str; func->source = func_expr->src_str;
func->source_len = func_expr->src_len; 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)); func->funcs = compiler_alloc(ctx->code, func->func_cnt * sizeof(*func->funcs));
if(!func->funcs) if(!func->funcs)

View File

@ -804,16 +804,13 @@ static HRESULT interp_end_finally(exec_ctx_t *ctx)
static HRESULT interp_func(exec_ctx_t *ctx) static HRESULT interp_func(exec_ctx_t *ctx)
{ {
unsigned func_idx = ctx->code->instrs[ctx->ip].arg1.uint; unsigned func_idx = ctx->code->instrs[ctx->ip].arg1.uint;
function_expression_t *expr;
jsdisp_t *dispex; jsdisp_t *dispex;
VARIANT v; VARIANT v;
HRESULT hres; HRESULT hres;
TRACE("%d\n", func_idx); TRACE("%d\n", func_idx);
expr = ctx->func_code->funcs[func_idx].expr; hres = create_source_function(ctx->script, ctx->code, ctx->func_code->funcs+func_idx,
hres = create_source_function(ctx->script, ctx->code, expr->parameter_list, ctx->func_code->funcs+func_idx,
ctx->scope_chain, &dispex); ctx->scope_chain, &dispex);
if(FAILED(hres)) if(FAILED(hres))
return 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; HRESULT hres = S_OK;
for(i = 0; i < func->func_cnt; i++) { for(i = 0; i < func->func_cnt; i++) {
function_expression_t *expr;
jsdisp_t *func_obj; jsdisp_t *func_obj;
VARIANT var; VARIANT var;
if(!func->funcs[i].name) if(!func->funcs[i].name)
continue; continue;
expr = func->funcs[i].expr; hres = create_source_function(ctx->script, code, func->funcs+i, ctx->scope_chain, &func_obj);
hres = create_source_function(ctx->script, code, expr->parameter_list, func->funcs+i,
ctx->scope_chain, &func_obj);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;

View File

@ -170,8 +170,6 @@ typedef struct _function_code_t {
BSTR name; BSTR name;
unsigned instr_off; unsigned instr_off;
function_expression_t *expr; /* FIXME */
const WCHAR *source; const WCHAR *source;
unsigned source_len; unsigned source_len;
@ -180,6 +178,9 @@ typedef struct _function_code_t {
unsigned var_cnt; unsigned var_cnt;
BSTR *variables; BSTR *variables;
unsigned param_cnt;
BSTR *params;
} function_code_t; } function_code_t;
typedef struct _bytecode_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; 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 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; HRESULT exec_source(exec_ctx_t*,bytecode_t*,function_code_t*,BOOL,jsexcept_t*,VARIANT*) DECLSPEC_HIDDEN;
HRESULT create_source_function(script_ctx_t*,bytecode_t*,function_code_t*,scope_chain_t*,jsdisp_t**) 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;
typedef enum { typedef enum {
LT_INT, LT_INT,
@ -501,11 +498,10 @@ struct _expression_t {
expression_type_t type; expression_type_t type;
}; };
struct _parameter_t { typedef struct _parameter_t {
const WCHAR *identifier; const WCHAR *identifier;
struct _parameter_t *next; struct _parameter_t *next;
}; } parameter_t;
struct _source_elements_t { struct _source_elements_t {
statement_t *statement; statement_t *statement;

View File

@ -28,7 +28,6 @@ typedef struct {
builtin_invoke_t value_proc; builtin_invoke_t value_proc;
const WCHAR *name; const WCHAR *name;
DWORD flags; DWORD flags;
parameter_t *parameters;
scope_chain_t *scope_chain; scope_chain_t *scope_chain;
bytecode_t *code; bytecode_t *code;
function_code_t *func_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, static HRESULT init_parameters(jsdisp_t *var_disp, FunctionInstance *function, DISPPARAMS *dp,
jsexcept_t *ei) jsexcept_t *ei)
{ {
parameter_t *param;
VARIANT var_empty; VARIANT var_empty;
DWORD cargs, i=0; DWORD cargs, i=0;
HRESULT hres; HRESULT hres;
@ -83,13 +81,11 @@ static HRESULT init_parameters(jsdisp_t *var_disp, FunctionInstance *function, D
V_VT(&var_empty) = VT_EMPTY; V_VT(&var_empty) = VT_EMPTY;
cargs = arg_cnt(dp); cargs = arg_cnt(dp);
for(param = function->parameters; param; param = param->next) { for(i=0; i < function->func_code->param_cnt; i++) {
hres = jsdisp_propput_name(var_disp, param->identifier, hres = jsdisp_propput_name(var_disp, function->func_code->params[i],
i < cargs ? get_arg(dp,i) : &var_empty, ei); i < cargs ? get_arg(dp,i) : &var_empty, ei);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
i++;
} }
return S_OK; return S_OK;
@ -658,13 +654,11 @@ HRESULT create_builtin_function(script_ctx_t *ctx, builtin_invoke_t value_proc,
return S_OK; 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) scope_chain_t *scope_chain, jsdisp_t **ret)
{ {
FunctionInstance *function; FunctionInstance *function;
jsdisp_t *prototype; jsdisp_t *prototype;
parameter_t *iter;
DWORD length = 0;
HRESULT hres; HRESULT hres;
hres = create_object(ctx, NULL, &prototype); 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)) if(FAILED(hres))
return hres; return hres;
function->func_code = func_code;
function->parameters = parameters;
if(scope_chain) { if(scope_chain) {
scope_addref(scope_chain); scope_addref(scope_chain);
function->scope_chain = 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); bytecode_addref(code);
function->code = code; function->code = code;
function->func_code = func_code;
for(iter = parameters; iter; iter = iter->next) function->length = function->func_code->param_cnt;
length++;
function->length = length;
*ret = &function->dispex; *ret = &function->dispex;
return S_OK; 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) static HRESULT construct_function(script_ctx_t *ctx, DISPPARAMS *dp, jsexcept_t *ei, IDispatch **ret)
{ {
function_expression_t *expr;
WCHAR *str = NULL, *ptr; WCHAR *str = NULL, *ptr;
DWORD argc, len = 0, l; DWORD argc, len = 0, l;
bytecode_t *code; bytecode_t *code;
@ -779,9 +767,8 @@ static HRESULT construct_function(script_ctx_t *ctx, DISPPARAMS *dp, jsexcept_t
release_bytecode(code); release_bytecode(code);
return E_UNEXPECTED; 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); release_bytecode(code);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;

View File

@ -836,7 +836,7 @@ static HRESULT WINAPI JScriptParseProcedure_ParseProcedureText(IActiveScriptPars
return hres; 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); release_bytecode(code);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;