From: Aaron Kennedy Date: Mon, 25 Jul 2011 03:35:03 +0000 (+1000) Subject: Support better boolean conversion semantics X-Git-Tag: qt-v5.0.0-alpha1~2097 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=408ecd82db47aba68b1ab5e4ed48045c24268a7d;p=profile%2Fivi%2Fqtdeclarative.git 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 Reviewed-by: Aaron Kennedy --- diff --git a/src/declarative/qml/v8/qv8engine.cpp b/src/declarative/qml/v8/qv8engine.cpp index a6af68d..b8a1bc4 100644 --- a/src/declarative/qml/v8/qv8engine.cpp +++ b/src/declarative/qml/v8/qv8engine.cpp @@ -174,6 +174,9 @@ QVariant QV8Engine::toVariant(v8::Handle 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 0000000..a7e08ec --- /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 aafae1e..d73da28 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()