aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/qml/qqmlexpression.cpp5
-rw-r--r--src/qml/qml/qqmljavascriptexpression.cpp14
-rw-r--r--tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp6
3 files changed, 15 insertions, 10 deletions
diff --git a/src/qml/qml/qqmlexpression.cpp b/src/qml/qml/qqmlexpression.cpp
index 59cc9bb09f..27d3acb9b7 100644
--- a/src/qml/qml/qqmlexpression.cpp
+++ b/src/qml/qml/qqmlexpression.cpp
@@ -252,6 +252,11 @@ QV4::ReturnedValue QQmlExpressionPrivate::v4value(bool *isUndefined)
if (!expressionFunctionValid) {
createQmlBinding(context(), scopeObject(), expression, url, line);
expressionFunctionValid = true;
+ if (hasError()) {
+ if (isUndefined)
+ *isUndefined = true;
+ return QV4::Encode::undefined();
+ }
}
return evaluate(isUndefined);
diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp
index 74148e3ca4..3daa107b64 100644
--- a/src/qml/qml/qqmljavascriptexpression.cpp
+++ b/src/qml/qml/qqmljavascriptexpression.cpp
@@ -451,15 +451,11 @@ void QQmlJavaScriptExpression::createQmlBinding(QQmlContextData *ctxt, QObject *
QV4::Script script(v4, qmlContext, code, filename, line);
script.parse();
if (v4->hasException) {
- QQmlError error = v4->catchExceptionAsQmlError();
- if (error.description().isEmpty())
- error.setDescription(QLatin1String("Exception occurred during function evaluation"));
- if (error.line() == -1)
- error.setLine(line);
- if (error.url().isEmpty())
- error.setUrl(QUrl::fromLocalFile(filename));
- error.setObject(qmlScope);
- ep->warning(error);
+ QQmlDelayedError *error = delayedError();
+ error->catchJavaScriptException(v4);
+ error->setErrorObject(qmlScope);
+ if (!error->addError(ep))
+ ep->warning(error);
return;
}
setupFunction(qmlContext, script.vmFunction);
diff --git a/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp b/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp
index e1ad1e8c5f..1decc04ad2 100644
--- a/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp
+++ b/tests/auto/qml/qqmlexpression/tst_qqmlexpression.cpp
@@ -101,8 +101,12 @@ void tst_qqmlexpression::syntaxError()
{
QQmlEngine engine;
QQmlExpression expression(engine.rootContext(), nullptr, "asd asd");
- QVariant v = expression.evaluate();
+ bool isUndefined = false;
+ QVariant v = expression.evaluate(&isUndefined);
QCOMPARE(v, QVariant());
+ QVERIFY(expression.hasError());
+ QCOMPARE(expression.error().description(), "SyntaxError: Expected token `;'");
+ QVERIFY(isUndefined);
}
void tst_qqmlexpression::exception()