From 94d6186445a94fb54e2bac56a600117c790064e5 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 22 Jan 2013 22:43:07 +0100 Subject: [PATCH] Fixed remaining failures for Array.prototype.reverse Change-Id: I688a35f8873012efa3202b18d050542a6ddde196 Reviewed-by: Simon Hausmann --- qv4arrayobject.cpp | 24 +++++++++++++++--------- tests/TestExpectations | 10 ---------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/qv4arrayobject.cpp b/qv4arrayobject.cpp index b740d6d..04a7090 100644 --- a/qv4arrayobject.cpp +++ b/qv4arrayobject.cpp @@ -275,19 +275,25 @@ Value ArrayPrototype::method_push(ExecutionContext *ctx) Value ArrayPrototype::method_reverse(ExecutionContext *ctx) { - ArrayObject *instance = ctx->thisObject.asArrayObject(); - if (!instance) - ctx->throwUnimplemented(QStringLiteral("Array.prototype.reverse")); + Object *instance = __qmljs_to_object(ctx->thisObject, ctx).objectValue(); + uint length = getLength(ctx, instance); - int lo = 0, hi = instance->array.length() - 1; + int lo = 0, hi = length - 1; - // ### for (; lo < hi; ++lo, --hi) { - Value tmp = instance->__get__(ctx, lo); - instance->array.set(lo, instance->__get__(ctx, hi)); - instance->array.set(hi, tmp); + bool loExists, hiExists; + Value lval = instance->__get__(ctx, lo, &loExists); + Value hval = instance->__get__(ctx, hi, &hiExists); + if (hiExists) + instance->__put__(ctx, lo, hval); + else + instance->__delete__(ctx, lo); + if (loExists) + instance->__put__(ctx, hi, lval); + else + instance->__delete__(ctx, hi); } - return Value::undefinedValue(); + return Value::fromObject(instance); } Value ArrayPrototype::method_shift(ExecutionContext *ctx) diff --git a/tests/TestExpectations b/tests/TestExpectations index 914d19d..1618263 100644 --- a/tests/TestExpectations +++ b/tests/TestExpectations @@ -337,16 +337,6 @@ S15.4.4.4_A2_T1 failing S15.4.4.4_A2_T2 failing S15.4.4.4_A3_T1 failing S15.5.4.11_A5_T1 failing -S15.4.4.8_A1_T1 failing -S15.4.4.8_A1_T2 failing -S15.4.4.8_A2_T1 failing -S15.4.4.8_A2_T2 failing -S15.4.4.8_A2_T3 failing -S15.4.4.8_A3_T1 failing -S15.4.4.8_A3_T2 failing -S15.4.4.8_A3_T3 failing -S15.4.4.8_A4_T1 failing -S15.4.4.8_A4_T2 failing 15.5.4.20-4-1 failing S15.5.4.8_A1_T4 failing S15.7.4.5_A1.4_T01 failing -- 2.7.4