From f60cde61149655d004343ab97f18b3414871d75b Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 6 Jan 2020 15:29:41 +0100 Subject: V4: Fix sorting of sparse arrays setArrayData() needs to handle a nullptr argument. Change-Id: I1ea05d9db9beb1fede6d3c068cfcf700702e8aa6 Reviewed-by: Fabian Kosmale --- tests/auto/qml/qjsengine/tst_qjsengine.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/auto/qml/qjsengine') 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" -- cgit v1.2.3