We should use "toBool" and "isBool" for consistency with QVariant.
Change-Id: I266f2a36a034a5b323e614777ceacbc0d2ffec16
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
}
/*!
- \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.
}
/*!
- \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".
QJSEngine *engine() const;
bool isValid() const;
bool isBool() const;
- bool isBoolean() const;
bool isNumber() const;
bool isFunction() const;
bool isNull() const;
QString toString() const;
double toNumber() const;
bool toBool() const;
- bool toBoolean() const;
double toInteger() const;
qint32 toInt32() const;
quint32 toUInt32() const;
{
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());
}
// 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);
}
}
{
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));
{
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));
{
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)));
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()
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());
}
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());
}
}
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"));
}
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"));
}
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();
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()
{
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);
}
}
{
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);
}
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
#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);
}
}