Skip to content

Commit

Permalink
Remove obsolete toBoolean() and isBoolean() QJSValue getters
Browse files Browse the repository at this point in the history
We should use "toBool" and "isBool" for consistency with QVariant.

Change-Id: I266f2a36a034a5b323e614777ceacbc0d2ffec16
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
  • Loading branch information
Simon Hausmann authored and Qt by Nokia committed Jan 11, 2012
1 parent 424d302 commit 30fdb6d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 86 deletions.
26 changes: 0 additions & 26 deletions src/declarative/qml/v8/qjsvalue.cpp
Expand Up @@ -368,20 +368,6 @@ bool QJSValue::isBool() const
return d->isBool();
}

/*!
\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.
Expand Down Expand Up @@ -557,18 +543,6 @@ bool QJSValue::toBool() const
return d->toBool();
}

/*!
\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".
Expand Down
2 changes: 0 additions & 2 deletions src/declarative/qml/v8/qjsvalue.h
Expand Up @@ -92,7 +92,6 @@ class Q_DECLARATIVE_EXPORT QJSValue
QJSEngine *engine() const;
bool isValid() const;
bool isBool() const;
bool isBoolean() const;
bool isNumber() const;
bool isFunction() const;
bool isNull() const;
Expand All @@ -109,7 +108,6 @@ class Q_DECLARATIVE_EXPORT QJSValue
QString toString() const;
double toNumber() const;
bool toBool() const;
bool toBoolean() const;
double toInteger() const;
qint32 toInt32() const;
quint32 toUInt32() const;
Expand Down
66 changes: 33 additions & 33 deletions tests/auto/declarative/qjsengine/tst_qjsengine.cpp
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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"));
}
Expand All @@ -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"));
}
Expand All @@ -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();
Expand Down Expand Up @@ -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()
Expand Down
50 changes: 25 additions & 25 deletions tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 30fdb6d

Please sign in to comment.