From d2921ffc52fed380326f8abb86d6d659cc47f9d1 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Fri, 24 Feb 2012 14:40:11 +1000 Subject: [PATCH] Check engine equality condition inside null ptr check 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 Reviewed-by: Michael Brasser --- src/declarative/qml/v8/qv8engine.cpp | 6 ++++-- .../qdeclarativevaluetypes/data/nonValueTypeComparison.qml | 10 ++++++++++ .../qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp | 13 +++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativevaluetypes/data/nonValueTypeComparison.qml diff --git a/src/declarative/qml/v8/qv8engine.cpp b/src/declarative/qml/v8/qv8engine.cpp index 04589fe..70e6528 100644 --- a/src/declarative/qml/v8/qv8engine.cpp +++ b/src/declarative/qml/v8/qv8engine.cpp @@ -75,12 +75,14 @@ static bool ObjectComparisonCallback(v8::Local lhs, v8::Local(lhs->GetExternalResource()); QV8ObjectResource *rhsr = static_cast(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 index 0000000..0ffa5eb --- /dev/null +++ b/tests/auto/declarative/qdeclarativevaluetypes/data/nonValueTypeComparison.qml @@ -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 +} diff --git a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp index 72ec7a5..e701efa 100644 --- a/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp +++ b/tests/auto/declarative/qdeclarativevaluetypes/tst_qdeclarativevaluetypes.cpp @@ -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" -- 2.7.4