diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2023-07-07 10:30:39 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-07-07 23:58:55 +0200 |
| commit | 8b1ee7662364d257705e6529af88a0fea93f2bdc (patch) | |
| tree | 0fb224487594a1074e9852cfc15287327256311d | |
| parent | 1fa3c386df152bc54bf5feef41c23080c3d24c22 (diff) | |
QtQml: Fix validation when calling methods with different 'this'
We were checking the wrong method offsets and we didn't check for
destroy() and toString().
Amends commit 3fd3a2a9d06505d549cc4a7c18819a17c6622dfd.
Pick-to: 6.5 6.6
Change-Id: I8ebeb927a7827cc1fd3394fb3ab589c35d31ab70
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
| -rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 6 | ||||
| -rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 11 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 14a4c67f96..b273cd9ef0 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -2455,6 +2455,10 @@ Heap::QObjectMethod::ThisObjectMode Heap::QObjectMethod::checkThisObject( return Included; } + // destroy() and toString() can be called on all QObjects, but not on gadgets. + if (index < 0) + return thisMeta->inherits(&QObject::staticMetaObject) ? Explicit : Invalid; + // Find the base type the method belongs to. int methodOffset = included->methodOffset(); while (true) { @@ -2464,9 +2468,9 @@ Heap::QObjectMethod::ThisObjectMode Heap::QObjectMethod::checkThisObject( if (methodOffset <= index) return thisMeta->inherits(included) ? Explicit : Invalid; - methodOffset -= QMetaObjectPrivate::get(included)->methodCount; included = included->superClass(); Q_ASSERT(included); + methodOffset -= QMetaObjectPrivate::get(included)->methodCount; }; Q_UNREACHABLE_RETURN(Invalid); diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 16d20e154e..a3d2be9105 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -7865,6 +7865,15 @@ void tst_qqmllanguage::objectAndGadgetMethodCallsAcceptThisObject() QQmlComponent c(&engine, testFileUrl("objectAndGadgetMethodCallsAcceptThisObject.qml")); QVERIFY2(c.isReady(), qPrintable(c.errorString())); + // Explicitly retrieve the metaobject for the Qt singleton so that the proxy data is created. + // This way the inheritance analysis we do when figuring out what toString() means is somewhat + // more interesting. Also, we get a deterministic result for Qt.toString(). + const QQmlType qtType = QQmlMetaType::qmlType(QStringLiteral("Qt"), QString(), QTypeRevision()); + QVERIFY(qtType.isValid()); + const QMetaObject *qtMeta = qtType.metaObject(); + QVERIFY(qtMeta); + QCOMPARE(QString::fromUtf8(qtMeta->className()), QLatin1String("Qt")); + QTest::ignoreMessage( QtWarningMsg, QRegularExpression( "objectAndGadgetMethodCallsAcceptThisObject.qml:16: Error: " @@ -7895,7 +7904,7 @@ void tst_qqmllanguage::objectAndGadgetMethodCallsAcceptThisObject() QCOMPARE(o->property("goodString2"), QStringLiteral("27")); QCOMPARE(o->property("goodString3"), QStringLiteral("28")); - QVERIFY(o->property("goodString4").value<QString>().startsWith("QtObject"_L1)); + QVERIFY(o->property("goodString4").value<QString>().startsWith("Qt("_L1)); QCOMPARE(o->property("badString2"), QString()); QCOMPARE(o->property("badInt"), 0); |
