summaryrefslogtreecommitdiff
path: root/src/qml/compiler/qv4compilerscanfunctions_p.h
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-11-10 14:26:54 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2021-11-10 22:02:29 +0100
commitbe194d965d530e57ed5851781c6805e691c6ae98 (patch)
treea5c3b0d03b3c2f5179c646bbcb06293c526caf16 /src/qml/compiler/qv4compilerscanfunctions_p.h
parent3d23912b0e9710dad7ecaf238690e4a7d253534d (diff)
downloadqtdeclarative-be194d965d530e57ed5851781c6805e691c6ae98.tar.gz
Handle function as default arguments in toplevel functions
Top level functions, that is, those directly defined in a QML component as opposed to those defined inside another function or class, are not visited directly by the ScanFunction visitor. Instead, they are manually considered in generateJSCodeForFunctionsAndBindings, and the visitor is then run on their body. This worked mostly fine, with one notable exception: In case there is a function expression used as the default value of a function parameter, that function would have never been visited. This would lead to subsequent asserts/crashes in the codegen, as the function was not properly set up. We fix this by manually visiting the function's formals in addition to the body. Pick-to: 6.2 5.15 Fixes: QTBUG-98032 Change-Id: I5cb4caae39ab45f01a0dfa1555099d7d4b796a19 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilerscanfunctions_p.h')
-rw-r--r--src/qml/compiler/qv4compilerscanfunctions_p.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4compilerscanfunctions_p.h b/src/qml/compiler/qv4compilerscanfunctions_p.h
index 073ee5c2a4..d2868fc428 100644
--- a/src/qml/compiler/qv4compilerscanfunctions_p.h
+++ b/src/qml/compiler/qv4compilerscanfunctions_p.h
@@ -83,6 +83,13 @@ public:
ScanFunctions(Codegen *cg, const QString &sourceCode, ContextType defaultProgramType);
void operator()(QQmlJS::AST::Node *node);
+ // see comment at its call site in generateJSCodeForFunctionsAndBindings
+ // for why this function is necessary
+ void handleTopLevelFunctionFormals(QQmlJS::AST::FunctionExpression *node) {
+ if (node && node->formals)
+ node->formals->accept(this);
+ }
+
void enterGlobalEnvironment(ContextType compilationMode);
void enterEnvironment(QQmlJS::AST::Node *node, ContextType compilationMode,
const QString &name);