Remove obsolete toBoolean() and isBoolean() QJSValue getters
authorSimon Hausmann <simon.hausmann@nokia.com>
Mon, 9 Jan 2012 11:08:18 +0000 (12:08 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 11 Jan 2012 14:52:35 +0000 (15:52 +0100)
We should use "toBool" and "isBool" for consistency with QVariant.

Change-Id: I266f2a36a034a5b323e614777ceacbc0d2ffec16
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
src/declarative/qml/v8/qjsvalue.cpp
src/declarative/qml/v8/qjsvalue.h
tests/auto/declarative/qjsengine/tst_qjsengine.cpp
tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp

index 0924378..7df1d04 100644 (file)
@@ -369,20 +369,6 @@ bool QJSValue::isBool() const
 }
 
 /*!
-  \obsolete
-
-  Use isBool() instead.
-  Returns true if this QJSValue is of the primitive type Boolean;
-  otherwise returns false.
-*/
-bool QJSValue::isBoolean() const
-{
-    Q_D(const QJSValue);
-    QScriptIsolate api(d->engine());
-    return d->isBool();
-}
-
-/*!
   Returns true if this QJSValue is of the primitive type Number;
   otherwise returns false.
 
@@ -558,18 +544,6 @@ bool QJSValue::toBool() const
 }
 
 /*!
-  \obsolete
-
-  Use toBool() instead.
-*/
-bool QJSValue::toBoolean() const
-{
-    Q_D(const QJSValue);
-    QScriptIsolate api(d->engine());
-    return d->toBool();
-}
-
-/*!
   Returns the integer value of this QJSValue, using the conversion
   rules described in \l{ECMA-262} section 9.4, "ToInteger".
 
index a5e44a6..c75bd3f 100644 (file)
@@ -92,7 +92,6 @@ public:
     QJSEngine *engine() const;
     bool isValid() const;
     bool isBool() const;
-    bool isBoolean() const;
     bool isNumber() const;
     bool isFunction() const;
     bool isNull() const;
@@ -109,7 +108,6 @@ public:
     QString toString() const;
     double toNumber() const;
     bool toBool() const;
-    bool toBoolean() const;
     double toInteger() const;
     qint32 toInt32() const;
     quint32 toUInt32() const;
index 231b348..281d1b8 100644 (file)
@@ -751,8 +751,8 @@ void tst_QJSEngine::newVariant_valueOfToString()
     {
         QJSValue object = eng.newVariant(QVariant(false));
         QJSValue value = object.property("valueOf").call(object);
-        QVERIFY(value.isBoolean());
-        QCOMPARE(value.toBoolean(), false);
+        QVERIFY(value.isBool());
+        QCOMPARE(value.toBool(), false);
         QCOMPARE(object.toString(), QString::fromLatin1("false"));
         QCOMPARE(object.toVariant().toString(), object.toString());
     }
@@ -929,8 +929,8 @@ void tst_QJSEngine::jsParseDate()
     // Date.parse() should be able to parse the output of Date().toString()
     {
         QJSValue ret = eng.evaluate("var x = new Date(); var s = x.toString(); s == new Date(Date.parse(s)).toString()");
-        QVERIFY(ret.isBoolean());
-        QCOMPARE(ret.toBoolean(), true);
+        QVERIFY(ret.isBool());
+        QCOMPARE(ret.toBool(), true);
     }
 }
 
@@ -1264,8 +1264,8 @@ void tst_QJSEngine::newQMetaObject()
     {
         QScriptValue ret = qclass3.call();
         QVERIFY(ret.isObject());
-        QVERIFY(ret.property("isCalledAsConstructor").isBoolean());
-        QVERIFY(!ret.property("isCalledAsConstructor").toBoolean());
+        QVERIFY(ret.property("isCalledAsConstructor").isBool());
+        QVERIFY(!ret.property("isCalledAsConstructor").toBool());
         QVERIFY(ret.instanceOf(qclass3));
         QVERIFY(instanceofJS(ret, qclass3).strictlyEquals(true));
         QVERIFY(!ret.instanceOf(qclass));
@@ -1274,8 +1274,8 @@ void tst_QJSEngine::newQMetaObject()
     {
         QScriptValue ret = qclass3.construct();
         QVERIFY(ret.isObject());
-        QVERIFY(ret.property("isCalledAsConstructor").isBoolean());
-        QVERIFY(ret.property("isCalledAsConstructor").toBoolean());
+        QVERIFY(ret.property("isCalledAsConstructor").isBool());
+        QVERIFY(ret.property("isCalledAsConstructor").toBool());
         QVERIFY(ret.instanceOf(qclass3));
         QVERIFY(instanceofJS(ret, qclass3).strictlyEquals(true));
         QVERIFY(!ret.instanceOf(qclass2));
@@ -2620,8 +2620,8 @@ void tst_QJSEngine::valueConversion_QVariant()
     {
         QJSValue val = eng.toScriptValue(QVariant(true));
         QVERIFY(!val.isVariant());
-        QVERIFY(val.isBoolean());
-        QCOMPARE(val.toBoolean(), true);
+        QVERIFY(val.isBool());
+        QCOMPARE(val.toBool(), true);
     }
     {
         QJSValue val = eng.toScriptValue(QVariant(int(123)));
@@ -3906,14 +3906,14 @@ void tst_QJSEngine::isEvaluating_fromNative()
     QScriptValue fun = eng.newFunction(myFunctionReturningIsEvaluating);
     eng.globalObject().setProperty("myFunctionReturningIsEvaluating", fun);
     QScriptValue ret = eng.evaluate("myFunctionReturningIsEvaluating()");
-    QVERIFY(ret.isBoolean());
-    QVERIFY(ret.toBoolean());
+    QVERIFY(ret.isBool());
+    QVERIFY(ret.toBool());
     ret = fun.call();
-    QVERIFY(ret.isBoolean());
-    QVERIFY(ret.toBoolean());
+    QVERIFY(ret.isBool());
+    QVERIFY(ret.toBool());
     ret = myFunctionReturningIsEvaluating(eng.currentContext(), &eng);
-    QVERIFY(ret.isBoolean());
-    QVERIFY(!ret.toBoolean());
+    QVERIFY(ret.isBool());
+    QVERIFY(!ret.toBool());
 }
 
 void tst_QJSEngine::isEvaluating_fromEvent()
@@ -4023,7 +4023,7 @@ void tst_QJSEngine::argumentsProperty_globalContext()
         QVERIFY(ret.isNumber());
         QCOMPARE(ret.toInt32(), 10);
     }
-    QVERIFY(eng.evaluate("delete arguments").toBoolean());
+    QVERIFY(eng.evaluate("delete arguments").toBool());
     QVERIFY(!eng.globalObject().property("arguments").isValid());
 }
 
@@ -4413,17 +4413,17 @@ void tst_QJSEngine::stringObjects()
         QCOMPARE(ret4.toInt32(), 456);
 
         QJSValue ret5 = eng.evaluate("delete s[0]");
-        QVERIFY(ret5.isBoolean());
+        QVERIFY(ret5.isBool());
         QEXPECT_FAIL("", "FIXME: This is V8 bug, please report it! ECMA script standard 15.5.5.2", Abort);
-        QVERIFY(!ret5.toBoolean());
+        QVERIFY(!ret5.toBool());
 
         QJSValue ret6 = eng.evaluate("delete s[-1]");
-        QVERIFY(ret6.isBoolean());
-        QVERIFY(ret6.toBoolean());
+        QVERIFY(ret6.isBool());
+        QVERIFY(ret6.toBool());
 
         QJSValue ret7 = eng.evaluate("delete s[s.length]");
-        QVERIFY(ret7.isBoolean());
-        QVERIFY(ret7.toBoolean());
+        QVERIFY(ret7.isBool());
+        QVERIFY(ret7.toBool());
     }
 }
 
@@ -4522,14 +4522,14 @@ void tst_QJSEngine::getterSetterThisObject_plain()
         eng.evaluate("o = {}");
         // read
         eng.evaluate("o.__defineGetter__('x', function() { return this; })");
-        QVERIFY(eng.evaluate("o.x === o").toBoolean());
+        QVERIFY(eng.evaluate("o.x === o").toBool());
         QVERIFY(eng.evaluate("with (o) x").equals(eng.evaluate("o")));
-        QVERIFY(eng.evaluate("(function() { with (o) return x; })() === o").toBoolean());
+        QVERIFY(eng.evaluate("(function() { with (o) return x; })() === o").toBool());
         eng.evaluate("q = {}; with (o) with (q) x").equals(eng.evaluate("o"));
         // write
         eng.evaluate("o.__defineSetter__('x', function() { return this; });");
         // SpiderMonkey says setter return value, JSC says RHS.
-        QVERIFY(eng.evaluate("(o.x = 'foo') === 'foo'").toBoolean());
+        QVERIFY(eng.evaluate("(o.x = 'foo') === 'foo'").toBool());
         QVERIFY(eng.evaluate("with (o) x = 'foo'").equals("foo"));
         QVERIFY(eng.evaluate("with (o) with (q) x = 'foo'").equals("foo"));
     }
@@ -4542,15 +4542,15 @@ void tst_QJSEngine::getterSetterThisObject_prototypeChain()
         eng.evaluate("o = {}; p = {}; o.__proto__ = p");
         // read
         eng.evaluate("p.__defineGetter__('x', function() { return this; })");
-        QVERIFY(eng.evaluate("o.x === o").toBoolean());
+        QVERIFY(eng.evaluate("o.x === o").toBool());
         QVERIFY(eng.evaluate("with (o) x").equals(eng.evaluate("o")));
-        QVERIFY(eng.evaluate("(function() { with (o) return x; })() === o").toBoolean());
+        QVERIFY(eng.evaluate("(function() { with (o) return x; })() === o").toBool());
         eng.evaluate("q = {}; with (o) with (q) x").equals(eng.evaluate("o"));
         eng.evaluate("with (q) with (o) x").equals(eng.evaluate("o"));
         // write
         eng.evaluate("o.__defineSetter__('x', function() { return this; });");
         // SpiderMonkey says setter return value, JSC says RHS.
-        QVERIFY(eng.evaluate("(o.x = 'foo') === 'foo'").toBoolean());
+        QVERIFY(eng.evaluate("(o.x = 'foo') === 'foo'").toBool());
         QVERIFY(eng.evaluate("with (o) x = 'foo'").equals("foo"));
         QVERIFY(eng.evaluate("with (o) with (q) x = 'foo'").equals("foo"));
     }
@@ -4567,16 +4567,16 @@ void tst_QJSEngine::getterSetterThisObject_activation()
         act.setProperty("act", act);
         // read
         eng.evaluate("act.__defineGetter__('x', function() { return this; })");
-        QVERIFY(eng.evaluate("x === act").toBoolean());
+        QVERIFY(eng.evaluate("x === act").toBool());
         QEXPECT_FAIL("", "QTBUG-17605: Not possible to implement local variables as getter/setter properties", Abort);
         QVERIFY(!eng.hasUncaughtException());
         QVERIFY(eng.evaluate("with (act) x").equals("foo"));
-        QVERIFY(eng.evaluate("(function() { with (act) return x; })() === act").toBoolean());
+        QVERIFY(eng.evaluate("(function() { with (act) return x; })() === act").toBool());
         eng.evaluate("q = {}; with (act) with (q) x").equals(eng.evaluate("act"));
         eng.evaluate("with (q) with (act) x").equals(eng.evaluate("act"));
         // write
         eng.evaluate("act.__defineSetter__('x', function() { return this; });");
-        QVERIFY(eng.evaluate("(x = 'foo') === 'foo'").toBoolean());
+        QVERIFY(eng.evaluate("(x = 'foo') === 'foo'").toBool());
         QVERIFY(eng.evaluate("with (act) x = 'foo'").equals("foo"));
         QVERIFY(eng.evaluate("with (act) with (q) x = 'foo'").equals("foo"));
         eng.popContext();
@@ -4674,7 +4674,7 @@ void tst_QJSEngine::jsShadowReadOnlyPrototypeProperty()
     QJSEngine eng;
     QVERIFY(eng.evaluate("o = {}; o.__proto__ = parseInt; o.length").isNumber());
     QCOMPARE(eng.evaluate("o.length = 123; o.length").toInt32(), 123);
-    QVERIFY(eng.evaluate("o.hasOwnProperty('length')").toBoolean());
+    QVERIFY(eng.evaluate("o.hasOwnProperty('length')").toBool());
 }
 
 void tst_QJSEngine::toObject()
index 43dd7d5..5a9ccc5 100644 (file)
@@ -97,10 +97,10 @@ void tst_QJSValue::ctor_boolWithEngine()
     {
         QJSValue v(&eng, false);
         QCOMPARE(v.isValid(), true);
-        QCOMPARE(v.isBoolean(), true);
+        QCOMPARE(v.isBool(), true);
         QCOMPARE(v.isBool(), true);
         QCOMPARE(v.isObject(), false);
-        QCOMPARE(v.toBoolean(), false);
+        QCOMPARE(v.toBool(), false);
         QCOMPARE(v.engine(), &eng);
     }
 }
@@ -283,10 +283,10 @@ void tst_QJSValue::ctor_bool()
 {
     QJSValue v(false);
     QCOMPARE(v.isValid(), true);
-    QCOMPARE(v.isBoolean(), true);
+    QCOMPARE(v.isBool(), true);
     QCOMPARE(v.isBool(), true);
     QCOMPARE(v.isObject(), false);
-    QCOMPARE(v.toBoolean(), false);
+    QCOMPARE(v.toBool(), false);
     QCOMPARE(v.engine(), (QJSEngine *)0);
 }
 
@@ -536,49 +536,49 @@ void tst_QJSValue::toBoolean() // deprecated
     QJSEngine eng;
 
     QJSValue undefined = eng.undefinedValue();
-    QCOMPARE(undefined.toBoolean(), false);
+    QCOMPARE(undefined.toBool(), false);
     QCOMPARE(qjsvalue_cast<bool>(undefined), false);
 
     QJSValue null = eng.nullValue();
-    QCOMPARE(null.toBoolean(), false);
+    QCOMPARE(null.toBool(), false);
     QCOMPARE(qjsvalue_cast<bool>(null), false);
 
     {
         QJSValue falskt = QJSValue(&eng, false);
-        QCOMPARE(falskt.toBoolean(), false);
+        QCOMPARE(falskt.toBool(), false);
         QCOMPARE(qjsvalue_cast<bool>(falskt), false);
 
         QJSValue sant = QJSValue(&eng, true);
-        QCOMPARE(sant.toBoolean(), true);
+        QCOMPARE(sant.toBool(), true);
         QCOMPARE(qjsvalue_cast<bool>(sant), true);
 
         QJSValue number = QJSValue(&eng, 0.0);
-        QCOMPARE(number.toBoolean(), false);
+        QCOMPARE(number.toBool(), false);
         QCOMPARE(qjsvalue_cast<bool>(number), false);
 
         QJSValue number2 = QJSValue(&eng, qSNaN());
-        QCOMPARE(number2.toBoolean(), false);
+        QCOMPARE(number2.toBool(), false);
         QCOMPARE(qjsvalue_cast<bool>(number2), false);
 
         QJSValue number3 = QJSValue(&eng, 123.0);
-        QCOMPARE(number3.toBoolean(), true);
+        QCOMPARE(number3.toBool(), true);
         QCOMPARE(qjsvalue_cast<bool>(number3), true);
 
         QJSValue number4 = QJSValue(&eng, -456.0);
-        QCOMPARE(number4.toBoolean(), true);
+        QCOMPARE(number4.toBool(), true);
         QCOMPARE(qjsvalue_cast<bool>(number4), true);
 
         QJSValue str = QJSValue(&eng, QString(""));
-        QCOMPARE(str.toBoolean(), false);
+        QCOMPARE(str.toBool(), false);
         QCOMPARE(qjsvalue_cast<bool>(str), false);
 
         QJSValue str2 = QJSValue(&eng, QString("123"));
-        QCOMPARE(str2.toBoolean(), true);
+        QCOMPARE(str2.toBool(), true);
         QCOMPARE(qjsvalue_cast<bool>(str2), true);
     }
 
     QJSValue object = eng.newObject();
-    QCOMPARE(object.toBoolean(), true);
+    QCOMPARE(object.toBool(), true);
     QCOMPARE(qjsvalue_cast<bool>(object), true);
 
     // FIXME: No c-style callbacks currently
@@ -589,44 +589,44 @@ void tst_QJSValue::toBoolean() // deprecated
 #endif
 
     QJSValue inv = QJSValue();
-    QCOMPARE(inv.toBoolean(), false);
+    QCOMPARE(inv.toBool(), false);
     QCOMPARE(qjsvalue_cast<bool>(inv), false);
 
     // V2 constructors
     {
         QJSValue falskt = QJSValue(false);
-        QCOMPARE(falskt.toBoolean(), false);
+        QCOMPARE(falskt.toBool(), false);
         QCOMPARE(qjsvalue_cast<bool>(falskt), false);
 
         QJSValue sant = QJSValue(true);
-        QCOMPARE(sant.toBoolean(), true);
+        QCOMPARE(sant.toBool(), true);
         QCOMPARE(qjsvalue_cast<bool>(sant), true);
 
         QJSValue number = QJSValue(0.0);
-        QCOMPARE(number.toBoolean(), false);
+        QCOMPARE(number.toBool(), false);
         QCOMPARE(qjsvalue_cast<bool>(number), false);
 
         QJSValue number2 = QJSValue(qSNaN());
-        QCOMPARE(number2.toBoolean(), false);
+        QCOMPARE(number2.toBool(), false);
         QCOMPARE(qjsvalue_cast<bool>(number2), false);
 
         QJSValue number3 = QJSValue(123.0);
-        QCOMPARE(number3.toBoolean(), true);
+        QCOMPARE(number3.toBool(), true);
         QCOMPARE(qjsvalue_cast<bool>(number3), true);
 
         QJSValue number4 = QJSValue(-456.0);
-        QCOMPARE(number4.toBoolean(), true);
+        QCOMPARE(number4.toBool(), true);
         QCOMPARE(qjsvalue_cast<bool>(number4), true);
 
         QJSValue number5 = QJSValue(0x43211234);
-        QCOMPARE(number5.toBoolean(), true);
+        QCOMPARE(number5.toBool(), true);
 
         QJSValue str = QJSValue(QString(""));
-        QCOMPARE(str.toBoolean(), false);
+        QCOMPARE(str.toBool(), false);
         QCOMPARE(qjsvalue_cast<bool>(str), false);
 
         QJSValue str2 = QJSValue(QString("123"));
-        QCOMPARE(str2.toBoolean(), true);
+        QCOMPARE(str2.toBool(), true);
         QCOMPARE(qjsvalue_cast<bool>(str2), true);
     }
 }