diff options
-rw-r--r-- | src/declarative/qml/v8/qjsvalue.cpp | 43 | ||||
-rw-r--r-- | src/declarative/qml/v8/qjsvalue.h | 4 | ||||
-rw-r--r-- | src/declarative/qml/v8/qjsvalue_impl_p.h | 148 | ||||
-rw-r--r-- | src/declarative/qml/v8/qjsvalue_p.h | 7 | ||||
-rw-r--r-- | src/declarative/qml/v8/qjsvalueiterator_impl_p.h | 4 | ||||
-rw-r--r-- | src/declarative/qml/v8/qv8engine.cpp | 4 | ||||
-rw-r--r-- | src/declarative/qml/v8/qv8typewrapper.cpp | 4 | ||||
-rw-r--r-- | tests/auto/declarative/qjsengine/tst_qjsengine.cpp | 204 | ||||
-rw-r--r-- | tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp | 114 | ||||
-rw-r--r-- | tests/auto/declarative/qjsvalueiterator/tst_qjsvalueiterator.cpp | 6 |
10 files changed, 191 insertions, 347 deletions
diff --git a/src/declarative/qml/v8/qjsvalue.cpp b/src/declarative/qml/v8/qjsvalue.cpp index a34031d555..73b7e4f9c7 100644 --- a/src/declarative/qml/v8/qjsvalue.cpp +++ b/src/declarative/qml/v8/qjsvalue.cpp @@ -111,14 +111,6 @@ QT_BEGIN_NAMESPACE /*! - Constructs an invalid value. -*/ -QJSValue::QJSValue() - : d_ptr(InvalidValue()) -{ -} - -/*! Constructs a new QJSValue with a boolean \a value. */ QJSValue::QJSValue(bool value) @@ -347,23 +339,6 @@ QJSValue::~QJSValue() { } -#ifdef QT_DEPRECATED - -/*! - \obsolete - - Returns true if this QJSValue is valid; otherwise returns - false. -*/ -bool QJSValue::isValid() const -{ - Q_D(const QJSValue); - QScriptIsolate api(d->engine()); - return d->isValid(); -} - -#endif // QT_DEPRECATED - /*! Returns true if this QJSValue is of the primitive type Boolean; otherwise returns false. @@ -693,7 +668,7 @@ QJSValue QJSValue::call(const QJSValueList &args) the function. If this QJSValue is not a function, call() does nothing - and returns an invalid QJSValue. + and returns an undefined QJSValue. Note that if \a instance is not an object, the global object (see \l{QJSEngine::globalObject()}) will be used as the @@ -787,7 +762,7 @@ QJSEngine* QJSValue::engine() const /*! If this QJSValue is an object, returns the internal prototype (\c{__proto__} property) of this object; otherwise returns an - invalid QJSValue. + undefined QJSValue. \sa setPrototype(), isObject() */ @@ -893,7 +868,7 @@ bool QJSValue::strictlyEquals(const QJSValue& other) const /*! Returns the value of this QJSValue's property with the given \a name. - If no such property exists, an invalid QJSValue is returned. + If no such property exists, an undefined QJSValue is returned. If the property is implemented using a getter function (i.e. has the PropertyGetter flag set), calling property() has side-effects on the @@ -939,18 +914,6 @@ QJSValue QJSValue::property(quint32 arrayIndex) const If this QJSValue does not already have a property with name \a name, a new property is created. - If \a value is invalid, the property is removed. - - If the property is implemented using a setter function (i.e. has the - PropertySetter flag set), calling setProperty() has side-effects on - the script engine, since the setter function will be called with the - given \a value as argument (possibly resulting in an uncaught script - exception). - - Note that you cannot specify custom getter or setter functions for - built-in properties, such as the \c{length} property of Array objects - or meta properties of QObject objects. - \sa property(), deleteProperty() */ void QJSValue::setProperty(const QString& name, const QJSValue& value) diff --git a/src/declarative/qml/v8/qjsvalue.h b/src/declarative/qml/v8/qjsvalue.h index f0be07e725..8ec2932dc3 100644 --- a/src/declarative/qml/v8/qjsvalue.h +++ b/src/declarative/qml/v8/qjsvalue.h @@ -66,11 +66,10 @@ public: }; public: - QJSValue(); + QJSValue(SpecialValue value = UndefinedValue); ~QJSValue(); QJSValue(const QJSValue &other); - QJSValue(SpecialValue value); QJSValue(bool value); QJSValue(int value); QJSValue(uint value); @@ -137,7 +136,6 @@ public: QT_DEPRECATED QJSEngine *engine() const; - QT_DEPRECATED bool isValid() const; QT_DEPRECATED bool isFunction() const; QT_DEPRECATED qint32 toInt32() const; QT_DEPRECATED quint32 toUInt32() const; diff --git a/src/declarative/qml/v8/qjsvalue_impl_p.h b/src/declarative/qml/v8/qjsvalue_impl_p.h index 386b203a41..b4e66ed093 100644 --- a/src/declarative/qml/v8/qjsvalue_impl_p.h +++ b/src/declarative/qml/v8/qjsvalue_impl_p.h @@ -42,30 +42,6 @@ QT_BEGIN_NAMESPACE -// This template is used indirectly by the Q_GLOBAL_STATIC macro below -template<> -class QGlobalStaticDeleter<QJSValuePrivate> -{ -public: - QGlobalStatic<QJSValuePrivate> &globalStatic; - QGlobalStaticDeleter(QGlobalStatic<QJSValuePrivate> &_globalStatic) - : globalStatic(_globalStatic) - { - globalStatic.pointer.load()->ref.ref(); - } - - inline ~QGlobalStaticDeleter() - { - if (!globalStatic.pointer.load()->ref.deref()) { // Logic copy & paste from SharedDataPointer - delete globalStatic.pointer.load(); - } - globalStatic.pointer.store(0); - globalStatic.destroyed = true; - } -}; - -Q_GLOBAL_STATIC(QJSValuePrivate, InvalidValue) - QJSValuePrivate* QJSValuePrivate::get(const QJSValue& q) { Q_ASSERT(q.d_ptr.data()); return q.d_ptr.data(); } QJSValue QJSValuePrivate::get(const QJSValuePrivate* d) @@ -86,11 +62,6 @@ QJSValue QJSValuePrivate::get(QJSValuePrivate* d) return QJSValue(d); } -QJSValuePrivate::QJSValuePrivate() - : m_engine(0), m_state(Invalid) -{ -} - QJSValuePrivate::QJSValuePrivate(bool value) : m_engine(0), m_state(CBool), u(value) { @@ -208,7 +179,6 @@ bool QJSValuePrivate::toBool() const return !(qIsNaN(u.m_number) || !u.m_number); case CBool: return u.m_bool; - case Invalid: case CNull: case CUndefined: return false; @@ -233,8 +203,6 @@ double QJSValuePrivate::toNumber() const case CBool: return u.m_bool ? 1 : 0; case CNull: - case Invalid: - return 0; case CUndefined: return qQNaN(); case CString: @@ -259,8 +227,6 @@ double QJSValuePrivate::toNumber() const QString QJSValuePrivate::toString() const { switch (m_state) { - case Invalid: - return QString(); case CBool: return u.m_bool ? QString::fromLatin1("true") : QString::fromLatin1("false"); case CString: @@ -290,8 +256,6 @@ QString QJSValuePrivate::toString() const QVariant QJSValuePrivate::toVariant() const { switch (m_state) { - case Invalid: - return QVariant(); case CBool: return QVariant(u.m_bool); case CString: @@ -427,11 +391,6 @@ inline bool QJSValuePrivate::isUndefined() const return m_state == CUndefined || (isJSBased() && m_value->IsUndefined()); } -inline bool QJSValuePrivate::isValid() const -{ - return m_state != Invalid; -} - inline bool QJSValuePrivate::isVariant() const { return isJSBased() && m_engine->isVariant(m_value); @@ -454,12 +413,6 @@ bool QJSValuePrivate::isQObject() const inline bool QJSValuePrivate::equals(QJSValuePrivate* other) { - if (!isValid()) - return !other->isValid(); - - if (!other->isValid()) - return false; - if (!isJSBased() && !other->isJSBased()) { switch (m_state) { case CNull: @@ -559,10 +512,8 @@ inline bool QJSValuePrivate::strictlyEquals(QJSValuePrivate* other) return u.m_bool == other->u.m_bool; } - if (!isValid() && !other->isValid()) - return true; - - return false; + return (isUndefined() && other->isUndefined()) + || (isNull() && other->isNull()); } inline bool QJSValuePrivate::lessThan(QJSValuePrivate *other) const @@ -572,9 +523,6 @@ inline bool QJSValuePrivate::lessThan(QJSValuePrivate *other) const return false; } - if (!isValid() || !other->isValid()) - return false; - if (isString() && other->isString()) return toString() < other->toString(); @@ -609,7 +557,7 @@ inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::prototype() const v8::HandleScope handleScope; return new QJSValuePrivate(engine(), v8::Handle<v8::Object>::Cast(m_value)->GetPrototype()); } - return InvalidValue(); + return new QJSValuePrivate(); } inline void QJSValuePrivate::setPrototype(QJSValuePrivate* prototype) @@ -644,42 +592,6 @@ inline void QJSValuePrivate::setProperty(v8::Handle<v8::String> name, QJSValuePr if (!value->isJSBased()) value->assignEngine(engine()); - if (!value->isValid()) { - // Remove the property. - v8::HandleScope handleScope; - v8::TryCatch tryCatch; - v8::Handle<v8::Object> recv(v8::Object::Cast(*m_value)); -// if (attribs & QJSValue::PropertyGetter && !(attribs & QJSValue::PropertySetter)) { -// v8::Local<v8::Object> descriptor = engine()->originalGlobalObject()->getOwnPropertyDescriptor(recv, name); -// if (!descriptor.IsEmpty()) { -// v8::Local<v8::Value> setter = descriptor->Get(v8::String::New("set")); -// if (!setter.IsEmpty() && !setter->IsUndefined()) { -// recv->Delete(name); -// engine()->originalGlobalObject()->defineGetterOrSetter(recv, name, setter, QJSValue::PropertySetter); -// if (tryCatch.HasCaught()) -// engine()->setException(tryCatch.Exception(), tryCatch.Message()); -// return; -// } -// } -// } else if (attribs & QJSValue::PropertySetter && !(attribs & QJSValue::PropertyGetter)) { -// v8::Local<v8::Object> descriptor = engine()->originalGlobalObject()->getOwnPropertyDescriptor(recv, name); -// if (!descriptor.IsEmpty()) { -// v8::Local<v8::Value> getter = descriptor->Get(v8::String::New("get")); -// if (!getter.IsEmpty() && !getter->IsUndefined()) { -// recv->Delete(name); -// engine()->originalGlobalObject()->defineGetterOrSetter(recv, name, getter, QJSValue::PropertyGetter); -// if (tryCatch.HasCaught()) -// engine()->setException(tryCatch.Exception(), tryCatch.Message()); -// return; -// } -// } -// } - recv->Delete(name); - if (tryCatch.HasCaught()) - engine()->setException(tryCatch.Exception(), tryCatch.Message()); - return; - } - if (engine() != value->engine()) { qWarning("QJSValue::setProperty(%s) failed: " "cannot set value created in a different engine", @@ -715,16 +627,6 @@ inline void QJSValuePrivate::setProperty(quint32 index, QJSValuePrivate* value, if (!value->isJSBased()) value->assignEngine(engine()); - if (!value->isValid()) { - // Remove the property. - v8::HandleScope handleScope; - v8::TryCatch tryCatch; - v8::Object::Cast(*m_value)->Delete(index); - if (tryCatch.HasCaught()) - engine()->setException(tryCatch.Exception(), tryCatch.Message()); - return; - } - if (engine() != value->engine()) { qWarning("QJSValue::setProperty() failed: cannot set value created in a different engine"); return; @@ -739,10 +641,10 @@ inline void QJSValuePrivate::setProperty(quint32 index, QJSValuePrivate* value, inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::property(const QString& name) const { - if (!name.length()) - return InvalidValue(); if (!isObject()) - return InvalidValue(); + return new QJSValuePrivate(); + if (!name.length()) + return new QJSValuePrivate(engine()); v8::HandleScope handleScope; return property(QJSConverter::toString(name)); @@ -752,14 +654,14 @@ inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::property(v8::Handle< { Q_ASSERT(!name.IsEmpty()); if (!isObject()) - return InvalidValue(); + return new QJSValuePrivate(); return property<>(name); } inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::property(quint32 index) const { if (!isObject()) - return InvalidValue(); + return new QJSValuePrivate(); return property<>(index); } @@ -777,11 +679,8 @@ inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::property(T name) con engine()->setException(result, tryCatch.Message()); return new QJSValuePrivate(engine(), result); } - if (result.IsEmpty() || (result->IsUndefined() && !self->Has(name))) { - // In QtScript we make a distinction between a property that exists and has value undefined, - // and a property that doesn't exist; in the latter case, we should return an invalid value. - return InvalidValue(); - } + if (result.IsEmpty()) + return new QJSValuePrivate(engine()); return new QJSValuePrivate(engine(), result); } @@ -836,7 +735,7 @@ inline QJSValue::PropertyFlags QJSValuePrivate::propertyFlags(v8::Handle<v8::Str inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::call(QJSValuePrivate* thisObject, const QJSValueList& args) { if (!isCallable()) - return InvalidValue(); + return new QJSValuePrivate(); v8::HandleScope handleScope; @@ -845,7 +744,7 @@ inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::call(QJSValuePrivate QVarLengthArray<v8::Handle<v8::Value>, 8> argv(argc); if (!prepareArgumentsForCall(argv.data(), args)) { qWarning("QJSValue::call() failed: cannot call function with argument created in a different engine"); - return InvalidValue(); + return new QJSValuePrivate(engine()); } return call(thisObject, argc, argv.data()); @@ -862,7 +761,7 @@ QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::call(QJSValuePrivate* thisO } else { if (!thisObject->assignEngine(e)) { qWarning("QJSValue::call() failed: cannot call function with thisObject created in a different engine"); - return InvalidValue(); + return new QJSValuePrivate(engine()); } recv = v8::Handle<v8::Object>(v8::Object::Cast(*thisObject->m_value)); @@ -913,7 +812,7 @@ inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::callAsConstructor(in inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::callAsConstructor(const QJSValueList& args) { if (!isCallable()) - return InvalidValue(); + return new QJSValuePrivate(); v8::HandleScope handleScope; @@ -922,23 +821,21 @@ inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::callAsConstructor(co QVarLengthArray<v8::Handle<v8::Value>, 8> argv(argc); if (!prepareArgumentsForCall(argv.data(), args)) { qWarning("QJSValue::callAsConstructor() failed: cannot construct function with argument created in a different engine"); - return InvalidValue(); + return new QJSValuePrivate(engine()); } return callAsConstructor(argc, argv.data()); } /*! \internal - * Make sure this value is associated with a v8 value belogning to this engine. - * If the value was invalid, or belogning to another engine, return false. + * Make sure this value is associated with a v8 value belonging to this engine. + * If the value belongs to another engine, returns false. */ bool QJSValuePrivate::assignEngine(QV8Engine* engine) { Q_ASSERT(engine); v8::HandleScope handleScope; switch (m_state) { - case Invalid: - return false; case CBool: m_value = v8::Persistent<v8::Value>::New(engine->makeJSValue(u.m_bool)); break; @@ -973,7 +870,7 @@ bool QJSValuePrivate::assignEngine(QV8Engine* engine) /*! \internal - Invalidates this value. + Invalidates this value (makes it undefined). Does not remove the value from the engine's list of registered values; that's the responsibility of the caller. @@ -987,7 +884,7 @@ void QJSValuePrivate::invalidate() delete u.m_string; } m_engine = 0; - m_state = Invalid; + m_state = CUndefined; } QV8Engine* QJSValuePrivate::engine() const @@ -1059,13 +956,10 @@ inline bool QJSValuePrivate::prepareArgumentsForCall(v8::Handle<v8::Value> argv[ for (int j = 0; i != args.constEnd(); j++, i++) { QJSValuePrivate* value = QJSValuePrivate::get(*i); if ((value->isJSBased() && engine() != value->engine()) - || (!value->isJSBased() && value->isValid() && !value->assignEngine(engine()))) + || (!value->isJSBased() && !value->assignEngine(engine()))) // Different engines are not allowed! return false; - if (value->isValid()) - argv[j] = *value; - else - argv[j] = engine()->makeJSValue(QJSValue::UndefinedValue); + argv[j] = *value; } return true; } diff --git a/src/declarative/qml/v8/qjsvalue_p.h b/src/declarative/qml/v8/qjsvalue_p.h index fd32a14bb8..02ffc8108e 100644 --- a/src/declarative/qml/v8/qjsvalue_p.h +++ b/src/declarative/qml/v8/qjsvalue_p.h @@ -59,7 +59,6 @@ class QJSValuePrivate : public QSharedData { public: - inline QJSValuePrivate(); inline static QJSValuePrivate* get(const QJSValue& q); inline static QJSValue get(const QJSValuePrivate* d); inline static QJSValue get(QJSValuePrivate* d); @@ -71,14 +70,14 @@ public: inline QJSValuePrivate(uint value); inline QJSValuePrivate(double value); inline QJSValuePrivate(const QString& value); - inline QJSValuePrivate(QJSValue::SpecialValue value); + inline QJSValuePrivate(QJSValue::SpecialValue value = QJSValue::UndefinedValue); inline QJSValuePrivate(QV8Engine *engine, bool value); inline QJSValuePrivate(QV8Engine *engine, int value); inline QJSValuePrivate(QV8Engine *engine, uint value); inline QJSValuePrivate(QV8Engine *engine, double value); inline QJSValuePrivate(QV8Engine *engine, const QString& value); - inline QJSValuePrivate(QV8Engine *engine, QJSValue::SpecialValue value); + inline QJSValuePrivate(QV8Engine *engine, QJSValue::SpecialValue value = QJSValue::UndefinedValue); inline QJSValuePrivate(QV8Engine *engine, v8::Handle<v8::Value>); inline void invalidate(); @@ -103,7 +102,6 @@ public: inline bool isObject() const; inline bool isString() const; inline bool isUndefined() const; - inline bool isValid() const; inline bool isVariant() const; inline bool isDate() const; inline bool isRegExp() const; @@ -149,7 +147,6 @@ private: // Please, update class documentation when you change the enum. enum State { - Invalid = 0, CString = 0x1000, CNumber, CBool, diff --git a/src/declarative/qml/v8/qjsvalueiterator_impl_p.h b/src/declarative/qml/v8/qjsvalueiterator_impl_p.h index e287bc175c..40814b1969 100644 --- a/src/declarative/qml/v8/qjsvalueiterator_impl_p.h +++ b/src/declarative/qml/v8/qjsvalueiterator_impl_p.h @@ -97,7 +97,7 @@ inline QString QJSValueIteratorPrivate::name() const inline QScriptPassPointer<QJSValuePrivate> QJSValueIteratorPrivate::value() const { if (!isValid()) - return InvalidValue(); + return new QJSValuePrivate(); v8::HandleScope handleScope; return m_object->property(m_names->Get(m_index - 1)->ToString()); @@ -105,7 +105,7 @@ inline QScriptPassPointer<QJSValuePrivate> QJSValueIteratorPrivate::value() cons inline bool QJSValueIteratorPrivate::isValid() const { - bool result = m_object ? m_object->isValid() : false; + bool result = m_object ? !m_object->isUndefined() : false; // We know that if this object is still valid then it is an object // if this assumption is not correct then some other logic in this class // have to be changed too. diff --git a/src/declarative/qml/v8/qv8engine.cpp b/src/declarative/qml/v8/qv8engine.cpp index 50250ffc8f..2f266a010e 100644 --- a/src/declarative/qml/v8/qv8engine.cpp +++ b/src/declarative/qml/v8/qv8engine.cpp @@ -1435,7 +1435,7 @@ QScriptPassPointer<QJSValuePrivate> QV8Engine::evaluate(v8::Handle<v8::Script> s v8::Handle<v8::Value> exception = tryCatch.Exception(); if (exception.IsEmpty()) { // This is possible on syntax errors like { a:12, b:21 } <- missing "(", ")" around expression. - return InvalidValue(); + return new QJSValuePrivate(this); } setException(exception, tryCatch.Message()); return new QJSValuePrivate(this, exception); @@ -1457,7 +1457,7 @@ QScriptPassPointer<QJSValuePrivate> QV8Engine::evaluate(v8::Handle<v8::Script> s QJSValue QV8Engine::scriptValueFromInternal(v8::Handle<v8::Value> value) const { if (value.IsEmpty()) - return QJSValuePrivate::get(InvalidValue()); + return QJSValuePrivate::get(new QJSValuePrivate(const_cast<QV8Engine*>(this))); return QJSValuePrivate::get(new QJSValuePrivate(const_cast<QV8Engine*>(this), value)); } diff --git a/src/declarative/qml/v8/qv8typewrapper.cpp b/src/declarative/qml/v8/qv8typewrapper.cpp index 9c362dbea9..0a4c390814 100644 --- a/src/declarative/qml/v8/qv8typewrapper.cpp +++ b/src/declarative/qml/v8/qv8typewrapper.cpp @@ -240,7 +240,7 @@ v8::Handle<v8::Value> QV8TypeWrapper::Getter(v8::Local<v8::String> property, // check for property. v8::Handle<v8::Value> rv = v8engine->qobjectWrapper()->getProperty(moduleApi->qobjectApi, propertystring, QV8QObjectWrapper::IgnoreRevision); return rv; - } else if (moduleApi->scriptApi.isValid()) { + } else if (!moduleApi->scriptApi.isUndefined()) { // NOTE: if used in a binding, changes will not trigger re-evaluation since non-NOTIFYable. QJSValuePrivate *apiprivate = QJSValuePrivate::get(moduleApi->scriptApi); QScopedPointer<QJSValuePrivate> propertyValue(apiprivate->property(property).give()); @@ -294,7 +294,7 @@ v8::Handle<v8::Value> QV8TypeWrapper::Setter(v8::Local<v8::String> property, if (moduleApi->qobjectApi) { v8engine->qobjectWrapper()->setProperty(moduleApi->qobjectApi, propertystring, value, QV8QObjectWrapper::IgnoreRevision); - } else if (moduleApi->scriptApi.isValid()) { + } else if (!moduleApi->scriptApi.isUndefined()) { QScopedPointer<QJSValuePrivate> setvalp(new QJSValuePrivate(v8engine, value)); QJSValuePrivate *apiprivate = QJSValuePrivate::get(moduleApi->scriptApi); if (apiprivate->propertyFlags(property) & QJSValue::ReadOnly) { 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()); } |