From d265b449325ef60624640f80f9438ac63547c1a8 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 8 Oct 2009 14:26:18 +1000 Subject: Fix crash --- src/declarative/qml/qmlobjectscriptclass.cpp | 2 +- .../qmlecmascript/data/extendedObjectPropertyLookup.qml | 8 ++++++++ .../auto/declarative/qmlecmascript/tst_qmlecmascript.cpp | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qmlecmascript/data/extendedObjectPropertyLookup.qml diff --git a/src/declarative/qml/qmlobjectscriptclass.cpp b/src/declarative/qml/qmlobjectscriptclass.cpp index 84470fc..d3a2a22 100644 --- a/src/declarative/qml/qmlobjectscriptclass.cpp +++ b/src/declarative/qml/qmlobjectscriptclass.cpp @@ -132,7 +132,7 @@ QmlObjectScriptClass::queryProperty(QObject *obj, const Identifier &name, cache = ddata->propertyCache; if (!cache) { cache = enginePrivate->cache(obj); - if (ddata) { cache->addref(); ddata->propertyCache = cache; } + if (cache && ddata) { cache->addref(); ddata->propertyCache = cache; } } if (cache) { diff --git a/tests/auto/declarative/qmlecmascript/data/extendedObjectPropertyLookup.qml b/tests/auto/declarative/qmlecmascript/data/extendedObjectPropertyLookup.qml new file mode 100644 index 0000000..8ff3aeb --- /dev/null +++ b/tests/auto/declarative/qmlecmascript/data/extendedObjectPropertyLookup.qml @@ -0,0 +1,8 @@ +import Qt.test 1.0 +import Qt 4.6 + +Object { + property MyExtendedObject a; + a: MyExtendedObject { id: Root } + property int b: Math.max(Root.extendedProperty, 0) +} diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp index 6bc88c0..dde3bb7 100644 --- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp +++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp @@ -60,6 +60,7 @@ private slots: void dynamicDestruction(); void objectToString(); void selfDeletingBinding(); + void extendedObjectPropertyLookup(); private: QmlEngine engine; @@ -709,6 +710,20 @@ void tst_qmlecmascript::selfDeletingBinding() } } +/* +Test that extended object properties can be accessed. + +This test a regression where this used to crash. The issue was specificially +for extended objects that did not include a synthesized meta object (so non-root +and no synthesiszed properties). +*/ +void tst_qmlecmascript::extendedObjectPropertyLookup() +{ + QmlComponent component(&engine, TEST_FILE("extendedObjectPropertyLookup.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); +} + QTEST_MAIN(tst_qmlecmascript) #include "tst_qmlecmascript.moc" -- cgit v0.12