Jacek Caban : jscript: Set arguments object on function call.

Alexandre Julliard julliard at winehq.org
Thu Sep 11 08:00:49 CDT 2008


Module: wine
Branch: master
Commit: 68d4f489f2d26bddef00eae71608e40fb2c4ab22
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=68d4f489f2d26bddef00eae71608e40fb2c4ab22

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Sep 10 21:06:43 2008 +0200

jscript: Set arguments object on function call.

---

 dlls/jscript/dispex.c      |   10 ++++++++++
 dlls/jscript/function.c    |   39 +++++++++++++++++++++++++++++++++++++--
 dlls/jscript/jscript.h     |    2 +-
 dlls/jscript/tests/lang.js |    1 +
 4 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/dlls/jscript/dispex.c b/dlls/jscript/dispex.c
index ad7b988..193a5b5 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 c58f002..615e7ce 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 2869fc3..f09cea7 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 19430fe..4be651b 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;
 }




More information about the wine-cvs mailing list