From cb6b9ee680f792750d0cb265ea59ff3ff4643562 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 28 Jan 2011 12:00:21 +1000 Subject: Ensure simple objects also get the appropriate property cache Task-number: QTBUG-13849 --- src/declarative/qml/qdeclarativedata_p.h | 5 +---- src/declarative/qml/qdeclarativeobjectscriptclass.cpp | 3 ++- src/declarative/qml/qdeclarativevme.cpp | 12 ++++++------ .../qdeclarativeecmascript/data/metaobjectRevision4.qml | 14 ++++++++++++++ .../qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp | 9 +++++++++ 5 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/metaobjectRevision4.qml diff --git a/src/declarative/qml/qdeclarativedata_p.h b/src/declarative/qml/qdeclarativedata_p.h index f0ff0c0..33458dc 100644 --- a/src/declarative/qml/qdeclarativedata_p.h +++ b/src/declarative/qml/qdeclarativedata_p.h @@ -66,7 +66,6 @@ class QDeclarativePropertyCache; class QDeclarativeContextData; class QDeclarativeNotifier; class QDeclarativeDataExtended; -class QDeclarativeType; // This class is structured in such a way, that simply zero'ing it is the // default state for elemental object allocations. This is crucial in the // workings of the QDeclarativeInstruction::CreateSimpleObject instruction. @@ -78,7 +77,7 @@ public: : ownMemory(true), ownContext(false), indestructible(true), explicitIndestructibleSet(false), context(0), outerContext(0), bindings(0), nextContextObject(0), prevContextObject(0), bindingBitsSize(0), bindingBits(0), lineNumber(0), columnNumber(0), deferredComponent(0), deferredIdx(0), - scriptValue(0), objectDataRefCount(0), propertyCache(0), guards(0), type(0), extendedData(0) { + scriptValue(0), objectDataRefCount(0), propertyCache(0), guards(0), extendedData(0) { init(); } @@ -137,8 +136,6 @@ public: QDeclarativeGuard *guards; - const QDeclarativeType *type; - static QDeclarativeData *get(const QObject *object, bool create = false) { QObjectPrivate *priv = QObjectPrivate::get(const_cast(object)); if (priv->wasDeleted) { diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index 7701a23..ee47d0b 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -166,8 +166,9 @@ QDeclarativeObjectScriptClass::queryProperty(QObject *obj, const Identifier &nam QDeclarativeEnginePrivate *enginePrivate = QDeclarativeEnginePrivate::get(engine); lastData = QDeclarativePropertyCache::property(engine, obj, name, local); if ((hints & ImplicitObject) && lastData && lastData->revision != 0) { + QDeclarativeData *ddata = QDeclarativeData::get(obj); - if (ddata && ddata->propertyCache && !ddata->propertyCache->isAllowedInRevision(lastData)) + if (ddata && ddata->propertyCache && !ddata->propertyCache->isAllowedInRevision(lastData)) return 0; } diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index 657b10d..366c64b 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -194,8 +194,6 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack &stack, QDeclarativeData *ddata = QDeclarativeData::get(o); Q_ASSERT(ddata); - if (types.at(instr.create.type).type) - ddata->type = types.at(instr.create.type).type; if (stack.isEmpty()) { if (ddata->context) { @@ -249,10 +247,12 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack &stack, ::memset(o, 0, instr.createSimple.typeSize + sizeof(QDeclarativeData)); instr.createSimple.create(o); - QDeclarativeData *ddata = - (QDeclarativeData *)(((const char *)o) + instr.createSimple.typeSize); - if (types.at(instr.createSimple.type).type) - ddata->type = types.at(instr.createSimple.type).type; + QDeclarativeData *ddata = (QDeclarativeData *)(((const char *)o) + instr.createSimple.typeSize); + const QDeclarativeCompiledData::TypeReference &ref = types.at(instr.createSimple.type); + if (!ddata->propertyCache && ref.typePropertyCache) { + ddata->propertyCache = ref.typePropertyCache; + ddata->propertyCache->addref(); + } ddata->lineNumber = instr.line; ddata->columnNumber = instr.createSimple.column; diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/metaobjectRevision4.qml b/tests/auto/declarative/qdeclarativeecmascript/data/metaobjectRevision4.qml new file mode 100644 index 0000000..81ea536 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/metaobjectRevision4.qml @@ -0,0 +1,14 @@ +import Qt.test 1.1 +import QtQuick 1.0 + +QtObject { + property variant a + property real test + + a: MyRevisionedClass { + prop2: 11 + + Component.onCompleted: test = prop2 + } +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index e7f9a2c..f66cd0b 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -2983,6 +2983,15 @@ void tst_qdeclarativeecmascript::revision() MyRevisionedClass *object = qobject_cast(component.create()); QVERIFY(object != 0); } + // Test that non-root classes can resolve revisioned methods + { + QDeclarativeComponent component(&engine, TEST_FILE("metaobjectRevision4.qml")); + + QObject *object = component.create(); + QVERIFY(object != 0); + QCOMPARE(object->property("test").toReal(), 11.); + delete object; + } } QTEST_MAIN(tst_qdeclarativeecmascript) -- cgit v0.12