diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-01-06 15:29:41 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-01-06 15:39:25 +0100 |
commit | f60cde61149655d004343ab97f18b3414871d75b (patch) | |
tree | 1c2a39bd1bb90560c57c3a2e3bc105fbe6181fe2 /tests/auto/qml/qjsengine | |
parent | 6fa617524a6d0a2bc988e2dc70e8d719d1b9c282 (diff) |
V4: Fix sorting of sparse arrays
setArrayData() needs to handle a nullptr argument.
Change-Id: I1ea05d9db9beb1fede6d3c068cfcf700702e8aa6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qjsengine')
-rw-r--r-- | tests/auto/qml/qjsengine/tst_qjsengine.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index 59319bead2..9f697e5a74 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -253,6 +253,7 @@ private slots: void triggerBackwardJumpWithDestructuring(); void arrayConcatOnSparseArray(); + void sortSparseArray(); public: Q_INVOKABLE QJSValue throwingCppMethod1(); @@ -4982,6 +4983,26 @@ void tst_QJSEngine::arrayConcatOnSparseArray() QVERIFY(value.property(i).isUndefined()); } +void tst_QJSEngine::sortSparseArray() +{ + QJSEngine engine; + engine.installExtensions(QJSEngine::ConsoleExtension); + const auto value = engine.evaluate( + "(function() {\n" + " var sparse = [0];\n" + " sparse = Object.defineProperty(sparse, \"10\", " + " {get: ()=>{return 2}, set: ()=>{return 2}} );\n" + " return Array.prototype.sort.call(sparse, ()=>{});\n" + "})();"); + + QCOMPARE(value.property("length").toInt(), 11); + QVERIFY(value.property(0).isNumber()); + QCOMPARE(value.property(0).toInt(), 0); + QVERIFY(value.property(1).isNumber()); + QCOMPARE(value.property(1).toInt(), 2); + QVERIFY(value.property(10).isUndefined()); +} + QTEST_MAIN(tst_QJSEngine) #include "tst_qjsengine.moc" |