diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-05-11 11:21:47 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-05-11 17:25:24 +0000 |
commit | d3a1e510f04137150f40204382bf5fffd2c2eebe (patch) | |
tree | 837a150f18ab9b778af9d3783cb63f253363177e /tests/auto/qml | |
parent | 8fd84a4ad487009ec493ad26af50e7a9f5a454f9 (diff) |
Add test case for delete inside a for-in loop
We had a bug where deleting a property on an object that is being
iterated on via a for-in loop would end up iterating too few times
because the iterator compared its progress against the size of the
internal class, which shrunk with each delete call. Commit
ea164ca4a8ec1e5c568ab82c0c4256a841f77bf0 fixed that by retaining the IC
size but just making the deleted members inaccessible, thereby
"accidentally" fixing QTBUG-40021. This change adds a test for the bug
to ensure that we don't regress.
Task-number: QTBUG-40021
Change-Id: Ie75906b665036c311256d86289c158ee0d29f8b7
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r-- | tests/auto/qml/qjsengine/tst_qjsengine.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index 0c86fb2611..85b4484403 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -210,6 +210,8 @@ private slots: void incrementAfterNewline(); + void deleteInsideForIn(); + signals: void testSignal(); }; @@ -4205,6 +4207,19 @@ void tst_QJSEngine::incrementAfterNewline() QVERIFY(result.toNumber() == -1); } +void tst_QJSEngine::deleteInsideForIn() +{ + QJSEngine engine; + + QJSValue iterationCount = engine.evaluate( + "var o = { a: 1, b: 2, c: 3, d: 4};\n" + "var count = 0;\n" + "for (var prop in o) { count++; delete o[prop]; }\n" + "count"); + QVERIFY(iterationCount.isNumber()); + QCOMPARE(iterationCount.toInt(), 4); +} + QTEST_MAIN(tst_QJSEngine) #include "tst_qjsengine.moc" |