aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2018-10-11 11:21:11 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2018-10-12 09:46:49 +0000
commit2755657a7a9bd088086888d7ece22c5121e0c2f4 (patch)
tree814efe641066c0722af804a461a85d18d500cf1f
parenta3a9940ea24dfcd48ffe71d2ca04cc1201884b2f (diff)
JS: Check expressions inside template literals for validity
And not use (a possibly invalid result) blindly, because this will cause assertion failures down the line. Task-number: QTBUG-71081 Change-Id: Id10149c55026094a355bd747f66014119c0e24f5 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--src/qml/compiler/qv4codegen.cpp4
-rw-r--r--tests/auto/qml/v4misc/tst_v4misc.cpp1
2 files changed, 5 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index 19e960bb57..f513184279 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -2739,6 +2739,8 @@ bool Codegen::visit(TemplateLiteral *ast)
bytecodeGenerator->addInstruction(store);
Reference expr = expression(ast->expression);
+ if (hasError)
+ return false;
if (ast->next) {
int temp2 = bytecodeGenerator->newRegister();
@@ -4084,6 +4086,8 @@ void Codegen::Reference::storeOnStack(int slotIndex) const
Codegen::Reference Codegen::Reference::doStoreOnStack(int slotIndex) const
{
+ Q_ASSERT(isValid());
+
if (isStackSlot() && slotIndex == -1 && !(stackSlotIsLocalOrArgument && isVolatile) && !requiresTDZCheck)
return *this;
diff --git a/tests/auto/qml/v4misc/tst_v4misc.cpp b/tests/auto/qml/v4misc/tst_v4misc.cpp
index 21a826850b..a080826e15 100644
--- a/tests/auto/qml/v4misc/tst_v4misc.cpp
+++ b/tests/auto/qml/v4misc/tst_v4misc.cpp
@@ -110,6 +110,7 @@ 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.");
+ QTest::newRow("`a${1++}`") << QString("ReferenceError: Invalid left-hand side expression in postfix operation");
}
void tst_v4misc::parserMisc()