From: Aaron Kennedy Date: Wed, 7 Dec 2011 14:20:01 +0000 (+0000) Subject: Fix QObject V8 wrapping for extended types X-Git-Tag: upstream/5.2.1~3116 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1c3a4e6f824289cd82aa1c4b0039b2e80c122d96;p=platform%2Fupstream%2Fqtdeclarative.git Fix QObject V8 wrapping for extended types The meta object for extended types must be marked as dynamic, to prevent their properties from being marked as IsDirect. Task-number: QTBUG-22997 Change-Id: I825f94f072cb46981706221a1044c9e2feeedcc2 Reviewed-by: Simon Hausmann Reviewed-by: Aaron Kennedy --- diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp index c175d72..ac89eb9 100644 --- a/src/declarative/qml/qdeclarativemetatype.cpp +++ b/src/declarative/qml/qdeclarativemetatype.cpp @@ -429,8 +429,10 @@ void QDeclarativeTypePrivate::init() const // XXX - very inefficient const QMetaObject *mo = m_baseMetaObject; if (m_extFunc) { - QMetaObject *mmo = new QMetaObject; - *mmo = *m_extMetaObject; + QMetaObjectBuilder builder; + clone(builder, m_extMetaObject, m_extMetaObject, m_extMetaObject); + builder.setFlags(QMetaObjectBuilder::DynamicMetaObject); + QMetaObject *mmo = builder.toMetaObject(); mmo->d.superdata = mo; QDeclarativeProxyMetaObject::ProxyData data = { mmo, m_extFunc, 0, 0 }; m_metaObjects << data; @@ -443,6 +445,7 @@ void QDeclarativeTypePrivate::init() const if (t->d->m_extFunc) { QMetaObjectBuilder builder; clone(builder, t->d->m_extMetaObject, t->d->m_baseMetaObject, m_baseMetaObject); + builder.setFlags(QMetaObjectBuilder::DynamicMetaObject); QMetaObject *mmo = builder.toMetaObject(); mmo->d.superdata = m_baseMetaObject; if (!m_metaObjects.isEmpty()) diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/extendedObjectPropertyLookup2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/extendedObjectPropertyLookup2.qml new file mode 100644 index 0000000..e4af335 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/extendedObjectPropertyLookup2.qml @@ -0,0 +1,14 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +QtObject { + id: root + property MyExtendedObject a; + a: MyExtendedObject { + id: obj + extendedProperty: 42; + } + function getValue() { + return obj.extendedProperty; + } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 5e62ec6..31d4feb 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -114,6 +114,7 @@ private slots: void objectHasOwnProperty(); void selfDeletingBinding(); void extendedObjectPropertyLookup(); + void extendedObjectPropertyLookup2(); void scriptErrors(); void functionErrors(); void propertyAssignmentErrors(); @@ -1361,6 +1362,21 @@ void tst_qdeclarativeecmascript::extendedObjectPropertyLookup() } /* +Test that extended object properties can be accessed correctly. +*/ +void tst_qdeclarativeecmascript::extendedObjectPropertyLookup2() +{ + QDeclarativeComponent component(&engine, TEST_FILE("extendedObjectPropertyLookup2.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + + QVariant returnValue; + QVERIFY(QMetaObject::invokeMethod(object, "getValue", Q_RETURN_ARG(QVariant, returnValue))); + QCOMPARE(returnValue.toInt(), 42); + + delete object; +} +/* Test file/lineNumbers for binding/Script errors. */ void tst_qdeclarativeecmascript::scriptErrors()