From ea74f0c68cddf706c950d3910cf7b363fe24885b Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 17 Apr 2019 12:35:42 +0200 Subject: Don't crash when accessing invalid properties through QObjectWrapper Change-Id: I613bf5dc685bb4235262b429d8f7318ea144fb9d Fixes: QTBUG-75203 Reviewed-by: Erik Verbruggen --- .../data/undefinedPropertiesInObjectWrapper.qml | 20 ++++++++++++++++++++ tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 10 ++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/auto/qml/qqmlecmascript/data/undefinedPropertiesInObjectWrapper.qml (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qqmlecmascript/data/undefinedPropertiesInObjectWrapper.qml b/tests/auto/qml/qqmlecmascript/data/undefinedPropertiesInObjectWrapper.qml new file mode 100644 index 0000000000..7e2f15fc23 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/undefinedPropertiesInObjectWrapper.qml @@ -0,0 +1,20 @@ +import QtQuick 2.12 + +QtObject { + property list entries: [ + QtObject { + readonly property color color: "green" + }, + QtObject { + } + ] + + property Row row: Row { + Repeater { + model: entries + Rectangle { + color: model.color ? model.color : "red" + } + } + } +} diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 0e8844d23f..85cad8f62c 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -367,6 +367,7 @@ private slots: void deleteSparseInIteration(); void saveAccumulatorBeforeToInt32(); void intMinDividedByMinusOne(); + void undefinedPropertiesInObjectWrapper(); private: // static void propertyVarWeakRefCallback(v8::Persistent object, void* parameter); @@ -8958,6 +8959,15 @@ void tst_qqmlecmascript::intMinDividedByMinusOne() QCOMPARE(object->property("doesNotFitInInt").toUInt(), 2147483648u); } +void tst_qqmlecmascript::undefinedPropertiesInObjectWrapper() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFile("undefinedPropertiesInObjectWrapper.qml")); + QVERIFY(component.isReady()); + QScopedPointer object(component.create()); + QVERIFY(!object.isNull()); +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" -- cgit v1.2.3 From c018df5b4075ae962966d4df7653d476dab02840 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 17 Apr 2019 08:38:20 +0200 Subject: QML: Remove static attchedPropertyIds map If the same object is available under two different names it should still have the same attached properties no matter which name you use. This was achieved by having a static map of metaobjects to attached property IDs that would always hold the first attached property ID registered for a given metaobject. This attached property ID was then used as key in the map of attached properties for the actual objects. The obvious downside to that is that we need a global static which gives us thread safety and static initialization (and destruction) problems. It turns out, all the attached properties are created by attached properties functions, registered by the user. Those functions only get the object to be amended as parameter. Therefore, no attached properties function can be registered for multiple attached properties on the same object as it wouldn't know which one to create for a given call. Thus, the whole ID dance is unnecessary as we can as well index the attached property objects by the function that created them. This nicely avoids creating two attached property objects for the same object and function and still makes the global static unnecessary. Fixes: QTBUG-75176 Change-Id: Ie8d53ef0a6f41c9b3d6b9d611cde1603a557901c Reviewed-by: Erik Verbruggen --- tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp index 7f103dc5ed..a7805922a5 100644 --- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp +++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp @@ -550,8 +550,8 @@ void tst_qqmlmetatype::unregisterAttachedProperties() c.setData("import QtQuick 2.2\n Item { }", dummy); const QQmlType attachedType = QQmlMetaType::qmlType("QtQuick/KeyNavigation", 2, 2); - QCOMPARE(attachedType.attachedPropertiesId(QQmlEnginePrivate::get(&e)), - attachedType.index()); + QCOMPARE(attachedType.attachedPropertiesType(QQmlEnginePrivate::get(&e)), + attachedType.metaObject()); QVERIFY(c.create()); } @@ -569,8 +569,8 @@ void tst_qqmlmetatype::unregisterAttachedProperties() "Item { KeyNavigation.up: null }", dummy); const QQmlType attachedType = QQmlMetaType::qmlType("QtQuick/KeyNavigation", 2, 2); - QCOMPARE(attachedType.attachedPropertiesId(QQmlEnginePrivate::get(&e)), - attachedType.index()); + QCOMPARE(attachedType.attachedPropertiesType(QQmlEnginePrivate::get(&e)), + attachedType.metaObject()); QVERIFY(c.create()); } -- cgit v1.2.3