summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/qml/jsruntime/qv4engine.cpp8
-rw-r--r--tests/auto/qml/qqmlcomponent/data/complexObjectArgument.qml10
-rw-r--r--tests/auto/qml/qqmlcomponent/data/dynamic.qml6
-rw-r--r--tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp11
4 files changed, 31 insertions, 4 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 82c85b18e8..2e4fdcc200 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -1709,10 +1709,7 @@ static QVariant objectToVariant(const QV4::Object *o, V4ObjectSet *visitedObject
}
result = list;
- } else if (const FunctionObject *f = o->as<FunctionObject>()) {
- // If it's a FunctionObject, we can only save it as QJSValue.
- result = QVariant::fromValue(QJSValuePrivate::fromReturnedValue(f->asReturnedValue()));
- } else {
+ } else if (o->getPrototypeOf() == o->engine()->objectPrototype()->d()) {
QVariantMap map;
QV4::Scope scope(o->engine());
QV4::ObjectIterator it(scope, o, QV4::ObjectIterator::EnumerableOnly);
@@ -1730,6 +1727,9 @@ static QVariant objectToVariant(const QV4::Object *o, V4ObjectSet *visitedObject
}
result = map;
+ } else {
+ // If it's not a plain object, we can only save it as QJSValue.
+ result = QVariant::fromValue(QJSValuePrivate::fromReturnedValue(o->asReturnedValue()));
}
visitedObjects->remove(o->d());
diff --git a/tests/auto/qml/qqmlcomponent/data/complexObjectArgument.qml b/tests/auto/qml/qqmlcomponent/data/complexObjectArgument.qml
new file mode 100644
index 0000000000..89c9242110
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/complexObjectArgument.qml
@@ -0,0 +1,10 @@
+import QtQml 2.15
+
+QtObject {
+ id: root
+ Component.onCompleted: {
+ let comp = Qt.createComponent("dynamic.qml");
+ let inst = comp.createObject(root, { testObj: new Set(), });
+ objectName = inst.use();
+ }
+}
diff --git a/tests/auto/qml/qqmlcomponent/data/dynamic.qml b/tests/auto/qml/qqmlcomponent/data/dynamic.qml
new file mode 100644
index 0000000000..b9a54d53ff
--- /dev/null
+++ b/tests/auto/qml/qqmlcomponent/data/dynamic.qml
@@ -0,0 +1,6 @@
+import QtQml
+
+QtObject {
+ property var testObj
+ function use() { return testObj.has(1) ? 25 : 26; }
+}
diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
index d6a53b9950..0af3db58fa 100644
--- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
+++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
@@ -146,6 +146,7 @@ private slots:
void loadFromModuleRequired();
void loadFromQrc();
void removeBinding();
+ void complexObjectArgument();
private:
QQmlEngine engine;
@@ -1450,6 +1451,16 @@ void tst_qqmlcomponent::removeBinding()
QCOMPARE(o->property("result"), QStringLiteral("42"));
}
+void tst_qqmlcomponent::complexObjectArgument()
+{
+ QQmlEngine e;
+ QQmlComponent c(&e, testFileUrl("complexObjectArgument.qml"));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+ QCOMPARE(o->objectName(), QStringLiteral("26"));
+}
+
QTEST_MAIN(tst_qqmlcomponent)
#include "tst_qqmlcomponent.moc"