Piotr Caban : jscript: Make Array.sort generic.

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


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

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

jscript: Make Array.sort generic.

---

 dlls/jscript/array.c      |   25 +++++++++++--------------
 dlls/jscript/tests/api.js |   10 ++++++++++
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/dlls/jscript/array.c b/dlls/jscript/array.c
index 15a6e78..b6fcd3c 100644
--- a/dlls/jscript/array.c
+++ b/dlls/jscript/array.c
@@ -685,10 +685,10 @@ static HRESULT sort_cmp(script_ctx_t *ctx, DispatchEx *cmp_func, VARIANT *v1, VA
 }
 
 /* ECMA-262 3rd Edition    15.4.4.11 */
-static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
+static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp,
         VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
 {
-    DispatchEx *cmp_func = NULL;
+    DispatchEx *jsthis, *cmp_func = NULL;
     VARIANT *vtab, **sorttab = NULL;
     DWORD length;
     DWORD i;
@@ -696,12 +696,9 @@ static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPA
 
     TRACE("\n");
 
-    if(is_vclass(jsthis, JSCLASS_ARRAY)) {
-        length = array_from_vdisp(jsthis)->length;
-    }else {
-        FIXME("unsupported this not array\n");
-        return E_NOTIMPL;
-    }
+    hres = get_length(ctx, vthis, ei, &jsthis, &length);
+    if(FAILED(hres))
+        return hres;
 
     if(arg_cnt(dp) > 1) {
         WARN("invalid arg_cnt %d\n", arg_cnt(dp));
@@ -731,8 +728,8 @@ static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPA
             jsdisp_release(cmp_func);
         if(retv) {
             V_VT(retv) = VT_DISPATCH;
-            V_DISPATCH(retv) = jsthis->u.disp;
-	    IDispatch_AddRef(jsthis->u.disp);
+            V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(jsthis);
+	    IDispatch_AddRef(V_DISPATCH(retv));
         }
         return S_OK;
     }
@@ -740,7 +737,7 @@ static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPA
     vtab = heap_alloc_zero(length * sizeof(VARIANT));
     if(vtab) {
         for(i=0; i<length; i++) {
-            hres = jsdisp_propget_idx(jsthis->u.jsdisp, i, vtab+i, ei, caller);
+            hres = jsdisp_propget_idx(jsthis, i, vtab+i, ei, caller);
             if(FAILED(hres) && hres != DISP_E_UNKNOWNNAME) {
                 WARN("Could not get elem %d: %08x\n", i, hres);
                 break;
@@ -817,7 +814,7 @@ static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPA
         }
 
         for(i=0; SUCCEEDED(hres) && i < length; i++)
-            hres = jsdisp_propput_idx(jsthis->u.jsdisp, i, sorttab[i], ei, caller);
+            hres = jsdisp_propput_idx(jsthis, i, sorttab[i], ei, caller);
     }
 
     if(vtab) {
@@ -834,8 +831,8 @@ static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPA
 
     if(retv) {
         V_VT(retv) = VT_DISPATCH;
-        V_DISPATCH(retv) = jsthis->u.disp;
-        IDispatch_AddRef(jsthis->u.disp);
+        V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(jsthis);
+        IDispatch_AddRef(V_DISPATCH(retv));
     }
 
     return S_OK;
diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js
index c8caea8..2fba252 100644
--- a/dlls/jscript/tests/api.js
+++ b/dlls/jscript/tests/api.js
@@ -695,6 +695,15 @@ ok(arr.sort() === arr, "arr.sort() !== arr");
 for(var i=0; i < arr.length; i++)
     ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
 
+arr = new Object();
+arr.length = 3;
+arr[0] = 1;
+arr[2] = "aa";
+arr.sort = Array.prototype.sort;
+tmp = arr.sort();
+ok(arr === tmp, "tmp !== arr");
+ok(arr[0]===1 && arr[1]==="aa" && arr[2]===undefined, "arr is sorted incorectly");
+
 arr = ["1", "2", "3"];
 arr.length = 1;
 ok(arr.length === 1, "arr.length = " + arr.length);
@@ -1903,6 +1912,7 @@ testArrayHostThis("unshift");
 testArrayHostThis("reverse");
 testArrayHostThis("join");
 testArrayHostThis("pop");
+testArrayHostThis("sort");
 
 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