Jacek Caban : jscript: Added Array.push implementation.

Alexandre Julliard julliard at winehq.org
Mon Sep 22 07:03:59 CDT 2008


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Sun Sep 21 15:35:58 2008 +0200

jscript: Added Array.push implementation.

---

 dlls/jscript/array.c      |   28 ++++++++++++++++++++++++++--
 dlls/jscript/tests/api.js |    8 ++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/dlls/jscript/array.c b/dlls/jscript/array.c
index c131865..18ee3f5 100644
--- a/dlls/jscript/array.c
+++ b/dlls/jscript/array.c
@@ -89,11 +89,35 @@ static HRESULT Array_pop(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *
     return E_NOTIMPL;
 }
 
+/* ECMA-262 3rd Edition    15.4.4.7 */
 static HRESULT Array_push(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
         VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
 {
-    FIXME("\n");
-    return E_NOTIMPL;
+    DWORD length = 0;
+    int i, n;
+    HRESULT hres;
+
+    TRACE("\n");
+
+    if(dispex->builtin_info->class == JSCLASS_ARRAY) {
+        length = ((ArrayInstance*)dispex)->length;
+    }else {
+        FIXME("not Array this\n");
+        return E_NOTIMPL;
+    }
+
+    n = dp->cArgs - dp->cNamedArgs;
+    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(retv) {
+        V_VT(retv) = VT_I4;
+        V_I4(retv) = length+n;
+    }
+    return S_OK;
 }
 
 static HRESULT Array_reverse(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 45765ed..c76a485 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -60,4 +60,12 @@ ok(typeof(arr) === "object", "arr (6) is not object");
 ok((arr.length === 6), "arr.length is not 6");
 ok(arr["0"] === undefined, "arr[0] is not undefined");
 
+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");
+
 reportSuccess();




More information about the wine-cvs mailing list