aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/jsruntime/qv4arrayobject.cpp4
-rw-r--r--tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml37
2 files changed, 39 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp
index d5b3b8a651..fbd757a829 100644
--- a/src/qml/jsruntime/qv4arrayobject.cpp
+++ b/src/qml/jsruntime/qv4arrayobject.cpp
@@ -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);
diff --git a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml
index 8847055a70..5103168fd3 100644
--- a/tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml
+++ b/tests/auto/qml/qqmlecmascript/data/sequenceConversion.array.qml
@@ -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 ];