diff options
author | Chris Adams <christopher.adams@nokia.com> | 2012-02-24 14:40:11 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-27 02:39:41 +0100 |
commit | d2921ffc52fed380326f8abb86d6d659cc47f9d1 (patch) | |
tree | 88502570f2e5b3fee145dc89608f21ab018c3e90 | |
parent | de02b0f6ba4c422ff617308617b32804b15d1f7e (diff) |
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 <charles.yin@nokia.com>
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
3 files changed, 27 insertions, 2 deletions
diff --git a/src/declarative/qml/v8/qv8engine.cpp b/src/declarative/qml/v8/qv8engine.cpp index 04589fe244..70e6528f0a 100644 --- a/src/declarative/qml/v8/qv8engine.cpp +++ b/src/declarative/qml/v8/qv8engine.cpp @@ -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 index 0000000000..0ffa5eb666 --- /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 72ec7a5abf..e701efa2a4 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" |