aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-01-18 09:37:30 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-02 08:10:18 +0100
commited84a6ee63ac7a53f37efad3eb4a7e4eaa047242 (patch)
tree30fccf1b66a465a73594e74f4bda54f07e9cce5d /tests
parent4587be8097d23efe51ff46100bafad59640c10d8 (diff)
Remove invalid QJSValue type
Rationale: It's confusing to have an invalid type (which doesn't exist in JavaScript), and it creates lots of extra cases that have to be handled e.g. in value conversion and comparison. The Undefined type should be sufficient. Also, the invalid value type was being (ab)used to 1) make setProperty() act as a property deleter, and 2) signify that a property queried by property() doesn't exist. The recently introduced functions has(Own)Property() and deleteProperty() now provide that functionality. Default-constructed QJSValues now have the Undefined type. Task-number: QTBUG-23604 Change-Id: I1847492724d31e03ee1212c09ec87a2010920dc5 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qjsengine/tst_qjsengine.cpp204
-rw-r--r--tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp114
-rw-r--r--tests/auto/declarative/qjsvalueiterator/tst_qjsvalueiterator.cpp6
3 files changed, 158 insertions, 166 deletions
diff --git a/tests/auto/declarative/qjsengine/tst_qjsengine.cpp b/tests/auto/declarative/qjsengine/tst_qjsengine.cpp
index 2d49619a8c..ca45d7e1c3 100644
--- a/tests/auto/declarative/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/declarative/qjsengine/tst_qjsengine.cpp
@@ -347,7 +347,7 @@ void tst_QJSEngine::currentContext()
QCOMPARE(globalCtx->argumentCount(), 0);
QCOMPARE(globalCtx->backtrace().size(), 1);
QVERIFY(!globalCtx->isCalledAsConstructor());
- QVERIFY(!globalCtx->callee().isValid());
+ QVERIFY(globalCtx->callee().isUndefined());
QCOMPARE(globalCtx->state(), QScriptContext::NormalState);
QVERIFY(globalCtx->thisObject().strictlyEquals(eng.globalObject()));
QVERIFY(globalCtx->activationObject().strictlyEquals(eng.globalObject()));
@@ -362,7 +362,7 @@ void tst_QJSEngine::pushPopContext()
QVERIFY(ctx != 0);
QCOMPARE(ctx->parentContext(), globalCtx);
QVERIFY(!ctx->isCalledAsConstructor());
- QVERIFY(!ctx->callee().isValid());
+ QVERIFY(ctx->callee().isUndefined());
QVERIFY(ctx->thisObject().strictlyEquals(eng.globalObject()));
QCOMPARE(ctx->argumentCount(), 0);
QCOMPARE(ctx->backtrace().size(), 2);
@@ -434,7 +434,7 @@ void tst_QJSEngine::newFunction()
QScriptEngine eng;
{
QScriptValue fun = eng.newFunction(myFunction);
- QCOMPARE(fun.isValid(), true);
+ QVERIFY(!fun.isUndefined());
QCOMPARE(fun.isCallable(), true);
QCOMPARE(fun.isObject(), true);
QCOMPARE(fun.scriptClass(), (QScriptClass*)0);
@@ -447,7 +447,7 @@ void tst_QJSEngine::newFunction()
QCOMPARE(prot.propertyFlags("constructor"), QScriptValue::SkipInEnumeration);
}
// prototype should be Function.prototype
- QCOMPARE(fun.prototype().isValid(), true);
+ QVERIFY(!fun.prototype().isUndefined());
QCOMPARE(fun.prototype().isCallable(), true);
QCOMPARE(fun.prototype().strictlyEquals(eng.evaluate("Function.prototype")), true);
@@ -472,7 +472,7 @@ void tst_QJSEngine::newFunctionWithArg()
QCOMPARE(prot.propertyFlags("constructor"), QScriptValue::SkipInEnumeration);
}
// prototype should be Function.prototype
- QCOMPARE(fun.prototype().isValid(), true);
+ QVERIFY(!fun.prototype().isUndefined());
QCOMPARE(fun.prototype().isCallable(), true);
QCOMPARE(fun.prototype().strictlyEquals(eng.evaluate("Function.prototype")), true);
@@ -487,11 +487,11 @@ void tst_QJSEngine::newFunctionWithProto()
{
QScriptValue proto = eng.newObject();
QScriptValue fun = eng.newFunction(myFunction, proto);
- QCOMPARE(fun.isValid(), true);
+ QVERIFY(!fun.isUndefined());
QCOMPARE(fun.isCallable(), true);
QCOMPARE(fun.isObject(), true);
// internal prototype should be Function.prototype
- QCOMPARE(fun.prototype().isValid(), true);
+ QVERIFY(!fun.prototype().isUndefined());
QCOMPARE(fun.prototype().isCallable(), true);
QCOMPARE(fun.prototype().strictlyEquals(eng.evaluate("Function.prototype")), true);
// public prototype should be the one we passed
@@ -506,7 +506,7 @@ void tst_QJSEngine::newFunctionWithProto()
// whether the return value is correct
{
QScriptValue fun = eng.newFunction(myFunctionThatReturns);
- QCOMPARE(fun.isValid(), true);
+ QVERIFY(!fun.isUndefined());
QCOMPARE(fun.isCallable(), true);
QCOMPARE(fun.isObject(), true);
@@ -517,7 +517,7 @@ void tst_QJSEngine::newFunctionWithProto()
// whether the return value is assigned to the correct engine
{
QScriptValue fun = eng.newFunction(myFunctionThatReturnsWithoutEngine);
- QCOMPARE(fun.isValid(), true);
+ QVERIFY(!fun.isUndefined());
QCOMPARE(fun.isCallable(), true);
QCOMPARE(fun.isObject(), true);
@@ -531,13 +531,12 @@ void tst_QJSEngine::newFunctionWithProto()
QScriptEngine wrongEngine;
QScriptValue fun = eng.newFunction(myFunctionThatReturnsWrongEngine, reinterpret_cast<void *>(&wrongEngine));
- QCOMPARE(fun.isValid(), true);
+ QVERIFY(!fun.isUndefined());
QCOMPARE(fun.isCallable(), true);
QCOMPARE(fun.isObject(), true);
QTest::ignoreMessage(QtWarningMsg, "QScriptValue::call(): Value from different engine returned from native function, returning undefined value instead.");
QScriptValue result = fun.call();
- QCOMPARE(result.isValid(), true);
QCOMPARE(result.isUndefined(), true);
}
// checking if arguments are passed correctly
@@ -545,7 +544,7 @@ void tst_QJSEngine::newFunctionWithProto()
QScriptEngine wrongEngine;
QScriptValue fun = eng.newFunction(sumFunction);
- QCOMPARE(fun.isValid(), true);
+ QVERIFY(!fun.isUndefined());
QCOMPARE(fun.isCallable(), true);
QCOMPARE(fun.isObject(), true);
@@ -572,12 +571,12 @@ void tst_QJSEngine::newObject()
{
QJSEngine eng;
QJSValue object = eng.newObject();
- QCOMPARE(object.isValid(), true);
+ QVERIFY(!object.isUndefined());
QCOMPARE(object.isObject(), true);
QCOMPARE(object.isCallable(), false);
// ###FIXME: No QScriptClass QCOMPARE(object.scriptClass(), (QScriptClass*)0);
// prototype should be Object.prototype
- QCOMPARE(object.prototype().isValid(), true);
+ QVERIFY(!object.prototype().isUndefined());
QCOMPARE(object.prototype().isObject(), true);
QCOMPARE(object.prototype().strictlyEquals(eng.evaluate("Object.prototype")), true);
}
@@ -586,13 +585,13 @@ void tst_QJSEngine::newArray()
{
QJSEngine eng;
QJSValue array = eng.newArray();
- QCOMPARE(array.isValid(), true);
+ QVERIFY(!array.isUndefined());
QCOMPARE(array.isArray(), true);
QCOMPARE(array.isObject(), true);
QVERIFY(!array.isCallable());
// ###FIXME: No QScriptClass QCOMPARE(array.scriptClass(), (QScriptClass*)0);
// prototype should be Array.prototype
- QCOMPARE(array.prototype().isValid(), true);
+ QVERIFY(!array.prototype().isUndefined());
QCOMPARE(array.prototype().isArray(), true);
QCOMPARE(array.prototype().strictlyEquals(eng.evaluate("Array.prototype")), true);
}
@@ -655,11 +654,11 @@ void tst_QJSEngine::newVariant()
QJSEngine eng;
{
QJSValue opaque = eng.toScriptValue(QVariant(QPoint(1, 2)));
- QCOMPARE(opaque.isValid(), true);
+ QVERIFY(!opaque.isUndefined());
QCOMPARE(opaque.isVariant(), true);
QVERIFY(!opaque.isCallable());
QCOMPARE(opaque.isObject(), true);
- QCOMPARE(opaque.prototype().isValid(), true);
+ QVERIFY(!opaque.prototype().isUndefined());
QEXPECT_FAIL("", "FIXME: newly created QObject's prototype is an JS Object", Continue);
QCOMPARE(opaque.prototype().isVariant(), true);
QVERIFY(opaque.property("valueOf").callWithInstance(opaque).equals(opaque));
@@ -700,7 +699,7 @@ void tst_QJSEngine::newVariant_promoteObject()
QScriptValue originalProto = object.property("foo").prototype();
QSKIP("It is not possible to promote plain object to a wrapper");
QScriptValue ret = eng.newVariant(object.property("foo"), QVariant(123));
- QVERIFY(ret.isValid());
+ QVERIFY(ret.isObject());
QVERIFY(ret.strictlyEquals(object.property("foo")));
QVERIFY(ret.isVariant());
QVERIFY(object.property("foo").isVariant());
@@ -718,7 +717,7 @@ void tst_QJSEngine::newVariant_replaceValue()
QScriptValue object = eng.newVariant(QVariant(123));
for (int x = 0; x < 2; ++x) {
QScriptValue ret = eng.newVariant(object, QVariant(456));
- QVERIFY(ret.isValid());
+ QVERIFY(!ret.isUndefined());
QVERIFY(ret.strictlyEquals(object));
QVERIFY(ret.isVariant());
QCOMPARE(ret.toVariant(), QVariant(456));
@@ -759,7 +758,7 @@ void tst_QJSEngine::newVariant_promoteNonQScriptObject()
{
QTest::ignoreMessage(QtWarningMsg, "QScriptEngine::newVariant(): changing class of non-QScriptObject not supported");
QScriptValue ret = eng.newVariant(eng.newArray(), 123);
- QVERIFY(!ret.isValid());
+ QVERIFY(ret.isUndefined());
}
}
#endif
@@ -769,12 +768,12 @@ void tst_QJSEngine::newRegExp()
QSKIP("Test failing - QTBUG-22238");
QJSEngine eng;
QJSValue rexp = eng.toScriptValue(QRegExp("foo"));
- QCOMPARE(rexp.isValid(), true);
+ QVERIFY(!rexp.isUndefined());
QCOMPARE(rexp.isRegExp(), true);
QCOMPARE(rexp.isObject(), true);
QVERIFY(rexp.isCallable()); // in JSC, RegExp objects are callable
// prototype should be RegExp.prototype
- QCOMPARE(rexp.prototype().isValid(), true);
+ QVERIFY(!rexp.prototype().isUndefined());
QCOMPARE(rexp.prototype().isObject(), true);
QCOMPARE(rexp.prototype().isRegExp(), false);
QCOMPARE(rexp.prototype().strictlyEquals(eng.evaluate("RegExp.prototype")), true);
@@ -853,12 +852,12 @@ void tst_QJSEngine::newDate()
{
QJSValue date = eng.evaluate("new Date(0)");
- QCOMPARE(date.isValid(), true);
+ QVERIFY(!date.isUndefined());
QCOMPARE(date.isDate(), true);
QCOMPARE(date.isObject(), true);
QVERIFY(!date.isCallable());
// prototype should be Date.prototype
- QCOMPARE(date.prototype().isValid(), true);
+ QVERIFY(!date.prototype().isUndefined());
QCOMPARE(date.prototype().isDate(), true);
QCOMPARE(date.prototype().strictlyEquals(eng.evaluate("Date.prototype")), true);
}
@@ -866,11 +865,11 @@ void tst_QJSEngine::newDate()
{
QDateTime dt = QDateTime(QDate(1, 2, 3), QTime(4, 5, 6, 7), Qt::LocalTime);
QJSValue date = eng.toScriptValue(dt);
- QCOMPARE(date.isValid(), true);
+ QVERIFY(!date.isUndefined());
QCOMPARE(date.isDate(), true);
QCOMPARE(date.isObject(), true);
// prototype should be Date.prototype
- QCOMPARE(date.prototype().isValid(), true);
+ QVERIFY(!date.prototype().isUndefined());
QCOMPARE(date.prototype().isDate(), true);
QCOMPARE(date.prototype().strictlyEquals(eng.evaluate("Date.prototype")), true);
@@ -909,20 +908,19 @@ void tst_QJSEngine::newQObject()
{
QJSValue qobject = eng.newQObject(0);
- QCOMPARE(qobject.isValid(), true);
QCOMPARE(qobject.isNull(), true);
QCOMPARE(qobject.isObject(), false);
QCOMPARE(qobject.toQObject(), (QObject *)0);
}
{
QJSValue qobject = eng.newQObject(this);
- QCOMPARE(qobject.isValid(), true);
+ QVERIFY(!qobject.isUndefined());
QCOMPARE(qobject.isQObject(), true);
QCOMPARE(qobject.isObject(), true);
QCOMPARE(qobject.toQObject(), (QObject *)this);
QVERIFY(!qobject.isCallable());
// prototype should be QObject.prototype
- QCOMPARE(qobject.prototype().isValid(), true);
+ QCOMPARE(qobject.prototype().isObject(), true);
QEXPECT_FAIL("", "FIXME: newly created QObject's prototype is an JS Object", Continue);
QCOMPARE(qobject.prototype().isQObject(), true);
// ###FIXME: No QScriptClass QCOMPARE(qobject.scriptClass(), (QScriptClass*)0);
@@ -997,7 +995,7 @@ void tst_QJSEngine::newQObject_promoteObject()
QScriptValue obj = eng.newObject();
QScriptValue originalProto = obj.prototype();
QScriptValue ret = eng.newQObject(obj, this);
- QVERIFY(ret.isValid());
+ QVERIFY(!ret.isUndefined());
QVERIFY(ret.isQObject());
QVERIFY(ret.strictlyEquals(obj));
QVERIFY(obj.isQObject());
@@ -1025,7 +1023,7 @@ void tst_QJSEngine::newQObject_promoteObject()
QObject otherQObject;
for (int x = 0; x < 2; ++x) {
QScriptValue ret = eng.newQObject(object, &otherQObject);
- QVERIFY(ret.isValid());
+ QVERIFY(!ret.isUndefined());
QVERIFY(ret.isQObject());
QVERIFY(ret.strictlyEquals(object));
QCOMPARE(ret.toQObject(), (QObject *)&otherQObject);
@@ -1121,7 +1119,7 @@ void tst_QJSEngine::newQObject_promoteNonQScriptObject()
{
QTest::ignoreMessage(QtWarningMsg, "QScriptEngine::newQObject(): changing class of non-QScriptObject not supported");
QScriptValue ret = eng.newQObject(eng.newArray(), this);
- QVERIFY(!ret.isValid());
+ QVERIFY(ret.isUndefined());
}
#endif
}
@@ -1161,13 +1159,13 @@ void tst_QJSEngine::newQMetaObject()
QScriptValue qclass = qScriptValueFromQMetaObject<QObject>(&eng);
QScriptValue qclass2 = qScriptValueFromQMetaObject<QWidget>(&eng);
#endif
- QCOMPARE(qclass.isValid(), true);
+ QVERIFY(!qclass.isUndefined());
QCOMPARE(qclass.isQMetaObject(), true);
QCOMPARE(qclass.toQMetaObject(), &QObject::staticMetaObject);
QCOMPARE(qclass.isCallable(), true);
QVERIFY(qclass.property("prototype").isObject());
- QCOMPARE(qclass2.isValid(), true);
+ QVERIFY(!qclass2.isUndefined());
QCOMPARE(qclass2.isQMetaObject(), true);
QCOMPARE(qclass2.toQMetaObject(), &QWidget::staticMetaObject);
QCOMPARE(qclass2.isCallable(), true);
@@ -1288,7 +1286,7 @@ void tst_QJSEngine::newActivationObject()
QScriptEngine eng;
QScriptValue act = eng.newActivationObject();
QEXPECT_FAIL("", "", Continue);
- QCOMPARE(act.isValid(), true);
+ QVERIFY(!act.isUndefined());
QEXPECT_FAIL("", "", Continue);
QCOMPARE(act.isObject(), true);
QVERIFY(!act.isCallable());
@@ -1296,7 +1294,7 @@ void tst_QJSEngine::newActivationObject()
act.setProperty("prop", v);
QEXPECT_FAIL("", "", Continue);
QCOMPARE(act.property("prop").strictlyEquals(v), true);
- QCOMPARE(act.scope().isValid(), false);
+ QVERIFY(act.scope().isUndefined());
QEXPECT_FAIL("", "", Continue);
QVERIFY(act.prototype().isNull());
}
@@ -1311,9 +1309,9 @@ void tst_QJSEngine::getSetGlobalObjectSimple()
engine.evaluate("var bar = 100");
engine.setGlobalObject(object);
engine.evaluate("rab = 100");
- QVERIFY(engine.globalObject().property("rab").isValid());
- QVERIFY(engine.globalObject().property("foo").isValid());
- QVERIFY(!engine.globalObject().property("bar").isValid());
+ QVERIFY(!engine.globalObject().property("rab").isUndefined());
+ QVERIFY(!engine.globalObject().property("foo").isUndefined());
+ QVERIFY(engine.globalObject().property("bar").isUndefined());
}
void tst_QJSEngine::getSetGlobalObject()
@@ -1324,7 +1322,7 @@ void tst_QJSEngine::getSetGlobalObject()
collectGarbage_helper(eng);
glob = eng.globalObject();
- QCOMPARE(glob.isValid(), true);
+ QVERIFY(!glob.isUndefined());
QCOMPARE(glob.isObject(), true);
QVERIFY(!glob.isCallable());
QVERIFY(eng.currentContext()->thisObject().strictlyEquals(glob));
@@ -1332,7 +1330,7 @@ void tst_QJSEngine::getSetGlobalObject()
QEXPECT_FAIL("", "FIXME: Do we really want to enforce this? ECMA standard says that it is implementation dependent, skipping for now", Continue);
QCOMPARE(glob.toString(), QString::fromLatin1("[object global]"));
// prototype should be Object.prototype
- QCOMPARE(glob.prototype().isValid(), true);
+ QVERIFY(!glob.prototype().isUndefined());
QCOMPARE(glob.prototype().isObject(), true);
QEXPECT_FAIL("", "FIXME: Do we really want to enforce this? ECMA standard says that it is implementation dependent, skipping for now", Continue);
QCOMPARE(glob.prototype().strictlyEquals(eng.evaluate("Object.prototype")), true);
@@ -1365,7 +1363,7 @@ void tst_QJSEngine::getSetGlobalObject()
QVERIFY(eng.currentContext()->thisObject().strictlyEquals(obj));
QVERIFY(eng.currentContext()->activationObject().strictlyEquals(obj));
- QVERIFY(!obj.property("foo").isValid());
+ QVERIFY(obj.property("foo").isUndefined());
eng.evaluate("var foo = 123");
{
QScriptValue ret = obj.property("foo");
@@ -1373,7 +1371,7 @@ void tst_QJSEngine::getSetGlobalObject()
QCOMPARE(ret.toInt(), 123);
}
- QVERIFY(!obj.property("bar").isValid());
+ QVERIFY(obj.property("bar").isUndefined());
eng.evaluate("bar = 456");
{
QScriptValue ret = obj.property("bar");
@@ -1381,7 +1379,7 @@ void tst_QJSEngine::getSetGlobalObject()
QCOMPARE(ret.toInt(), 456);
}
- QVERIFY(!obj.property("baz").isValid());
+ QVERIFY(obj.property("baz").isUndefined());
eng.evaluate("this['baz'] = 789");
{
QScriptValue ret = obj.property("baz");
@@ -1399,7 +1397,7 @@ void tst_QJSEngine::getSetGlobalObject()
QScriptValue ret = eng.evaluate("delete foo");
QVERIFY(ret.isBool());
QVERIFY(ret.toBool());
- QVERIFY(!obj.property("foo").isValid());
+ QVERIFY(obj.property("foo").isUndefined());
}
// Getter/setter property.
@@ -1588,19 +1586,19 @@ void tst_QJSEngine::createGlobalObjectProperty()
// create property with no attributes
{
QString name = QString::fromLatin1("foo");
- QVERIFY(!global.property(name).isValid());
+ QVERIFY(global.property(name).isUndefined());
QJSValue val(123);
global.setProperty(name, val);
QVERIFY(global.property(name).equals(val));
QVERIFY(global.propertyFlags(name) == 0);
- global.setProperty(name, QJSValue());
- QVERIFY(!global.property(name).isValid());
+ global.deleteProperty(name);
+ QVERIFY(global.property(name).isUndefined());
}
// create property with attributes
#if 0 // ###FIXME: setProperty with flags is not supported
{
QString name = QString::fromLatin1("bar");
- QVERIFY(!global.property(name).isValid());
+ QVERIFY(global.property(name).isUndefined());
QScriptValue val(QString::fromLatin1("ciao"));
QScriptValue::PropertyFlags flags = QScriptValue::ReadOnly | QScriptValue::SkipInEnumeration;
global.setProperty(name, val, flags);
@@ -1608,7 +1606,7 @@ void tst_QJSEngine::createGlobalObjectProperty()
//QEXPECT_FAIL("", "QTBUG-6134: custom Global Object properties don't retain attributes", Continue);
QCOMPARE(global.propertyFlags(name), flags);
global.setProperty(name, QScriptValue());
- QVERIFY(!global.property(name).isValid());
+ QVERIFY(global.property(name).isUndefined());
}
#endif
}
@@ -1718,7 +1716,7 @@ void tst_QJSEngine::customGlobalObjectWithPrototype()
QVERIFY(ret.isCallable());
QVERIFY(ret.strictlyEquals(global.property("print")));
}
- QVERIFY(!anotherProto.property("print").isValid());
+ QVERIFY(anotherProto.property("print").isUndefined());
}
}
#endif
@@ -2218,7 +2216,7 @@ void tst_QJSEngine::uncaughtException()
eng.clearExceptions();
QVERIFY(!eng.hasUncaughtException());
QCOMPARE(eng.uncaughtExceptionLineNumber(), -1);
- QVERIFY(!eng.uncaughtException().isValid());
+ QVERIFY(eng.uncaughtException().isUndefined());
eng.evaluate("2 = 3");
QVERIFY(eng.hasUncaughtException());
@@ -2235,7 +2233,7 @@ void tst_QJSEngine::uncaughtException()
{
QScriptValue ret = eng.evaluate("a = 10");
QVERIFY(!eng.hasUncaughtException());
- QVERIFY(!eng.uncaughtException().isValid());
+ QVERIFY(eng.uncaughtException().isUndefined());
}
{
QScriptValue ret = eng.evaluate("1 = 2");
@@ -2279,7 +2277,7 @@ void tst_QJSEngine::getSetDefaultPrototype_int()
QScriptEngine eng;
QScriptValue object = eng.newObject();
- QCOMPARE(eng.defaultPrototype(qMetaTypeId<int>()).isValid(), false);
+ QVERIFY(eng.defaultPrototype(qMetaTypeId<int>()).isUndefined());
eng.setDefaultPrototype(qMetaTypeId<int>(), object);
QCOMPARE(eng.defaultPrototype(qMetaTypeId<int>()).strictlyEquals(object), true);
QScriptValue value = eng.newVariant(int(123));
@@ -2287,7 +2285,7 @@ void tst_QJSEngine::getSetDefaultPrototype_int()
QCOMPARE(value.prototype().strictlyEquals(object), true);
eng.setDefaultPrototype(qMetaTypeId<int>(), QScriptValue());
- QCOMPARE(eng.defaultPrototype(qMetaTypeId<int>()).isValid(), false);
+ QVERIFY(eng.defaultPrototype(qMetaTypeId<int>()).isUndefined());
QScriptValue value2 = eng.newVariant(int(123));
QCOMPARE(value2.prototype().strictlyEquals(object), false);
}
@@ -2297,7 +2295,7 @@ void tst_QJSEngine::getSetDefaultPrototype_customType()
QScriptEngine eng;
QScriptValue object = eng.newObject();
- QCOMPARE(eng.defaultPrototype(qMetaTypeId<Foo>()).isValid(), false);
+ QVERIFY(eng.defaultPrototype(qMetaTypeId<Foo>()).isUndefined());
eng.setDefaultPrototype(qMetaTypeId<Foo>(), object);
QCOMPARE(eng.defaultPrototype(qMetaTypeId<Foo>()).strictlyEquals(object), true);
QScriptValue value = eng.newVariant(qVariantFromValue(Foo()));
@@ -2305,7 +2303,7 @@ void tst_QJSEngine::getSetDefaultPrototype_customType()
QCOMPARE(value.prototype().strictlyEquals(object), true);
eng.setDefaultPrototype(qMetaTypeId<Foo>(), QScriptValue());
- QCOMPARE(eng.defaultPrototype(qMetaTypeId<Foo>()).isValid(), false);
+ QVERIFY(eng.defaultPrototype(qMetaTypeId<Foo>()).isUndefined());
QScriptValue value2 = eng.newVariant(qVariantFromValue(Foo()));
QCOMPARE(value2.prototype().strictlyEquals(object), false);
}
@@ -2558,8 +2556,6 @@ void tst_QJSEngine::valueConversion_QVariant()
QJSValue val1 = eng.toScriptValue(tmp1);
QJSValue val2 = eng.toScriptValue(tmp2);
- QVERIFY(val1.isValid());
- QVERIFY(val2.isValid());
QVERIFY(val1.isUndefined());
QEXPECT_FAIL("", "Variant are unrwapped, maybe we should not...", Continue);
QVERIFY(!val2.isUndefined());
@@ -2577,8 +2573,8 @@ void tst_QJSEngine::valueConversion_QVariant()
QJSValue val1 = eng.toScriptValue(tmp2);
QJSValue val2 = eng.toScriptValue(tmp3);
- QVERIFY(val1.isValid());
- QVERIFY(val2.isValid());
+ QVERIFY(!val1.isUndefined());
+ QVERIFY(!val2.isUndefined());
QEXPECT_FAIL("", "Variant are unrwapped, maybe we should not...", Continue);
QVERIFY(val1.isVariant());
QEXPECT_FAIL("", "Variant are unrwapped, maybe we should not...", Continue);
@@ -2742,8 +2738,8 @@ void tst_QJSEngine::valueConversion_regExp()
#if 0 // FIXME: No qScriptValueFromValue
void tst_QJSEngine::qScriptValueFromValue_noEngine()
{
- QVERIFY(!qScriptValueFromValue(0, 123).isValid());
- QVERIFY(!qScriptValueFromValue(0, QVariant(123)).isValid());
+ QVERIFY(qScriptValueFromValue(0, 123).isUndefined());
+ QVERIFY(qScriptValueFromValue(0, QVariant(123)).isUndefined());
}
#endif
@@ -2783,10 +2779,10 @@ void tst_QJSEngine::importExtension()
{
QScriptEngine eng;
for (int x = 0; x < 2; ++x) {
- QCOMPARE(eng.globalObject().property("com").isValid(), x == 1);
+ QCOMPARE(!eng.globalObject().property("com").isUndefined(), x == 1);
QScriptValue ret = eng.importExtension("com.trolltech");
QCOMPARE(eng.hasUncaughtException(), false);
- QCOMPARE(ret.isUndefined(), true);
+ QVERIFY(ret.isUndefined());
QScriptValue com = eng.globalObject().property("com");
QCOMPARE(com.isObject(), true);
@@ -3717,7 +3713,7 @@ void tst_QJSEngine::abortEvaluation()
switch (receiver.resultType) {
case EventReceiver3::None:
QVERIFY(!eng.hasUncaughtException());
- QVERIFY(!ret.isValid());
+ QVERIFY(ret.isUndefined());
break;
case EventReceiver3::Number:
QVERIFY(!eng.hasUncaughtException());
@@ -3760,7 +3756,7 @@ void tst_QJSEngine::abortEvaluation_tryCatch()
switch (receiver.resultType) {
case EventReceiver3::None:
QVERIFY(!eng.hasUncaughtException());
- QVERIFY(!ret.isValid());
+ QVERIFY(ret.isUndefined());
break;
case EventReceiver3::Number:
QVERIFY(!eng.hasUncaughtException());
@@ -3786,7 +3782,7 @@ void tst_QJSEngine::abortEvaluation_fromNative()
QScriptValue fun = eng.newFunction(myFunctionAbortingEvaluation);
eng.globalObject().setProperty("myFunctionAbortingEvaluation", fun);
QScriptValue ret = eng.evaluate("myFunctionAbortingEvaluation()");
- QVERIFY(!ret.isValid());
+ QVERIFY(ret.isUndefined());
}
class ThreadedEngine : public QThread {
@@ -3993,7 +3989,7 @@ void tst_QJSEngine::argumentsProperty_globalContext()
QCOMPARE(ret.toInt(), 10);
}
QVERIFY(eng.evaluate("delete arguments").toBool());
- QVERIFY(!eng.globalObject().property("arguments").isValid());
+ QVERIFY(eng.globalObject().property("arguments").isUndefined());
}
void tst_QJSEngine::argumentsProperty_JS()
@@ -4007,13 +4003,13 @@ void tst_QJSEngine::argumentsProperty_JS()
}
{
QJSEngine eng;
- QVERIFY(!eng.globalObject().property("arguments").isValid());
+ QVERIFY(eng.globalObject().property("arguments").isUndefined());
// This is testing ECMA-262 compliance. In function calls, "arguments"
// appears like a local variable, and it can be replaced.
QJSValue ret = eng.evaluate("(function() { arguments = 456; return arguments; })()");
QVERIFY(ret.isNumber());
QCOMPARE(ret.toInt(), 456);
- QVERIFY(!eng.globalObject().property("arguments").isValid());
+ QVERIFY(eng.globalObject().property("arguments").isUndefined());
}
}
@@ -4297,7 +4293,7 @@ void tst_QJSEngine::jsFunctionDeclarationAsStatement()
// check this behavior.
QJSEngine eng;
- QVERIFY(!eng.globalObject().property("bar").isValid());
+ QVERIFY(eng.globalObject().property("bar").isUndefined());
eng.evaluate("function foo(arg) {\n"
" if (arg == 'bar')\n"
" function bar() { return 'bar'; }\n"
@@ -4305,24 +4301,24 @@ void tst_QJSEngine::jsFunctionDeclarationAsStatement()
" function baz() { return 'baz'; }\n"
" return (arg == 'bar') ? bar : baz;\n"
"}");
- QVERIFY(!eng.globalObject().property("bar").isValid());
- QVERIFY(!eng.globalObject().property("baz").isValid());
+ QVERIFY(eng.globalObject().property("bar").isUndefined());
+ QVERIFY(eng.globalObject().property("baz").isUndefined());
QVERIFY(eng.evaluate("foo").isCallable());
{
QJSValue ret = eng.evaluate("foo('bar')");
QVERIFY(ret.isCallable());
QJSValue ret2 = ret.call();
QCOMPARE(ret2.toString(), QString::fromLatin1("bar"));
- QVERIFY(!eng.globalObject().property("bar").isValid());
- QVERIFY(!eng.globalObject().property("baz").isValid());
+ QVERIFY(eng.globalObject().property("bar").isUndefined());
+ QVERIFY(eng.globalObject().property("baz").isUndefined());
}
{
QJSValue ret = eng.evaluate("foo('baz')");
QVERIFY(ret.isCallable());
QJSValue ret2 = ret.call();
QCOMPARE(ret2.toString(), QString::fromLatin1("baz"));
- QVERIFY(!eng.globalObject().property("bar").isValid());
- QVERIFY(!eng.globalObject().property("baz").isValid());
+ QVERIFY(eng.globalObject().property("bar").isUndefined());
+ QVERIFY(eng.globalObject().property("baz").isUndefined());
}
}
@@ -4343,13 +4339,14 @@ void tst_QJSEngine::stringObjects()
QCOMPARE(obj.property(pname).toString(), QString(str.at(i)));
QEXPECT_FAIL("", "FIXME: This is V8 issue 862. ECMA script standard 15.5.5.2 compliance.", Continue);
QCOMPARE(obj.propertyFlags(pname), QJSValue::PropertyFlags(QJSValue::Undeletable | QJSValue::ReadOnly));
- obj.setProperty(pname, QJSValue());
+ QEXPECT_FAIL("", "FIXME: This is V8 issue 862. ECMA script standard 15.5.5.2 compliance.", Continue);
+ QVERIFY(!obj.deleteProperty(pname));
obj.setProperty(pname, QJSValue(&eng, 123));
QVERIFY(obj.property(pname).isString());
QCOMPARE(obj.property(pname).toString(), QString(str.at(i)));
}
- QVERIFY(!obj.property("-1").isValid());
- QVERIFY(!obj.property(QString::number(str.length())).isValid());
+ QVERIFY(obj.property("-1").isUndefined());
+ QVERIFY(obj.property(QString::number(str.length())).isUndefined());
QJSValue val(&eng, 123);
obj.setProperty("-1", val);
@@ -4950,14 +4947,14 @@ void tst_QJSEngine::reentrancy_typeConversion()
QCOMPARE(foo2.x, 12);
QCOMPARE(foo2.y, 34);
}
- QVERIFY(!eng1.defaultPrototype(qMetaTypeId<Foo>()).isValid());
- QVERIFY(!eng2.defaultPrototype(qMetaTypeId<Foo>()).isValid());
+ QVERIFY(eng1.defaultPrototype(qMetaTypeId<Foo>()).isUndefined());
+ QVERIFY(eng2.defaultPrototype(qMetaTypeId<Foo>()).isUndefined());
QScriptValue proto1 = eng1.newObject();
eng1.setDefaultPrototype(qMetaTypeId<Foo>(), proto1);
- QVERIFY(!eng2.defaultPrototype(qMetaTypeId<Foo>()).isValid());
+ QVERIFY(eng2.defaultPrototype(qMetaTypeId<Foo>()).isUndefined());
QScriptValue proto2 = eng2.newObject();
eng2.setDefaultPrototype(qMetaTypeId<Foo>(), proto2);
- QVERIFY(eng2.defaultPrototype(qMetaTypeId<Foo>()).isValid());
+ QVERIFY(!eng2.defaultPrototype(qMetaTypeId<Foo>()).isUndefined());
QVERIFY(eng1.defaultPrototype(qMetaTypeId<Foo>()).strictlyEquals(proto1));
}
#endif
@@ -4966,10 +4963,10 @@ void tst_QJSEngine::reentrancy_globalObjectProperties()
{
QJSEngine eng1;
QJSEngine eng2;
- QVERIFY(!eng2.globalObject().property("a").isValid());
+ QVERIFY(eng2.globalObject().property("a").isUndefined());
eng1.evaluate("a = 10");
QVERIFY(eng1.globalObject().property("a").isNumber());
- QVERIFY(!eng2.globalObject().property("a").isValid());
+ QVERIFY(eng2.globalObject().property("a").isUndefined());
eng2.evaluate("a = 20");
QVERIFY(eng2.globalObject().property("a").isNumber());
QCOMPARE(eng1.globalObject().property("a").toInt(), 10);
@@ -5095,13 +5092,13 @@ void tst_QJSEngine::installTranslatorFunctions()
{
QScriptEngine eng;
QScriptValue global = eng.globalObject();
- QVERIFY(!global.property("qsTranslate").isValid());
- QVERIFY(!global.property("QT_TRANSLATE_NOOP").isValid());
- QVERIFY(!global.property("qsTr").isValid());
- QVERIFY(!global.property("QT_TR_NOOP").isValid());
- QVERIFY(!global.property("qsTrId").isValid());
- QVERIFY(!global.property("QT_TRID_NOOP").isValid());
- QVERIFY(!global.property("String").property("prototype").property("arg").isValid());
+ QVERIFY(global.property("qsTranslate").isUndefined());
+ QVERIFY(global.property("QT_TRANSLATE_NOOP").isUndefined());
+ QVERIFY(global.property("qsTr").isUndefined());
+ QVERIFY(global.property("QT_TR_NOOP").isUndefined());
+ QVERIFY(global.property("qsTrId").isUndefined());
+ QVERIFY(global.property("QT_TRID_NOOP").isUndefined());
+ QVERIFY(global.property("String").property("prototype").property("arg").isUndefined());
eng.installTranslatorFunctions();
QVERIFY(global.property("qsTranslate").isCallable());
@@ -5582,13 +5579,13 @@ void tst_QJSEngine::functionScopes()
QEXPECT_FAIL("", "QScriptValue::scope() is internal, not implemented", Abort);
QVERIFY(fun.scope().isObject());
QVERIFY(fun.scope().strictlyEquals(eng.globalObject()));
- QVERIFY(!eng.globalObject().scope().isValid());
+ QVERIFY(eng.globalObject().scope().isUndefined());
}
{
QScriptValue fun = eng.globalObject().property("Object");
QVERIFY(fun.isCallable());
// native built-in functions don't have scope
- QVERIFY(!fun.scope().isValid());
+ QVERIFY(fun.scope().isUndefined());
}
{
// closure
@@ -5873,7 +5870,7 @@ void tst_QJSEngine::evaluateProgram_empty()
QScriptProgram program;
QVERIFY(program.isNull());
QScriptValue ret = eng.evaluate(program);
- QVERIFY(!ret.isValid());
+ QVERIFY(ret.isUndefined());
}
}
#endif
@@ -5976,7 +5973,6 @@ void tst_QJSEngine::qRegExpInport()
QJSValue rexp;
rexp = eng.toScriptValue(rx);
- QCOMPARE(rexp.isValid(), true);
QCOMPARE(rexp.isRegExp(), true);
QVERIFY(rexp.isCallable());
@@ -6110,7 +6106,7 @@ void tst_QJSEngine::newFixedStaticScopeObject()
}
// Property that doesn't exist.
- QVERIFY(!scope.property("noSuchProperty").isValid());
+ QVERIFY(scope.property("noSuchProperty").isUndefined());
QCOMPARE(scope.propertyFlags("noSuchProperty"), QScriptValue::PropertyFlags());
// Write to writable property.
@@ -6193,9 +6189,9 @@ void tst_QJSEngine::newFixedStaticScopeObject()
// As with normal JS, assigning to an undefined variable will create
// the property on the Global Object, not the inner scope.
- QVERIFY(!eng.globalObject().property("newProperty").isValid());
+ QVERIFY(eng.globalObject().property("newProperty").isUndefined());
QVERIFY(eng.evaluate("(function() { newProperty = 789; })()").isUndefined());
- QVERIFY(!scope.property("newProperty").isValid());
+ QVERIFY(!scope.property("newProperty").isUndefined());
QVERIFY(eng.globalObject().property("newProperty").isNumber());
// Nested static scope.
@@ -6238,7 +6234,7 @@ void tst_QJSEngine::newGrowingStaticScopeObject()
// Initially empty.
QVERIFY(!QScriptValueIterator(scope).hasNext());
- QVERIFY(!scope.property("foo").isValid());
+ QVERIFY(scope.property("foo").isUndefined());
// Add a static property.
scope.setProperty("foo", 123);
@@ -6345,7 +6341,7 @@ void tst_QJSEngine::scriptValueFromQMetaObject()
QCOMPARE(meta.toQMetaObject(), &QScriptEngine::staticMetaObject);
// Because of missing Q_SCRIPT_DECLARE_QMETAOBJECT() for QScriptEngine.
QEXPECT_FAIL("", "FIXME: because construct never returns invalid values", Continue);
- QVERIFY(!meta.callAsConstructor().isValid());
+ QVERIFY(meta.callAsConstructor().isUndefined());
}
{
QScriptValue meta = eng.scriptValueFromQMetaObject<QStandardItemModel>();
diff --git a/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp b/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
index d034b76c03..e478dc3fd3 100644
--- a/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
+++ b/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
@@ -62,7 +62,7 @@ void tst_QJSValue::ctor_invalid()
QJSEngine eng;
{
QJSValue v;
- QCOMPARE(v.isValid(), false);
+ QVERIFY(v.isUndefined());
QCOMPARE(v.engine(), (QJSEngine *)0);
}
}
@@ -72,8 +72,7 @@ void tst_QJSValue::ctor_undefinedWithEngine()
QJSEngine eng;
{
QJSValue v(&eng, QJSValue::UndefinedValue);
- QCOMPARE(v.isValid(), true);
- QCOMPARE(v.isUndefined(), true);
+ QVERIFY(v.isUndefined());
QCOMPARE(v.isObject(), false);
QCOMPARE(v.engine(), &eng);
}
@@ -84,7 +83,7 @@ void tst_QJSValue::ctor_nullWithEngine()
QJSEngine eng;
{
QJSValue v(&eng, QJSValue::NullValue);
- QCOMPARE(v.isValid(), true);
+ QVERIFY(!v.isUndefined());
QCOMPARE(v.isNull(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.engine(), &eng);
@@ -96,7 +95,7 @@ void tst_QJSValue::ctor_boolWithEngine()
QJSEngine eng;
{
QJSValue v(&eng, false);
- QCOMPARE(v.isValid(), true);
+ QVERIFY(!v.isUndefined());
QCOMPARE(v.isBool(), true);
QCOMPARE(v.isBool(), true);
QCOMPARE(v.isObject(), false);
@@ -110,7 +109,7 @@ void tst_QJSValue::ctor_intWithEngine()
QJSEngine eng;
{
QJSValue v(&eng, int(1));
- QCOMPARE(v.isValid(), true);
+ QVERIFY(!v.isUndefined());
QCOMPARE(v.isNumber(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.toNumber(), 1.0);
@@ -127,7 +126,7 @@ void tst_QJSValue::ctor_int()
}
{
QJSValue v(int(1));
- QCOMPARE(v.isValid(), true);
+ QVERIFY(!v.isUndefined());
QCOMPARE(v.isNumber(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.toNumber(), 1.0);
@@ -140,7 +139,7 @@ void tst_QJSValue::ctor_uintWithEngine()
QJSEngine eng;
{
QJSValue v(&eng, uint(1));
- QCOMPARE(v.isValid(), true);
+ QVERIFY(!v.isUndefined());
QCOMPARE(v.isNumber(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.toNumber(), 1.0);
@@ -157,7 +156,7 @@ void tst_QJSValue::ctor_uint()
}
{
QJSValue v(uint(1));
- QCOMPARE(v.isValid(), true);
+ QVERIFY(!v.isUndefined());
QCOMPARE(v.isNumber(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.toNumber(), 1.0);
@@ -170,7 +169,7 @@ void tst_QJSValue::ctor_floatWithEngine()
QJSEngine eng;
{
QJSValue v(&eng, 1.0);
- QCOMPARE(v.isValid(), true);
+ QVERIFY(!v.isUndefined());
QCOMPARE(v.isNumber(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.toNumber(), 1.0);
@@ -187,7 +186,7 @@ void tst_QJSValue::ctor_float()
}
{
QJSValue v(1.0);
- QCOMPARE(v.isValid(), true);
+ QVERIFY(!v.isUndefined());
QCOMPARE(v.isNumber(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.toNumber(), 1.0);
@@ -200,7 +199,7 @@ void tst_QJSValue::ctor_stringWithEngine()
QJSEngine eng;
{
QJSValue v(&eng, QLatin1String("ciao"));
- QCOMPARE(v.isValid(), true);
+ QVERIFY(!v.isUndefined());
QCOMPARE(v.isString(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.toString(), QLatin1String("ciao"));
@@ -212,7 +211,7 @@ void tst_QJSValue::ctor_string()
{
{
QJSValue v(QString("ciao"));
- QCOMPARE(v.isValid(), true);
+ QVERIFY(!v.isUndefined());
QCOMPARE(v.isString(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.toString(), QLatin1String("ciao"));
@@ -220,7 +219,7 @@ void tst_QJSValue::ctor_string()
}
{
QJSValue v("ciao");
- QCOMPARE(v.isValid(), true);
+ QVERIFY(!v.isUndefined());
QCOMPARE(v.isString(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.toString(), QLatin1String("ciao"));
@@ -264,8 +263,7 @@ void tst_QJSValue::ctor_copyAndAssignWithEngine()
void tst_QJSValue::ctor_undefined()
{
QJSValue v(QJSValue::UndefinedValue);
- QCOMPARE(v.isValid(), true);
- QCOMPARE(v.isUndefined(), true);
+ QVERIFY(v.isUndefined());
QCOMPARE(v.isObject(), false);
QCOMPARE(v.engine(), (QJSEngine *)0);
}
@@ -273,7 +271,7 @@ void tst_QJSValue::ctor_undefined()
void tst_QJSValue::ctor_null()
{
QJSValue v(QJSValue::NullValue);
- QCOMPARE(v.isValid(), true);
+ QVERIFY(!v.isUndefined());
QCOMPARE(v.isNull(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.engine(), (QJSEngine *)0);
@@ -282,7 +280,7 @@ void tst_QJSValue::ctor_null()
void tst_QJSValue::ctor_bool()
{
QJSValue v(false);
- QCOMPARE(v.isValid(), true);
+ QVERIFY(!v.isUndefined());
QCOMPARE(v.isBool(), true);
QCOMPARE(v.isBool(), true);
QCOMPARE(v.isObject(), false);
@@ -416,7 +414,7 @@ void tst_QJSValue::toString()
}
QJSValue inv = QJSValue();
- QCOMPARE(inv.toString(), QString());
+ QCOMPARE(inv.toString(), QString::fromLatin1("undefined"));
// V2 constructors
{
@@ -496,8 +494,8 @@ void tst_QJSValue::toNumber()
#endif
QJSValue inv = QJSValue();
- QCOMPARE(inv.toNumber(), 0.0);
- QCOMPARE(qjsvalue_cast<qreal>(inv), 0.0);
+ QVERIFY(qIsNaN(inv.toNumber()));
+ QVERIFY(qIsNaN(qjsvalue_cast<qreal>(inv)));
// V2 constructors
{
@@ -1495,7 +1493,6 @@ void tst_QJSValue::getSetProperty_HooliganTask183072()
void tst_QJSValue::getSetProperty_propertyRemoval()
{
- // test property removal (setProperty(QJSValue()))
QJSEngine eng;
QJSValue object = eng.newObject();
QJSValue str = QJSValue(&eng, QLatin1String("bar"));
@@ -1505,17 +1502,17 @@ void tst_QJSValue::getSetProperty_propertyRemoval()
QCOMPARE(object.property("foo").strictlyEquals(num), true);
object.setProperty("bar", str);
QCOMPARE(object.property("bar").strictlyEquals(str), true);
- object.setProperty("foo", QJSValue());
- QCOMPARE(object.property("foo").isValid(), false);
+ QVERIFY(object.deleteProperty("foo"));
+ QVERIFY(!object.hasOwnProperty("foo"));
QCOMPARE(object.property("bar").strictlyEquals(str), true);
object.setProperty("foo", num);
QCOMPARE(object.property("foo").strictlyEquals(num), true);
QCOMPARE(object.property("bar").strictlyEquals(str), true);
- object.setProperty("bar", QJSValue());
- QCOMPARE(object.property("bar").isValid(), false);
+ QVERIFY(object.deleteProperty("bar"));
+ QVERIFY(!object.hasOwnProperty("bar"));
QCOMPARE(object.property("foo").strictlyEquals(num), true);
- object.setProperty("foo", QJSValue());
- object.setProperty("foo", QJSValue());
+ QVERIFY(object.deleteProperty("foo"));
+ QVERIFY(!object.hasOwnProperty("foo"));
eng.globalObject().setProperty("object3", object);
QCOMPARE(eng.evaluate("object3.hasOwnProperty('foo')")
@@ -1523,7 +1520,7 @@ void tst_QJSValue::getSetProperty_propertyRemoval()
object.setProperty("foo", num);
QCOMPARE(eng.evaluate("object3.hasOwnProperty('foo')")
.strictlyEquals(QJSValue(&eng, true)), true);
- eng.globalObject().setProperty("object3", QJSValue());
+ QVERIFY(eng.globalObject().deleteProperty("object3"));
QCOMPARE(eng.evaluate("this.hasOwnProperty('object3')")
.strictlyEquals(QJSValue(&eng, false)), true);
}
@@ -1561,7 +1558,8 @@ void tst_QJSValue::getSetProperty_twoEngines()
QJSValue otherNum = QJSValue(&otherEngine, 123);
QTest::ignoreMessage(QtWarningMsg, "QJSValue::setProperty(oof) failed: cannot set value created in a different engine");
object.setProperty("oof", otherNum);
- QCOMPARE(object.property("oof").isValid(), false);
+ QVERIFY(!object.hasOwnProperty("oof"));
+ QVERIFY(object.property("oof").isUndefined());
}
@@ -1573,7 +1571,7 @@ void tst_QJSValue::getSetProperty_gettersAndSetters()
QJSValue num = QJSValue(&eng, 123.0);
QJSValue object = eng.newObject();
for (int x = 0; x < 2; ++x) {
- object.setProperty("foo", QJSValue());
+ object.deleteProperty("foo");
// getter() returns this.x
object.setProperty("foo", eng.newFunction(getter),
QJSValue::PropertyGetter | QJSValue::UserRange);
@@ -1618,7 +1616,7 @@ void tst_QJSValue::getSetProperty_gettersAndSetters()
}
for (int x = 0; x < 2; ++x) {
- object.setProperty("foo", QJSValue());
+ object.deleteProperty("foo");
// setter() sets this.x
object.setProperty("foo", eng.newFunction(setter), QJSValue::PropertySetter);
object.setProperty("foo", str);
@@ -1646,7 +1644,7 @@ void tst_QJSValue::getSetProperty_gettersAndSetters()
}
// use a single function as both getter and setter
- object.setProperty("foo", QJSValue());
+ object.deleteProperty("foo");
object.setProperty("foo", eng.newFunction(getterSetter),
QJSValue::PropertyGetter | QJSValue::PropertySetter);
QCOMPARE(object.propertyFlags("foo"),
@@ -1800,7 +1798,7 @@ void tst_QJSValue::getSetProperty_array()
QCOMPARE(array.property("length").toUInt(), quint32(2));
array.setProperty("length", QJSValue(&eng, 1));
QCOMPARE(array.property("length").toUInt(), quint32(1));
- QCOMPARE(array.property(1).isValid(), false);
+ QVERIFY(array.property(1).isUndefined());
}
void tst_QJSValue::getSetProperty_gettersAndSettersStupid()
@@ -1863,7 +1861,7 @@ void tst_QJSValue::getSetProperty()
QJSValue inv;
inv.setProperty("foo", num);
- QCOMPARE(inv.property("foo").isValid(), false);
+ QCOMPARE(inv.property("foo").isUndefined(), true);
eng.globalObject().setProperty("object", object);
@@ -1916,7 +1914,7 @@ void tst_QJSValue::getSetProperty()
QCOMPARE(ret.strictlyEquals(QJSValue(&eng, true)), true);
}
// should still be deletable from C++
- object.setProperty("undeletableProperty", QJSValue());
+ object.deleteProperty("undeletableProperty");
QEXPECT_FAIL("", "QTBUG-17617: With JSC-based back-end, undeletable properties can't be deleted from C++", Continue);
QVERIFY(!object.property("undeletableProperty").isValid());
QEXPECT_FAIL("", "QTBUG-17617: With JSC-based back-end, undeletable properties can't be deleted from C++", Continue);
@@ -1981,7 +1979,7 @@ void tst_QJSValue::getSetProperty()
// using interned strings
QScriptString foo = eng.toStringHandle("foo");
- object.setProperty(foo, QJSValue());
+ QVERIFY(object.deleteProperty(foo));
QVERIFY(!object.property(foo).isValid());
object.setProperty(foo, num);
@@ -2068,7 +2066,7 @@ void tst_QJSValue::getSetPrototype_invalidPrototype()
QJSValue proto = object.prototype();
QVERIFY(object.prototype().strictlyEquals(proto));
inv.setPrototype(object);
- QCOMPARE(inv.prototype().isValid(), false);
+ QVERIFY(inv.prototype().isUndefined());
object.setPrototype(inv);
QVERIFY(object.prototype().strictlyEquals(proto));
}
@@ -2566,8 +2564,7 @@ void tst_QJSValue::call_invalidArguments()
args << QJSValue();
QJSValue ret = fun.callWithInstance(args);
QVERIFY(!eng.hasUncaughtException());
- QCOMPARE(ret.isValid(), true);
- QCOMPARE(ret.isUndefined(), true);
+ QVERIFY(ret.isUndefined());
}
}
{
@@ -2576,8 +2573,7 @@ void tst_QJSValue::call_invalidArguments()
QJSValueList args;
args << QJSValue();
QJSValue ret = fun.call(args);
- QCOMPARE(ret.isValid(), true);
- QCOMPARE(ret.isUndefined(), true);
+ QVERIFY(ret.isUndefined());
}
}
{
@@ -2586,7 +2582,7 @@ void tst_QJSValue::call_invalidArguments()
QJSValueList args;
args << QJSValue() << QJSValue();
QJSValue ret = fun.call(args);
- QCOMPARE(ret.isValid(), true);
+ QVERIFY(!ret.isUndefined());
QCOMPARE(ret.isNumber(), true);
QCOMPARE(qIsNaN(ret.toNumber()), true);
}
@@ -2602,7 +2598,7 @@ void tst_QJSValue::call_invalidReturn()
QJSValue fun = eng.newFunction(returnInvalidValue);
eng.globalObject().setProperty("returnInvalidValue", fun);
QJSValue ret = eng.evaluate("returnInvalidValue() + returnInvalidValue()");
- QCOMPARE(ret.isValid(), true);
+ QVERIFY(!ret.isUndefined());
QCOMPARE(ret.isNumber(), true);
QCOMPARE(qIsNaN(ret.toNumber()), true);
#endif
@@ -2619,11 +2615,11 @@ void tst_QJSValue::call_twoEngines()
QTest::ignoreMessage(QtWarningMsg, "QJSValue::call() failed: "
"cannot call function with thisObject created in "
"a different engine");
- QCOMPARE(fun.callWithInstance(object).isValid(), false);
+ QVERIFY(fun.callWithInstance(object).isUndefined());
QTest::ignoreMessage(QtWarningMsg, "QJSValue::call() failed: "
"cannot call function with argument created in "
"a different engine");
- QCOMPARE(fun.call(QJSValueList() << QJSValue(&eng, 123)).isValid(), false);
+ QVERIFY(fun.call(QJSValueList() << QJSValue(&eng, 123)).isUndefined());
{
QJSValue fun = eng.evaluate("Object");
QVERIFY(fun.isCallable());
@@ -2703,7 +2699,7 @@ void tst_QJSValue::call_nonFunction()
{
// calling things that are not functions
QFETCH(QJSValue, value);
- QVERIFY(!value.call().isValid());
+ QVERIFY(value.call().isUndefined());
}
#if 0 // FIXME: no c-style callbacks
@@ -2743,7 +2739,7 @@ void tst_QJSValue::construct_nonFunction_data()
void tst_QJSValue::construct_nonFunction()
{
QFETCH(QJSValue, value);
- QVERIFY(!value.callAsConstructor().isValid());
+ QVERIFY(value.callAsConstructor().isUndefined());
}
void tst_QJSValue::construct_simple()
@@ -2752,6 +2748,7 @@ void tst_QJSValue::construct_simple()
QJSValue fun = eng.evaluate("(function () { this.foo = 123; })");
QVERIFY(fun.isCallable());
QJSValue ret = fun.callAsConstructor();
+ QVERIFY(!ret.isUndefined());
QVERIFY(ret.isObject());
QVERIFY(ret.prototype().strictlyEquals(fun.property("prototype")));
QCOMPARE(ret.property("foo").toInt(), 123);
@@ -2848,7 +2845,6 @@ void tst_QJSValue::construct()
// construct with single array object as arguments
QJSValue ret = fun.callAsConstructor(array);
QVERIFY(!eng.hasUncaughtException());
- QVERIFY(ret.isValid());
QVERIFY(ret.isObject());
QCOMPARE(ret.property(0).strictlyEquals(array.property(0)), true);
QCOMPARE(ret.property(1).strictlyEquals(array.property(1)), true);
@@ -2885,9 +2881,9 @@ void tst_QJSValue::construct_twoEngines()
QJSValue ctor = engine.evaluate("(function (a, b) { this.foo = 123; })");
QJSValue arg(&otherEngine, 124567);
QTest::ignoreMessage(QtWarningMsg, "QJSValue::callAsConstructor() failed: cannot construct function with argument created in a different engine");
- QVERIFY(!ctor.callAsConstructor(QJSValueList() << arg).isValid());
+ QVERIFY(ctor.callAsConstructor(QJSValueList() << arg).isUndefined());
QTest::ignoreMessage(QtWarningMsg, "QJSValue::callAsConstructor() failed: cannot construct function with argument created in a different engine");
- QVERIFY(!ctor.callAsConstructor(QJSValueList() << arg << otherEngine.newObject()).isValid());
+ QVERIFY(ctor.callAsConstructor(QJSValueList() << arg << otherEngine.newObject()).isUndefined());
}
void tst_QJSValue::construct_constructorThrowsPrimitive()
@@ -3069,8 +3065,8 @@ void tst_QJSValue::equals()
QCOMPARE(null.equals(null), true);
QCOMPARE(undefined.equals(null), true);
QCOMPARE(null.equals(undefined), true);
- QCOMPARE(undefined.equals(QJSValue()), false);
- QCOMPARE(null.equals(QJSValue()), false);
+ QVERIFY(undefined.equals(QJSValue()));
+ QVERIFY(null.equals(QJSValue()));
QVERIFY(!null.equals(num));
QVERIFY(!undefined.equals(num));
@@ -3512,18 +3508,18 @@ void tst_QJSValue::engineDeleted()
delete eng;
- QVERIFY(!v1.isValid());
+ QVERIFY(v1.isUndefined());
QVERIFY(v1.engine() == 0);
- QVERIFY(!v2.isValid());
+ QVERIFY(v2.isUndefined());
QVERIFY(v2.engine() == 0);
- QVERIFY(!v3.isValid());
+ QVERIFY(v3.isUndefined());
QVERIFY(v3.engine() == 0);
- QVERIFY(!v4.isValid());
+ QVERIFY(v4.isUndefined());
QVERIFY(v4.engine() == 0);
- QVERIFY(v5.isValid());
+ QVERIFY(v5.isString()); // was not bound to engine
QVERIFY(v5.engine() == 0);
- QVERIFY(!v3.property("foo").isValid());
+ QVERIFY(v3.property("foo").isUndefined());
}
void tst_QJSValue::valueOfWithClosure()
diff --git a/tests/auto/declarative/qjsvalueiterator/tst_qjsvalueiterator.cpp b/tests/auto/declarative/qjsvalueiterator/tst_qjsvalueiterator.cpp
index f54fcc3918..1965924a09 100644
--- a/tests/auto/declarative/qjsvalueiterator/tst_qjsvalueiterator.cpp
+++ b/tests/auto/declarative/qjsvalueiterator/tst_qjsvalueiterator.cpp
@@ -506,15 +506,15 @@ void tst_QJSValueIterator::iterateOverObjectFromDeletedEngine()
delete engine;
- QVERIFY(!objet.isValid());
+ QVERIFY(objet.isUndefined());
QVERIFY(it.name().isEmpty());
- QVERIFY(!it.value().isValid());
+ QVERIFY(it.value().isUndefined());
QVERIFY(!it.hasNext());
it.next();
QVERIFY(it.name().isEmpty());
- QVERIFY(!it.value().isValid());
+ QVERIFY(it.value().isUndefined());
}