aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-02-16 10:47:04 +0100
committerUlf Hermann <ulf.hermann@qt.io>2022-02-21 12:53:38 +0100
commit82d9d8ec445c20056087374812f12d7f6ee27670 (patch)
tree3046475432d2f6733ac77240004697d658e2cce8 /tests
parent345cb3b6f38bead32cff74dfbe68fa4bfe13b631 (diff)
QmlCompiler: Perform QVariant conversion in JavaScript semantics
In JavaScript we have a number of extra conversions not covered by qvariant_cast. Therefore, add a method to perform a QVariant conversion in JavaScript semantics to QJSEngine, and use that in the compiler. Fixes: QTBUG-100883 Change-Id: I8b0bfa0974bc6b339d2601fb373859bc710788c8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Jarkko Koivikko <jarkko.koivikko@code-q.fi> (cherry picked from commit d0f4e0c037cf61eb5bb559755ee7c9ce6cf6b7dc)
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt1
-rw-r--r--tests/auto/qml/qmlcppcodegen/data/objectInVar.qml15
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp19
3 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
index 34c6ea3542..02e0f06deb 100644
--- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
+++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt
@@ -92,6 +92,7 @@ set(qml_files
noscope.qml
notEqualsInt.qml
nullAccess.qml
+ objectInVar.qml
outOfBounds.qml
overriddenMember.qml
ownProperty.qml
diff --git a/tests/auto/qml/qmlcppcodegen/data/objectInVar.qml b/tests/auto/qml/qmlcppcodegen/data/objectInVar.qml
new file mode 100644
index 0000000000..9177ff2089
--- /dev/null
+++ b/tests/auto/qml/qmlcppcodegen/data/objectInVar.qml
@@ -0,0 +1,15 @@
+pragma Strict
+import QtQml
+
+QtObject {
+ id: self
+
+ property var thing: self
+
+ function doThing() : bool {
+ if (self.thing)
+ return true;
+ else
+ return false;
+ }
+}
diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
index 48e0bb68c9..46e0b4fb90 100644
--- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
+++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
@@ -120,6 +120,7 @@ private slots:
void infinities();
void blockComments();
void functionLookup();
+ void objectInVar();
};
void tst_QmlCppCodegen::simpleBinding()
@@ -1805,6 +1806,24 @@ void tst_QmlCppCodegen::functionLookup()
QCOMPARE(result.toString(), QStringLiteral("a99"));
}
+void tst_QmlCppCodegen::objectInVar()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/objectInVar.qml"_qs));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(o);
+ QCOMPARE(qvariant_cast<QObject*>(o->property("thing")), o.data());
+
+ bool result = false;
+ QVERIFY(QMetaObject::invokeMethod(o.data(), "doThing", Q_RETURN_ARG(bool, result)));
+ QVERIFY(result);
+
+ o->setProperty("thing", QVariant::fromValue<std::nullptr_t>(nullptr));
+ QVERIFY(QMetaObject::invokeMethod(o.data(), "doThing", Q_RETURN_ARG(bool, result)));
+ QVERIFY(!result);
+}
+
void tst_QmlCppCodegen::runInterpreted()
{
if (qEnvironmentVariableIsSet("QV4_FORCE_INTERPRETER"))