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 /tests/auto/qml/qqmlecmascript/data | |
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 'tests/auto/qml/qqmlecmascript/data')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/functionAsDefaultArgument.qml | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/functionAsDefaultArgument.qml b/tests/auto/qml/qqmlecmascript/data/functionAsDefaultArgument.qml new file mode 100644 index 0000000000..9f576d1af8 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/functionAsDefaultArgument.qml @@ -0,0 +1,8 @@ +import QtQml 2.15 + +QtObject { + id: root + + function f(inner=function(){ root.objectName = "didRun" } ){ inner() } + Component.onCompleted: f() +} |