diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-11-10 14:26:54 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-11-10 22:02:29 +0100 |
commit | be194d965d530e57ed5851781c6805e691c6ae98 (patch) | |
tree | a5c3b0d03b3c2f5179c646bbcb06293c526caf16 /src/qml/compiler/qqmlirbuilder.cpp | |
parent | 3d23912b0e9710dad7ecaf238690e4a7d253534d (diff) |
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/qqmlirbuilder.cpp')
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 9605eda030..b7295626ae 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -1984,6 +1984,12 @@ QVector<int> JSCodeGen::generateJSCodeForFunctionsAndBindings( scan.enterEnvironment(f.parentNode, QV4::Compiler::ContextType::Binding, qmlName(f)); } + /* We do not want to visit the whole function, as we already called enterQmlFunction + However, there might be a function defined as a default argument of the function. + That needs to be considered, too, so we call handleTopLevelFunctionFormals to + deal with them. + */ + scan.handleTopLevelFunctionFormals(function); scan(function ? function->body : f.node); scan.leaveEnvironment(); } |