From 8780764b274217b256aadd00114a76bdffbdb1ef Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 10 Apr 2018 11:07:24 +0200 Subject: Warn about non spec compliant extension being used eval("function(){}") would return a function object in our engine. This is not compliant with the ES spec, so warn about it, as it'll start throwing a syntax error in 5.12. Also fix the two places where we were using that syntax in our auto tests. Change-Id: I573c2ad0ec4955570b857c69edef2f75998d55a9 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4script.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index b4d9e11716..afa7d2ed52 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -90,6 +90,12 @@ void Script::parse() Module module(v4->debugger() != nullptr); + if (sourceCode.startsWith(QLatin1String("function("))) { + qWarning() << "Warning: Using function expressions as statements in scripts in not compliant with the ECMAScript specification at\n" + << (sourceCode.leftRef(70) + QLatin1String("...")) + << "\nThis will throw a syntax error in Qt 5.12. If you want a function expression, surround it by parentheses."; + } + Engine ee, *engine = ⅇ Lexer lexer(engine); lexer.setCode(sourceCode, line, parseAsBinding); -- cgit v1.2.3