diff --git a/dlls/jscript/dispex.c b/dlls/jscript/dispex.c index ad7b988109a..193a5b5d71f 100644 --- a/dlls/jscript/dispex.c +++ b/dlls/jscript/dispex.c @@ -883,6 +883,16 @@ HRESULT jsdisp_propput_name(DispatchEx *obj, const WCHAR *name, LCID lcid, VARIA return prop_put(obj, prop, lcid, &dp, ei, caller); } +HRESULT jsdisp_propput_idx(DispatchEx *obj, DWORD idx, LCID lcid, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller) +{ + WCHAR buf[12]; + + static const WCHAR formatW[] = {'%','d',0}; + + sprintfW(buf, formatW, idx); + return jsdisp_propput_name(obj, buf, lcid, val, ei, caller); +} + HRESULT disp_propput(IDispatch *disp, DISPID id, LCID lcid, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller) { DISPID dispid = DISPID_PROPERTYPUT; diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c index c58f002971a..615e7ce666d 100644 --- a/dlls/jscript/function.c +++ b/dlls/jscript/function.c @@ -88,17 +88,52 @@ static HRESULT init_parameters(DispatchEx *var_disp, FunctionInstance *function, return S_OK; } +static HRESULT init_arguments(DispatchEx *arg_disp, FunctionInstance *function, LCID lcid, DISPPARAMS *dp, + jsexcept_t *ei, IServiceProvider *caller) +{ + VARIANT var; + DWORD i; + HRESULT hres; + + for(i=0; i < dp->cArgs-dp->cNamedArgs; i++) { + hres = jsdisp_propput_idx(arg_disp, i, lcid, dp->rgvarg+dp->cArgs-1-i, ei, caller); + if(FAILED(hres)) + return hres; + } + + V_VT(&var) = VT_I4; + V_I4(&var) = dp->cArgs - dp->cNamedArgs; + return jsdisp_propput_name(arg_disp, lengthW, lcid, &var, ei, caller); +} + static HRESULT create_var_disp(FunctionInstance *function, LCID lcid, DISPPARAMS *dp, jsexcept_t *ei, IServiceProvider *caller, DispatchEx **ret) { - DispatchEx *var_disp; + DispatchEx *var_disp, *arg_disp; HRESULT hres; + static const WCHAR argumentsW[] = {'a','r','g','u','m','e','n','t','s',0}; + hres = create_dispex(function->dispex.ctx, NULL, NULL, &var_disp); if(FAILED(hres)) return hres; - hres = init_parameters(var_disp, function, lcid, dp, ei, caller); + hres = create_dispex(function->dispex.ctx, NULL, NULL, &arg_disp); + if(SUCCEEDED(hres)) { + hres = init_arguments(arg_disp, function, lcid, dp, ei, caller); + if(SUCCEEDED(hres)) { + VARIANT var; + + V_VT(&var) = VT_DISPATCH; + V_DISPATCH(&var) = (IDispatch*)_IDispatchEx_(arg_disp); + hres = jsdisp_propput_name(var_disp, argumentsW, lcid, &var, ei, caller); + } + + jsdisp_release(arg_disp); + } + + if(SUCCEEDED(hres)) + hres = init_parameters(var_disp, function, lcid, dp, ei, caller); if(FAILED(hres)) { jsdisp_release(var_disp); return hres; diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 2869fc31ed2..f09cea71b6d 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -109,7 +109,7 @@ HRESULT jsdisp_call_value(DispatchEx*,LCID,WORD,DISPPARAMS*,VARIANT*,jsexcept_t* HRESULT disp_propget(IDispatch*,DISPID,LCID,VARIANT*,jsexcept_t*,IServiceProvider*); HRESULT disp_propput(IDispatch*,DISPID,LCID,VARIANT*,jsexcept_t*,IServiceProvider*); HRESULT jsdisp_propput_name(DispatchEx*,const WCHAR*,LCID,VARIANT*,jsexcept_t*,IServiceProvider*); -HRESULT jsdisp_set_prototype(DispatchEx*,DispatchEx*); +HRESULT jsdisp_propput_idx(DispatchEx*,DWORD,LCID,VARIANT*,jsexcept_t*,IServiceProvider*); HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,DWORD,DispatchEx*,DispatchEx**); diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js index 19430fe4827..4be651ba2b2 100644 --- a/dlls/jscript/tests/lang.js +++ b/dlls/jscript/tests/lang.js @@ -44,6 +44,7 @@ function testFunc1(x, y) { ok(this !== undefined, "this is undefined"); ok(x === true, "x is not 1"); ok(y === "test", "y is not \"test\""); + ok(arguments.length === 2, "arguments.length is not 2"); return true; }