aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4script.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-06-02 12:01:20 +0200
committerUlf Hermann <ulf.hermann@qt.io>2025-06-04 09:09:49 +0200
commit681352aaeba998a02c76cd5df0695eb6381f0ad2 (patch)
tree3fe99c6f0ecd50e4602f1f9e6a190cbb90e03b5b /src/qml/jsruntime/qv4script.cpp
parentddcafa0a51c65d86f6b5481f06fce5faeb75920d (diff)
QML: Turn warning into a syntax error
It has wanted to be a syntax error since Qt 5.12. [ChangeLog][QtQml] Using a bare function expression in eval() is now correctly recognized as syntax error. You have to surround it in parentheses to make it a statement. This has been generating warnings since Qt 5.11 and it should have become an error already in 5.12. Change-Id: Icb80ff62bf75d3510c43767ccc3477600af6cb63 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4script.cpp')
-rw-r--r--src/qml/jsruntime/qv4script.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp
index d8f6ebbf48..357f638031 100644
--- a/src/qml/jsruntime/qv4script.cpp
+++ b/src/qml/jsruntime/qv4script.cpp
@@ -55,9 +55,14 @@ void Script::parse()
if (sourceCode.startsWith(QLatin1String("function("))) {
static const int snippetLength = 70;
- qWarning() << "Warning: Using function expressions as statements in scripts is not compliant with the ECMAScript specification:\n"
- << (QStringView{sourceCode}.left(snippetLength) + QLatin1String("..."))
- << "\nThis will throw a syntax error in Qt 5.12. If you want a function expression, surround it by parentheses.";
+ v4->throwSyntaxError(
+ QLatin1String(
+ "Using function expressions as statements in scripts is not compliant "
+ "with the ECMAScript specification:"
+ "\n%1...\n"
+ "If you want a function expression, surround it by parentheses.")
+ .arg(QStringView{sourceCode}.left(snippetLength)));
+ return;
}
Engine ee, *engine = &ee;