aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
diff options
context:
space:
mode:
authorGlenn Watson <glenn.watson@nokia.com>2012-07-18 13:20:00 +1000
committerQt by Nokia <qt-info@nokia.com>2012-08-08 00:34:22 +0200
commitec519529087cc3005d55242569dcbca3dcee91bf (patch)
tree9fb83a2396c62e5231b11aaff013e94ed7f239dc /tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
parent8bb5677f45935a03f1ed439e8a01ca71e9f1152c (diff)
Support JS Array.sort() function for sequence wrappers.
The V8 natve sort implementation calls some functions that are incompatible with the way sequence wrappers work. In particular, it calls an internal length() function which does not pass through the length accessor provided by sequence wrappers, so the sort function always thinks the array is zero length. Instead, clone the array prototype and override the sort function with one that is specific to sequence wrappers. Task-number: QTBUG-25269 Change-Id: Ic83b9ee0bd3a0707e512f28057f0f99b432fded4 Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp')
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 4e1638f516..f6ec475d40 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -186,6 +186,8 @@ private slots:
void sequenceConversionBindings();
void sequenceConversionCopy();
void assignSequenceTypes();
+ void sequenceSort_data();
+ void sequenceSort();
void qtbug_22464();
void qtbug_21580();
void singleV8BindingDestroyedDuringEvaluation();
@@ -7121,6 +7123,48 @@ void tst_qqmlecmascript::fallbackBindings()
QCOMPARE(object->property("success").toBool(), true);
}
+void tst_qqmlecmascript::sequenceSort_data()
+{
+ QTest::addColumn<QString>("function");
+ QTest::addColumn<bool>("useComparer");
+
+ QTest::newRow("qtbug_25269") << "test_qtbug_25269" << false;
+
+ const char *types[] = { "alphabet", "numbers", "reals" };
+ const char *sort[] = { "insertionSort", "quickSort" };
+
+ for (size_t t=0 ; t < sizeof(types)/sizeof(types[0]) ; ++t) {
+ for (size_t s=0 ; s < sizeof(sort)/sizeof(sort[0]) ; ++s) {
+ for (int c=0 ; c < 2 ; ++c) {
+ QString testName = QLatin1String(types[t]) + QLatin1String("_") + QLatin1String(sort[s]);
+ QString fnName = QLatin1String("test_") + testName;
+ bool useComparer = c != 0;
+ testName += useComparer ? QLatin1String("[custom]") : QLatin1String("[default]");
+ QTest::newRow(testName.toAscii().constData()) << fnName << useComparer;
+ }
+ }
+ }
+}
+
+void tst_qqmlecmascript::sequenceSort()
+{
+ QFETCH(QString, function);
+ QFETCH(bool, useComparer);
+
+ QQmlComponent component(&engine, testFileUrl("sequenceSort.qml"));
+
+ QObject *object = component.create();
+ if (object == 0)
+ qDebug() << component.errorString();
+ QVERIFY(object != 0);
+
+ QVariant q;
+ QMetaObject::invokeMethod(object, function.toAscii().constData(), Q_RETURN_ARG(QVariant, q), Q_ARG(QVariant, useComparer));
+ QVERIFY(q.toBool() == true);
+
+ delete object;
+}
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"