shift and unshift fail for QQmlSequence types
authorMartin Jones <martin.jones@jollamobile.com>
Wed, 16 Jul 2014 03:20:53 +0000 (13:20 +1000)
committerRobin Burchell <robin+qt@viroteck.net>
Tue, 22 Jul 2014 10:24:53 +0000 (12:24 +0200)
QQmlSequence is a Custom array type, so must use the generic
shift/unshift implementation.

Task-number: QTBUG-40244
Change-Id: I491d9dc87a3a204daad4cf7460ffac81165056a5
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/jsruntime/qv4arrayobject.cpp
tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml

index d5b3b8a..fbd757a 100644 (file)
@@ -371,7 +371,7 @@ ReturnedValue ArrayPrototype::method_shift(CallContext *ctx)
 
     ScopedValue result(scope);
 
-    if (!instance->protoHasArray() && !instance->arrayData->hasAttributes() && instance->arrayData->length() <= len) {
+    if (!instance->protoHasArray() && !instance->arrayData->hasAttributes() && instance->arrayData->length() <= len && instance->arrayData->type != ArrayData::Custom) {
         result = instance->arrayData->vtable()->pop_front(instance.getPointer());
     } else {
         result = instance->getIndexed(0);
@@ -550,7 +550,7 @@ ReturnedValue ArrayPrototype::method_unshift(CallContext *ctx)
 
     uint len = instance->getLength();
 
-    if (!instance->protoHasArray() && !instance->arrayData->hasAttributes() && instance->arrayData->length() <= len) {
+    if (!instance->protoHasArray() && !instance->arrayData->hasAttributes() && instance->arrayData->length() <= len && instance->arrayData->type != ArrayData::Custom) {
         instance->arrayData->vtable()->push_front(instance.getPointer(), ctx->callData->args, ctx->callData->argc);
     } else {
         ScopedValue v(scope);
index 8847055..5103168 100644 (file)
@@ -165,6 +165,43 @@ Item {
                 }
             }
         }
+
+        // unshift
+        msco.stringListProperty = [ "one", "two" ]
+        var unshiftedVal = msco.stringListProperty.unshift("zero")
+        expected = [ "zero", "one", "two" ]
+        if (msco.stringListProperty.toString() != expected.toString()) success = false;
+        expected = 3
+        if (msco.stringListProperty.length != expected) success = false
+        msco.stringListProperty = [ ]
+        msco.stringListProperty.unshift("zero", "one")
+        expected = [ "zero", "one" ]
+        if (msco.stringListProperty.toString() != expected.toString()) success = false;
+        expected = 2
+        if (msco.stringListProperty.length != expected) success = false
+
+        // shift
+        msco.stringListProperty = [ "one", "two", "three" ]
+        var shiftVal = msco.stringListProperty.shift()
+        expected = [ "two", "three" ]
+        if (msco.stringListProperty.toString() != expected.toString()) success = false;
+        expected = "one"
+        if (shiftVal != expected) success = false
+        shiftVal = msco.stringListProperty.shift()
+        expected = [ "three" ]
+        if (msco.stringListProperty.toString() != expected.toString()) success = false;
+        expected = "two"
+        if (shiftVal != expected) success = false
+        shiftVal = msco.stringListProperty.shift()
+        expected = 0
+        if (msco.stringListProperty.length != expected) success = false;
+        expected = "three"
+        if (shiftVal != expected) success = false
+        shiftVal = msco.stringListProperty.shift()
+        expected = 0
+        if (msco.stringListProperty.length != expected) success = false;
+        expected = undefined
+        if (shiftVal != expected) success = false
     }
 
     property variant variantList: [ 1, 2, 3, 4, 5 ];