diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-12-12 11:51:04 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-12-13 08:58:52 +0000 |
commit | 904179cb681e28b248d892e699f5706666a1b4fc (patch) | |
tree | 61bf6c68be99f05d295d1fd304a97fde7a4ca385 /tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | |
parent | 93ad68de3a3873cbdc33336520bd0b6443312ec1 (diff) |
Fix iterator assignment for for-in loops
When iterating over an object using an for-in loop, the value for the
next iteration should be assigned in the body of the loop. This means
that after the loop, the value of the last iteration is still assigned
to that variable, not null (which marks the end of the iterable values).
Task-number: QTBUG-65104
Change-Id: Icbddbc67723719005120587bcdc63dcdfa52b67f
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 4415e6cf74..71bb357a43 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -345,6 +345,8 @@ private slots: void qtbug_60547(); void delayLoadingArgs(); void manyArguments(); + void forInIterator(); + void localForInIterator(); private: // static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter); @@ -8394,6 +8396,37 @@ void tst_qqmlecmascript::manyArguments() engine.evaluate(testCase); } +void tst_qqmlecmascript::forInIterator() +{ + auto testCase = + "(function(){\n" + "var x = 'yoyo'\n" + "var i\n" + "for (i in x) {\n" + "}\n" + "return i\n" + "})()"; + QJSEngine engine; + QJSValue ret = engine.evaluate(testCase); + QVERIFY(ret.isString()); + QCOMPARE(ret.toString(), QStringLiteral("3")); +} + +void tst_qqmlecmascript::localForInIterator() +{ + auto testCase = + "(function(){\n" + "var x = 'yoyo'\n" + "for (var i in x) {\n" + "}\n" + "return i\n" + "})()"; + QJSEngine engine; + QJSValue ret = engine.evaluate(testCase); + QVERIFY(ret.isString()); + QCOMPARE(ret.toString(), QStringLiteral("3")); +} + QTEST_MAIN(tst_qqmlecmascript) |