Jacek Caban : jscript: Make Array.push generic.

Alexandre Julliard julliard at winehq.org
Sat Aug 29 11:36:03 CDT 2009


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Sat Aug 29 00:03:22 2009 +0200

jscript: Make Array.push generic.

---

 dlls/jscript/array.c      |   36 +++++++++++++++++++++++++++++++++---
 dlls/jscript/tests/api.js |   13 +++++++++++++
 2 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/dlls/jscript/array.c b/dlls/jscript/array.c
index 2aea70b..6b7a58f 100644
--- a/dlls/jscript/array.c
+++ b/dlls/jscript/array.c
@@ -46,6 +46,29 @@ static const WCHAR unshiftW[] = {'u','n','s','h','i','f','t',0};
 
 static const WCHAR default_separatorW[] = {',',0};
 
+static HRESULT get_jsdisp_length(DispatchEx *obj, LCID lcid, jsexcept_t *ei, DWORD *ret)
+{
+    VARIANT var;
+    HRESULT hres;
+
+    hres = jsdisp_propget_name(obj, lengthW, lcid, &var, ei, NULL/*FIXME*/);
+    if(FAILED(hres))
+        return hres;
+
+    hres = to_uint32(obj->ctx, &var, ei, ret);
+    VariantClear(&var);
+    return hres;
+}
+
+static HRESULT set_jsdisp_length(DispatchEx *obj, LCID lcid, jsexcept_t *ei, DWORD length)
+{
+    VARIANT var;
+
+    V_VT(&var) = VT_I4;
+    V_I4(&var) = length;
+    return jsdisp_propput_name(obj, lengthW, lcid, &var, ei, NULL/*FIXME*/);
+}
+
 static HRESULT Array_length(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
 {
@@ -380,17 +403,24 @@ static HRESULT Array_push(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS
     if(dispex->builtin_info->class == JSCLASS_ARRAY) {
         length = ((ArrayInstance*)dispex)->length;
     }else {
-        FIXME("not Array this\n");
-        return E_NOTIMPL;
+        hres = get_jsdisp_length(dispex, lcid, ei, &length);
+        if(FAILED(hres))
+            return hres;
     }
 
-    n = dp->cArgs - dp->cNamedArgs;
+    n = arg_cnt(dp);
     for(i=0; i < n; i++) {
         hres = jsdisp_propput_idx(dispex, length+i, lcid, get_arg(dp, i), ei, sp);
         if(FAILED(hres))
             return hres;
     }
 
+    if(!is_class(dispex, JSCLASS_ARRAY)) {
+        hres = set_jsdisp_length(dispex, lcid, ei, length+n);
+        if(FAILED(hres))
+            return hres;
+    }
+
     if(retv) {
         V_VT(retv) = VT_I4;
         V_I4(retv) = length+n;
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 75074a1..d5d7fb3 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -492,6 +492,19 @@ ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
 ok(arr[8] === "b", "arr[8] != 'b'");
 ok(arr.length === 10, "arr.length != 10");
 
+var arr = new Object();
+arr.push = Array.prototype.push;
+
+arr.length = 6;
+
+ok(arr.push() === 6, "arr.push() !== 6");
+ok(arr.push(1) === 7, "arr.push(1) !== 7");
+ok(arr[6] === 1, "arr[6] != 1");
+ok(arr.length === 7, "arr.length != 10");
+ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
+ok(arr[8] === "b", "arr[8] != 'b'");
+ok(arr.length === 10, "arr.length != 10");
+
 arr = [3,4,5];
 tmp = arr.pop();
 ok(arr.length === 2, "arr.length = " + arr.length);




More information about the wine-cvs mailing list