diff options
-rw-r--r-- | src/qml/qml/qqmlcomponent.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qml/qqmlcomponent/data/jsmodule/Dynamic.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmlcomponent/data/jsmodule/module.mjs | 6 | ||||
-rw-r--r-- | tests/auto/qml/qqmlcomponent/data/jsmodule/test.qml | 10 | ||||
-rw-r--r-- | tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp | 10 |
5 files changed, 33 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index 279befb351..f35c3011d3 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -1369,7 +1369,8 @@ void QQmlComponentPrivate::setInitialProperties(QV4::ExecutionEngine *engine, QV if (engine->hasException) return; - QV4::ScopedStackFrame frame(scope, qmlContext->d()); + // js modules (mjs) have no qmlContext + QV4::ScopedStackFrame frame(scope, qmlContext ? qmlContext->d() : engine->scriptContext()->d()); while (1) { name = it.nextPropertyNameAsString(val); diff --git a/tests/auto/qml/qqmlcomponent/data/jsmodule/Dynamic.qml b/tests/auto/qml/qqmlcomponent/data/jsmodule/Dynamic.qml new file mode 100644 index 0000000000..0d894eb3fe --- /dev/null +++ b/tests/auto/qml/qqmlcomponent/data/jsmodule/Dynamic.qml @@ -0,0 +1,5 @@ +import QtQml + +QtObject { + property int value +} diff --git a/tests/auto/qml/qqmlcomponent/data/jsmodule/module.mjs b/tests/auto/qml/qqmlcomponent/data/jsmodule/module.mjs new file mode 100644 index 0000000000..3dd3507d45 --- /dev/null +++ b/tests/auto/qml/qqmlcomponent/data/jsmodule/module.mjs @@ -0,0 +1,6 @@ +export function withProp(root) { + const component = Qt.createComponent("data/jsmodule/Dynamic.qml"); + const el = component.createObject(root, { value: 42 }); + return el.value; +} + diff --git a/tests/auto/qml/qqmlcomponent/data/jsmodule/test.qml b/tests/auto/qml/qqmlcomponent/data/jsmodule/test.qml new file mode 100644 index 0000000000..123c857180 --- /dev/null +++ b/tests/auto/qml/qqmlcomponent/data/jsmodule/test.qml @@ -0,0 +1,10 @@ +import "./module.mjs" as MJ +import QtQml 2.15 + +QtObject { + id: root + property bool ok: false + Component.onCompleted: { + root.ok = MJ.withProp(root) == 42 + } +} diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index 36c13bb705..c4a1a6aea4 100644 --- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp +++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp @@ -125,6 +125,7 @@ private slots: void testRequiredProperties(); void testRequiredPropertiesFromQml(); void testSetInitialProperties(); + void createInsideJSModule(); private: QQmlEngine engine; @@ -832,6 +833,15 @@ void tst_qqmlcomponent::testSetInitialProperties() } } +void tst_qqmlcomponent::createInsideJSModule() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("jsmodule/test.qml")); + QScopedPointer<QObject> root(component.create()); + QVERIFY2(root, qPrintable(component.errorString())); + QVERIFY(root->property("ok").toBool()); +} + QTEST_MAIN(tst_qqmlcomponent) #include "tst_qqmlcomponent.moc" |