diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-08-02 11:53:56 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-06 16:53:19 +0000 |
commit | b93c56568613a57fb8abaacbecb6be352c2c2185 (patch) | |
tree | 97413e632124c0fc9a227d3850f5fd303cc5245f /tests | |
parent | 19be4d51814f6b83708a5f867f7c5bf813240518 (diff) |
QQmlObjectCreator: Add scripts also to context of inline components
The object creator only called setImportedScripts on a context if
subComponentIndex was -1 (indicating the root of a component). However,
since the introduction of inline components, subcomponents can also be
component roots. This patch adjusts the check to also consider inline
components. This fixes the issue that javascript libraries could nod be
referenced inside inline components.
Fixes: QTBUG-95095
Change-Id: I22d14c6f102edca6d2991d25280bfe3c42df820f
Reviewed-by: Ivan Tkachenko <me@ratijas.tk>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
(cherry picked from commit 86039f61b32095cb2e341402438c96178baa0158)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/Lib.js | 3 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/icUsingJSLib.qml | 12 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 11 |
3 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/Lib.js b/tests/auto/qml/qqmlecmascript/data/Lib.js new file mode 100644 index 0000000000..67d4f7f56d --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/Lib.js @@ -0,0 +1,3 @@ +.pragma library + +function f() { return 42 } diff --git a/tests/auto/qml/qqmlecmascript/data/icUsingJSLib.qml b/tests/auto/qml/qqmlecmascript/data/icUsingJSLib.qml new file mode 100644 index 0000000000..507027e101 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/icUsingJSLib.qml @@ -0,0 +1,12 @@ +import QtQml + +import "Lib.js" as Lib + +QtObject { + component C : QtObject { + property int num: Lib.f() + } + + property var test: C { id: c } + property alias num: c.num +} diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index e3a0ca3444..b108e9a3dc 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -411,6 +411,8 @@ private slots: void frozenQObject(); void constPointer(); + void icUsingJSLib(); + void optionalChainEval(); void optionalChainDelete(); void optionalChainNull(); @@ -9704,6 +9706,15 @@ void tst_qqmlecmascript::constPointer() QVERIFY(root->property("propertyOk").toBool()); } +void tst_qqmlecmascript::icUsingJSLib() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("icUsingJSLib.qml")); + QScopedPointer<QObject> root(component.create()); + QVERIFY2(root, qPrintable(component.errorString())); + QCOMPARE(root->property("num").toInt(), 42); +} + void tst_qqmlecmascript::optionalChainEval() { QQmlEngine qmlengine; |