aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2011-07-25 13:35:03 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-25 06:08:56 +0200
commit408ecd82db47aba68b1ab5e4ed48045c24268a7d (patch)
tree589ed69fe2f3c5b0377035ab532ca4f80b554015
parent2c4c10942314ab76fa8f06f690e44adc6b7f2199 (diff)
Support better boolean conversion semantics
Task-number: QTBUG-20242 Change-Id: Ie678f6189a8060de600b5394fbaaaef49be274c6 Reviewed-on: http://codereview.qt.nokia.com/2061 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
-rw-r--r--src/declarative/qml/v8/qv8engine.cpp3
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/booleanConversion.qml28
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp22
3 files changed, 53 insertions, 0 deletions
diff --git a/src/declarative/qml/v8/qv8engine.cpp b/src/declarative/qml/v8/qv8engine.cpp
index a6af68d392..b8a1bc41e2 100644
--- a/src/declarative/qml/v8/qv8engine.cpp
+++ b/src/declarative/qml/v8/qv8engine.cpp
@@ -174,6 +174,9 @@ QVariant QV8Engine::toVariant(v8::Handle<v8::Value> value, int typeHint)
if (value.IsEmpty())
return QVariant();
+ if (typeHint == QVariant::Bool)
+ return QVariant(value->BooleanValue());
+
if (value->IsObject()) {
QV8ObjectResource *r = (QV8ObjectResource *)value->ToObject()->GetExternalResource();
if (r) {
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/booleanConversion.qml b/tests/auto/declarative/qdeclarativeecmascript/data/booleanConversion.qml
new file mode 100644
index 0000000000..a7e08ecc56
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/booleanConversion.qml
@@ -0,0 +1,28 @@
+import QtQuick 1.0
+
+QtObject {
+ id: root
+
+ property bool test_true1: false
+ property bool test_true2: false
+ property bool test_true3: false
+ property bool test_true4: false
+ property bool test_true5: false
+
+ property bool test_false1: true
+ property bool test_false2: true
+ property bool test_false3: true
+
+
+ Component.onCompleted: {
+ test_true1 = 11
+ test_true2 = "Hello"
+ test_true3 = root
+ test_true4 = { a: 10, b: 11 }
+ test_true5 = true
+
+ test_false1 = 0
+ test_false2 = null
+ test_false3 = false
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index aafae1ea54..d73da28212 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -150,6 +150,7 @@ private slots:
void propertyChangeSlots();
void elementAssign();
void objectPassThroughSignals();
+ void booleanConversion();
void bug1();
void bug2();
@@ -2938,6 +2939,27 @@ void tst_qdeclarativeecmascript::objectPassThroughSignals()
delete object;
}
+// QTBUG-20242
+void tst_qdeclarativeecmascript::booleanConversion()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("booleanConversion.qml"));
+
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("test_true1").toBool(), true);
+ QCOMPARE(object->property("test_true2").toBool(), true);
+ QCOMPARE(object->property("test_true3").toBool(), true);
+ QCOMPARE(object->property("test_true4").toBool(), true);
+ QCOMPARE(object->property("test_true5").toBool(), true);
+
+ QCOMPARE(object->property("test_false1").toBool(), false);
+ QCOMPARE(object->property("test_false2").toBool(), false);
+ QCOMPARE(object->property("test_false3").toBool(), false);
+
+ delete object;
+}
+
// Test that assigning a null object works
// Regressed with: df1788b4dbbb2826ae63f26bdf166342595343f4
void tst_qdeclarativeecmascript::nullObjectBinding()