Skip to content

Commit

Permalink
Support better boolean conversion semantics
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Aaron Kennedy authored and Qt by Nokia committed Jul 25, 2011
1 parent 2c4c109 commit 408ecd8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/declarative/qml/v8/qv8engine.cpp
Expand Up @@ -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) {
Expand Down
@@ -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
}
}
Expand Up @@ -150,6 +150,7 @@ private slots:
void propertyChangeSlots();
void elementAssign();
void objectPassThroughSignals();
void booleanConversion();

void bug1();
void bug2();
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 408ecd8

Please sign in to comment.