summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2018-10-11 10:48:19 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2018-11-16 09:47:15 +0000
commitf92c48a231d5f98513e649340652baaf01f327ad (patch)
treea6011016996842e6eca514b1ad4c9331af8d8f76
parent7eaa93680ce583354f23f3b29bd6db59169dfece (diff)
JS: Check array subscripts for validity when generating code
Task-number: QTBUG-71079 Change-Id: I999130f3994f513bb9d2ca8ddaa94688451937fc Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> (cherry picked from commit b8f4005f132c26b842387e1ae5f492594dc03d86) Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/qml/compiler/qv4codegen.cpp2
-rw-r--r--tests/auto/qml/v4misc/tst_v4misc.cpp22
2 files changed, 23 insertions, 1 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index e831fd48f5..7307ee3bd8 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -679,6 +679,8 @@ bool Codegen::visit(ArrayMemberExpression *ast)
return false;
}
Reference index = expression(ast->expression);
+ if (hasError)
+ return false;
_expr.setResult(Reference::fromSubscript(base, index));
return false;
}
diff --git a/tests/auto/qml/v4misc/tst_v4misc.cpp b/tests/auto/qml/v4misc/tst_v4misc.cpp
index 55a1f65608..ff9d41805f 100644
--- a/tests/auto/qml/v4misc/tst_v4misc.cpp
+++ b/tests/auto/qml/v4misc/tst_v4misc.cpp
@@ -45,6 +45,9 @@ private slots:
void moveMapping_1();
void moveMapping_2();
+
+ void parserMisc_data();
+ void parserMisc();
};
using namespace QT_PREPEND_NAMESPACE(QV4::IR);
@@ -227,6 +230,23 @@ void tst_v4misc::moveMapping_2()
QVERIFY(mapping._moves.at(9).needsSwap);
}
-QTEST_MAIN(tst_v4misc)
+void tst_v4misc::parserMisc_data()
+{
+ QTest::addColumn<QString>("error");
+
+ QTest::newRow("8[++i][+++i]") << QString("ReferenceError: Prefix ++ operator applied to value that is not a reference.");
+}
+
+void tst_v4misc::parserMisc()
+{
+ QFETCH(QString, error);
+
+ QJSEngine engine;
+ QJSValue result = engine.evaluate(QString::fromUtf8(QTest::currentDataTag()));
+ QVERIFY(result.isError());
+ QCOMPARE(result.toString(), error);
+}
+
+QTEST_MAIN(tst_v4misc);
#include "tst_v4misc.moc"