Check engine equality condition inside null ptr check
authorChris Adams <christopher.adams@nokia.com>
Fri, 24 Feb 2012 04:40:11 +0000 (14:40 +1000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 27 Feb 2012 01:39:41 +0000 (02:39 +0100)
Previously, we asserted if the engine associated with the two external
resources from the arguments to the object comparison callback were
not equal, prior to checking that the external resources were non-null.

Task-number: QTBUG-24489
Change-Id: I4b2bd2377fcf38163d1341e43e056b1405ab72ac
Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
src/declarative/qml/v8/qv8engine.cpp
tests/auto/declarative/qdeclarativevaluetypes/data/nonValueTypeComparison.qml [new file with mode: 0644]
tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp

index 04589fe..70e6528 100644 (file)
@@ -75,12 +75,14 @@ static bool ObjectComparisonCallback(v8::Local<v8::Object> lhs, v8::Local<v8::Ob
     if (lhs == rhs)
         return true;
 
+    if (lhs.IsEmpty() || rhs.IsEmpty())
+        return false;
+
     QV8ObjectResource *lhsr = static_cast<QV8ObjectResource*>(lhs->GetExternalResource());
     QV8ObjectResource *rhsr = static_cast<QV8ObjectResource*>(rhs->GetExternalResource());
 
-    Q_ASSERT(lhsr->engine == rhsr->engine);
-
     if (lhsr && rhsr) {
+        Q_ASSERT(lhsr->engine == rhsr->engine);
         QV8ObjectResource::ResourceType lhst = lhsr->resourceType();
         QV8ObjectResource::ResourceType rhst = rhsr->resourceType();
 
diff --git a/tests/auto/declarative/qdeclarativevaluetypes/data/nonValueTypeComparison.qml b/tests/auto/declarative/qdeclarativevaluetypes/data/nonValueTypeComparison.qml
new file mode 100644 (file)
index 0000000..0ffa5eb
--- /dev/null
@@ -0,0 +1,10 @@
+import QtQuick 2.0
+
+Item {
+    property variant somepoint: Qt.point(1,2)
+    property variant randomjsobj: {"some": 1, "thing": 2}
+    property bool test1: somepoint != randomjsobj
+
+    property variant similar: {"x":1, "y":2}
+    property bool test2: somepoint != similar
+}
index 72ec7a5..e701efa 100644 (file)
@@ -93,6 +93,7 @@ private slots:
     void returnValues();
     void varAssignment();
     void bindingsSpliceCorrectly();
+    void nonValueTypeComparison();
 
 private:
     QDeclarativeEngine engine;
@@ -1301,6 +1302,18 @@ void tst_qdeclarativevaluetypes::bindingsSpliceCorrectly()
     }
 }
 
+void tst_qdeclarativevaluetypes::nonValueTypeComparison()
+{
+    QDeclarativeComponent component(&engine, testFileUrl("nonValueTypeComparison.qml"));
+    QObject *object = component.create();
+    QVERIFY(object != 0);
+
+    QCOMPARE(object->property("test1").toBool(), true);
+    QCOMPARE(object->property("test2").toBool(), true);
+
+    delete object;
+}
+
 QTEST_MAIN(tst_qdeclarativevaluetypes)
 
 #include "tst_qdeclarativevaluetypes.moc"