diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2018-10-11 12:25:09 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2018-10-15 10:50:50 +0000 |
commit | 1a1e5789c754838473cbb81665667a4d3a42e33b (patch) | |
tree | 51987d628da11e3ccda07c1231115065c8320d1a | |
parent | 67fbdadb3ba1aa9f86ae2d6ca3bff69479fb12be (diff) |
JS: Check lhs of an 'in' expression to be an lvalue
For example: 'for (foo() in something) {}' is not valid: a call
expression is not an lvalue.
Task-number: QTBUG-71086
Change-Id: Ia1498cd38526b073afb8e4524ceaea14dca3d65f
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qml/v4misc/tst_v4misc.cpp | 1 |
2 files changed, 5 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 0776165d2a..8ff8ab7993 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -3307,6 +3307,10 @@ bool Codegen::visit(ForEachStatement *ast) Reference lhs = expression(e); if (hasError) goto error; + if (!lhs.isLValue()) { + throwReferenceError(e->firstSourceLocation(), QStringLiteral("Invalid left-hand side expression for 'in' expression")); + goto error; + } lhs = lhs.asLValue(); lhsValue.loadInAccumulator(); lhs.storeConsumeAccumulator(); diff --git a/tests/auto/qml/v4misc/tst_v4misc.cpp b/tests/auto/qml/v4misc/tst_v4misc.cpp index e1796d18b4..ff04be523b 100644 --- a/tests/auto/qml/v4misc/tst_v4misc.cpp +++ b/tests/auto/qml/v4misc/tst_v4misc.cpp @@ -112,6 +112,7 @@ void tst_v4misc::parserMisc_data() QTest::newRow("8[++i][+++i]") << QString("ReferenceError: Prefix ++ operator applied to value that is not a reference."); QTest::newRow("`a${1++}`") << QString("ReferenceError: Invalid left-hand side expression in postfix operation"); QTest::newRow("for (var f in ++!binaryMathg) ;") << QString("ReferenceError: Prefix ++ operator applied to value that is not a reference."); + QTest::newRow("for (va() in obj) {}") << QString("ReferenceError: Invalid left-hand side expression for 'in' expression"); } void tst_v4misc::parserMisc() |