Piotr Caban : jscript: Make Array.pop generic.

Alexandre Julliard julliard at winehq.org
Wed Jan 20 14:29:45 CST 2010


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

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Wed Jan 20 17:12:38 2010 +0100

jscript: Make Array.pop generic.

---

 dlls/jscript/array.c      |   43 +++++++++++++++++--------------------------
 dlls/jscript/tests/api.js |   12 ++++++++++++
 2 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/dlls/jscript/array.c b/dlls/jscript/array.c
index 5acfa01..15a6e78 100644
--- a/dlls/jscript/array.c
+++ b/dlls/jscript/array.c
@@ -372,52 +372,42 @@ static HRESULT Array_join(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPAR
     return hres;
 }
 
-static HRESULT Array_pop(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
+static HRESULT Array_pop(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp,
         VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
 {
+    DispatchEx *jsthis;
     VARIANT val;
     DWORD length;
-    WCHAR buf[14];
-    DISPID id;
     HRESULT hres;
 
-    static const WCHAR formatW[] = {'%','d',0};
-
     TRACE("\n");
 
-    if(is_vclass(jsthis, JSCLASS_ARRAY)) {
-        ArrayInstance *array = array_from_vdisp(jsthis);
-        length = array->length;
-    }else {
-        FIXME("not Array this\n");
-        return E_NOTIMPL;
-    }
+    hres = get_length(ctx, vthis, ei, &jsthis, &length);
+    if(FAILED(hres))
+        return hres;
 
     if(!length) {
+        hres = set_length(jsthis, ei, 0);
+        if(FAILED(hres))
+            return hres;
+
         if(retv)
             V_VT(retv) = VT_EMPTY;
         return S_OK;
     }
 
-    sprintfW(buf, formatW, --length);
-    hres = jsdisp_get_id(jsthis->u.jsdisp, buf, 0, &id);
+    length--;
+    hres = jsdisp_propget_idx(jsthis, length, &val, ei, caller);
     if(SUCCEEDED(hres)) {
-        hres = jsdisp_propget(jsthis->u.jsdisp, id, &val, ei, caller);
-        if(FAILED(hres))
-            return hres;
-
-        hres = IDispatchEx_DeleteMemberByDispID(jsthis->u.dispex, id);
-    }else if(hres == DISP_E_UNKNOWNNAME) {
+        hres = jsdisp_delete_idx(jsthis, length);
+    } else if(hres == DISP_E_UNKNOWNNAME) {
         V_VT(&val) = VT_EMPTY;
         hres = S_OK;
-    }else {
+    } else
         return hres;
-    }
 
-    if(SUCCEEDED(hres)) {
-        ArrayInstance *array = array_from_vdisp(jsthis);
-        array->length = length;
-    }
+    if(SUCCEEDED(hres))
+        hres = set_length(jsthis, ei, length);
 
     if(FAILED(hres)) {
         VariantClear(&val);
@@ -428,6 +418,7 @@ static HRESULT Array_pop(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPAR
         *retv = val;
     else
         VariantClear(&val);
+
     return S_OK;
 }
 
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index 40193a7..c8caea8 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -618,6 +618,12 @@ 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.pop = Array.prototype.pop;
+ok(arr.pop() === false, "arr.pop() !== false");
+ok(arr[8] === "b", "arr[8] !== 'b'");
+ok(arr.pop() === 'b', "arr.pop() !== 'b'");
+ok(arr[8] === undefined, "arr[8] !== undefined");
+
 arr = [3,4,5];
 tmp = arr.pop();
 ok(arr.length === 2, "arr.length = " + arr.length);
@@ -633,6 +639,11 @@ for(tmp in arr)
 tmp = arr.pop();
 ok(arr.length === 0, "arr.length = " + arr.length);
 ok(tmp === undefined, "tmp = " + tmp);
+arr = new Object();
+arr.pop = Array.prototype.pop;
+tmp = arr.pop();
+ok(arr.length === 0, "arr.length = " + arr.length);
+ok(tmp === undefined, "tmp = " + tmp);
 arr = [,,,,,];
 tmp = arr.pop();
 ok(arr.length === 5, "arr.length = " + arr.length);
@@ -1891,6 +1902,7 @@ testArrayHostThis("splice");
 testArrayHostThis("unshift");
 testArrayHostThis("reverse");
 testArrayHostThis("join");
+testArrayHostThis("pop");
 
 function testObjectInherit(obj, constr, ts, tls, vo) {
     ok(obj instanceof Object, "obj is not instance of Object");




More information about the wine-cvs mailing list