From b9b305f6c7bc960101bfd883ca6e3df889483481 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 30 Mar 2010 16:37:28 +1000 Subject: Correctly construct boolean JSValue's Task-number: QTBUG-9205 --- src/script/bridge/qscriptdeclarativeclass.cpp | 12 +++++++++--- .../qdeclarativeecmascript/data/strictlyEquals.qml | 17 +++++++++++++++++ .../tst_qdeclarativeecmascript.cpp | 21 +++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/strictlyEquals.qml diff --git a/src/script/bridge/qscriptdeclarativeclass.cpp b/src/script/bridge/qscriptdeclarativeclass.cpp index acfb2a4..0f450ca 100644 --- a/src/script/bridge/qscriptdeclarativeclass.cpp +++ b/src/script/bridge/qscriptdeclarativeclass.cpp @@ -70,9 +70,12 @@ QScriptDeclarativeClass::Value::Value(QScriptContext *ctxt, uint value) new (this) JSC::JSValue(QScriptEnginePrivate::frameForContext(ctxt), value); } -QScriptDeclarativeClass::Value::Value(QScriptContext *ctxt, bool value) +QScriptDeclarativeClass::Value::Value(QScriptContext *, bool value) { - new (this) JSC::JSValue(QScriptEnginePrivate::frameForContext(ctxt), value); + if (value) + new (this) JSC::JSValue(JSC::JSValue::JSTrue); + else + new (this) JSC::JSValue(JSC::JSValue::JSFalse); } QScriptDeclarativeClass::Value::Value(QScriptContext *ctxt, double value) @@ -107,7 +110,10 @@ QScriptDeclarativeClass::Value::Value(QScriptEngine *eng, uint value) QScriptDeclarativeClass::Value::Value(QScriptEngine *eng, bool value) { - new (this) JSC::JSValue(QScriptEnginePrivate::get(eng)->currentFrame, value); + if (value) + new (this) JSC::JSValue(JSC::JSValue::JSTrue); + else + new (this) JSC::JSValue(JSC::JSValue::JSFalse); } QScriptDeclarativeClass::Value::Value(QScriptEngine *eng, double value) diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/strictlyEquals.qml b/tests/auto/declarative/qdeclarativeecmascript/data/strictlyEquals.qml new file mode 100644 index 0000000..b9e455d --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/strictlyEquals.qml @@ -0,0 +1,17 @@ +import Qt 4.6 + +QtObject { + property bool test1: (a === true) + property bool test2: !(a === false) + property bool test3: (b === 11.2) + property bool test4: !(b === 9) + property bool test5: (c === 9) + property bool test6: !(c === 13) + property bool test7: (d === "Hello world") + property bool test8: !(d === "Hi") + + property bool a: true + property real b: 11.2 + property int c: 9 + property string d: "Hello world" +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index 2791722c..b218d30 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -128,6 +128,7 @@ private slots: void scriptDisconnect(); void ownership(); void qlistqobjectMethods(); + void strictlyEquals(); void bug1(); void dynamicCreationCrash(); @@ -2005,6 +2006,26 @@ void tst_qdeclarativeecmascript::qlistqobjectMethods() delete object; } +// QTBUG-9205 +void tst_qdeclarativeecmascript::strictlyEquals() +{ + QDeclarativeComponent component(&engine, TEST_FILE("strictlyEquals.qml")); + + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("test1").toBool(), true); + QCOMPARE(object->property("test2").toBool(), true); + QCOMPARE(object->property("test3").toBool(), true); + QCOMPARE(object->property("test4").toBool(), true); + QCOMPARE(object->property("test5").toBool(), true); + QCOMPARE(object->property("test6").toBool(), true); + QCOMPARE(object->property("test7").toBool(), true); + QCOMPARE(object->property("test8").toBool(), true); + + delete object; +} + QTEST_MAIN(tst_qdeclarativeecmascript) #include "tst_qdeclarativeecmascript.moc" -- cgit v0.12