Fix crash in lazy meta object generation.
authorAaron Kennedy <aaron.kennedy@nokia.com>
Fri, 1 Jun 2012 14:07:54 +0000 (15:07 +0100)
committerQt by Nokia <qt-info@nokia.com>
Sun, 3 Jun 2012 23:34:31 +0000 (01:34 +0200)
Inside the property cache, override data can only handle overrides
pointing to either a method or a property, but not to a signal
handler.  This is a bug in itself, but has never come up before due
to no one following override data on methods.  When this
was changed by d2e557c2c2d7fcf3bf7c1676df3902e115986dc2, this bug
was exposed.

This change doesn't actually fix the underlying problem, but it does
restore exactly the same behavior we had previously.  The complete
fix will come in a later change.

Change-Id: I6a890e6ca1e40735da8158b21dfe38dc88091081
Reviewed-by: Martin Jones <martin.jones@nokia.com>

src/qml/qml/qqmlpropertycache.cpp
tests/auto/qml/qqmlecmascript/data/overrideDataAssert.qml [new file with mode: 0644]
tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp

index 8167280..b073d22 100644 (file)
@@ -1201,7 +1201,7 @@ void QQmlPropertyCache::toMetaObjectBuilder(QMetaObjectBuilder &builder)
 
             QQmlPropertyData *olddata = data;
             data = This->overrideData(data);
-            if (data) Insert::in(This, properties, methods, iter, data);
+            if (data && !data->isFunction()) Insert::in(This, properties, methods, iter, data);
         } else {
             if (data->coreIndex < This->propertyIndexCacheStart)
                 return;
diff --git a/tests/auto/qml/qqmlecmascript/data/overrideDataAssert.qml b/tests/auto/qml/qqmlecmascript/data/overrideDataAssert.qml
new file mode 100644 (file)
index 0000000..e419bd3
--- /dev/null
@@ -0,0 +1,6 @@
+import QtQuick 2.0
+
+QtObject {
+    signal routeStatusChanged
+    function onRouteStatusChanged() { }
+}
index 4dc041c..45005e6 100644 (file)
@@ -268,6 +268,7 @@ private slots:
     void qqmldataDestroyed();
     void secondAlias();
     void varAlias();
+    void overrideDataAssert();
 
 private:
     static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
@@ -6961,6 +6962,16 @@ void tst_qqmlecmascript::varAlias()
     delete object;
 }
 
+// Used to trigger an assert in the lazy meta object creation stage
+void tst_qqmlecmascript::overrideDataAssert()
+{
+    QQmlComponent c(&engine, testFileUrl("overrideDataAssert.qml"));
+    QObject *object = c.create();
+    QVERIFY(object != 0);
+    object->metaObject();
+    delete object;
+}
+
 QTEST_MAIN(tst_qqmlecmascript)
 
 #include "tst_qqmlecmascript.moc"