jscript: Added implementation of Array.reverse.

This commit is contained in:
Piotr Caban 2010-01-15 08:17:30 +01:00 committed by Alexandre Julliard
parent e6edbc451d
commit 6f61893685
2 changed files with 61 additions and 2 deletions

View File

@ -469,8 +469,41 @@ static HRESULT Array_push(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPAR
static HRESULT Array_reverse(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
DispatchEx *jsthis;
DWORD length, k, l;
VARIANT v1, v2;
HRESULT hres1, hres2;
TRACE("\n");
hres1 = get_length(ctx, vthis, ei, &jsthis, &length);
if(FAILED(hres1))
return hres1;
for(k=0; k<length/2; k++) {
l = length-k-1;
hres1 = jsdisp_propget_idx(jsthis, k, &v1, ei, sp);
hres2 = jsdisp_propget_idx(jsthis, l, &v2, ei, sp);
if(hres1 == DISP_E_UNKNOWNNAME)
jsdisp_delete_idx(jsthis, l);
else
jsdisp_propput_idx(jsthis, l, &v1, ei, sp);
if(hres2 == DISP_E_UNKNOWNNAME)
jsdisp_delete_idx(jsthis, k);
else
jsdisp_propput_idx(jsthis, k, &v2, ei, sp);
}
if(retv) {
V_VT(retv) = VT_DISPATCH;
V_DISPATCH(retv) = (IDispatch*)_IDispatchEx_(jsthis);
IDispatch_AddRef(V_DISPATCH(retv));
}
return S_OK;
}
/* ECMA-262 3rd Edition 15.4.4.9 */

View File

@ -687,6 +687,31 @@ ok(arr.toString() === "a,b,c", "arr.toString() = " + arr.toString());
ok(arr.valueOf === Object.prototype.valueOf, "arr.valueOf !== Object.prototype.valueOf");
ok(arr === arr.valueOf(), "arr !== arr.valueOf");
arr = [1,2,3];
tmp = arr.reverse();
ok(tmp === arr, "tmp !== arr");
ok(arr.length === 3, "arr.length = " + arr.length);
ok(arr.toString() === "3,2,1", "arr.toString() = " + arr.toString());
arr = [];
arr[3] = 5;
arr[5] = 1;
tmp = arr.reverse();
ok(tmp === arr, "tmp !== arr");
ok(arr.length === 6, "arr.length = " + arr.length);
ok(arr.toString() === "1,,5,,,", "arr.toString() = " + arr.toString());
arr = new Object();
arr.length = 3;
arr[0] = "aa";
arr[2] = 2;
arr[7] = 3;
arr.reverse = Array.prototype.reverse;
tmp = arr.reverse();
ok(tmp === arr, "tmp !== arr");
ok(arr.length === 3, "arr.length = " + arr.length);
ok(arr[0] === 2 && arr[1] === undefined && arr[2] === "aa", "unexpected array");
arr = [1,2,3];
tmp = arr.unshift(0);
ok(tmp === (invokeVersion < 2 ? undefined : 4), "[1,2,3].unshift(0) returned " +tmp);
@ -1854,6 +1879,7 @@ testArrayHostThis("shift");
testArrayHostThis("slice");
testArrayHostThis("splice");
testArrayHostThis("unshift");
testArrayHostThis("reverse");
function testObjectInherit(obj, constr, ts, tls, vo) {
ok(obj instanceof Object, "obj is not instance of Object");