Commit 6f618936 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

jscript: Added implementation of Array.reverse.

parent e6edbc45
...@@ -469,8 +469,41 @@ static HRESULT Array_push(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPAR ...@@ -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, static HRESULT Array_reverse(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{ {
FIXME("\n"); DispatchEx *jsthis;
return E_NOTIMPL; 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 */ /* ECMA-262 3rd Edition 15.4.4.9 */
......
...@@ -688,6 +688,31 @@ ok(arr.valueOf === Object.prototype.valueOf, "arr.valueOf !== Object.prototype.v ...@@ -688,6 +688,31 @@ ok(arr.valueOf === Object.prototype.valueOf, "arr.valueOf !== Object.prototype.v
ok(arr === arr.valueOf(), "arr !== arr.valueOf"); ok(arr === arr.valueOf(), "arr !== arr.valueOf");
arr = [1,2,3]; 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); tmp = arr.unshift(0);
ok(tmp === (invokeVersion < 2 ? undefined : 4), "[1,2,3].unshift(0) returned " +tmp); ok(tmp === (invokeVersion < 2 ? undefined : 4), "[1,2,3].unshift(0) returned " +tmp);
ok(arr.length === 4, "arr.length = " + arr.length); ok(arr.length === 4, "arr.length = " + arr.length);
...@@ -1854,6 +1879,7 @@ testArrayHostThis("shift"); ...@@ -1854,6 +1879,7 @@ testArrayHostThis("shift");
testArrayHostThis("slice"); testArrayHostThis("slice");
testArrayHostThis("splice"); testArrayHostThis("splice");
testArrayHostThis("unshift"); testArrayHostThis("unshift");
testArrayHostThis("reverse");
function testObjectInherit(obj, constr, ts, tls, vo) { function testObjectInherit(obj, constr, ts, tls, vo) {
ok(obj instanceof Object, "obj is not instance of Object"); ok(obj instanceof Object, "obj is not instance of Object");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment