Skip to content

Commit

Permalink
Remove QJSEngine::undefinedValue() function
Browse files Browse the repository at this point in the history
Rationale: It's strange to have an undefined value factory function.
There should just be one way of constructing undefined values: By
passing UndefinedValue to the QJSValue constructor.

The undefinedValue() function created a value that was bound to the
engine; the QJSValue constructor does not. In order to ensure that
we're testing the same behavior as before, I've replaced
undefinedValue() calls by toScriptValue(QVariant()) in the autotests.

Task-number: QTBUG-23604
Change-Id: Ie9295b7af49c853b5a4a3445da48c325fef8d6b1
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
  • Loading branch information
Kent Hansen authored and Qt by Nokia committed Feb 2, 2012
1 parent fe6173c commit 52b77f9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 53 deletions.
17 changes: 0 additions & 17 deletions src/declarative/qml/v8/qjsengine.cpp
Expand Up @@ -309,23 +309,6 @@ QJSValue QJSEngine::evaluate(const QString& program, const QString& fileName, in
return QJSValuePrivate::get(d->evaluate(program, fileName, lineNumber));
}

#ifdef QT_DEPRECATED

/*!
\obsolete
Returns a QJSValue of the primitive type Undefined.
*/
QJSValue QJSEngine::undefinedValue()
{
Q_D(QJSEngine);
QScriptIsolate api(d, QScriptIsolate::NotNullEngine);
v8::HandleScope handleScope;
return QJSValuePrivate::get(new QJSValuePrivate(d, v8::Undefined()));
}

#endif // QT_DEPRECATED

/*!
Creates a JavaScript object of class Object.
Expand Down
2 changes: 0 additions & 2 deletions src/declarative/qml/v8/qjsengine.h
Expand Up @@ -87,8 +87,6 @@ class Q_DECLARATIVE_EXPORT QJSEngine
QT_DEPRECATED bool hasUncaughtException() const;
QT_DEPRECATED QJSValue uncaughtException() const;
QT_DEPRECATED void clearExceptions();

QT_DEPRECATED QJSValue undefinedValue();
#endif

Q_SIGNALS:
Expand Down
2 changes: 0 additions & 2 deletions src/declarative/qml/v8/qjsvalue.cpp
Expand Up @@ -261,8 +261,6 @@ bool QJSValue::isString() const
/*!
Returns true if this QJSValue is of the primitive type Undefined;
otherwise returns false.
\sa QJSEngine::undefinedValue()
*/
bool QJSValue::isUndefined() const
{
Expand Down
64 changes: 32 additions & 32 deletions tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
Expand Up @@ -71,7 +71,7 @@ void tst_QJSValue::ctor_undefinedWithEngine()
{
QJSEngine eng;
{
QJSValue v = eng.evaluate("undefined");
QJSValue v = eng.toScriptValue(QVariant());
QVERIFY(v.isUndefined());
QCOMPARE(v.isObject(), false);
QCOMPARE(v.engine(), &eng);
Expand Down Expand Up @@ -327,7 +327,7 @@ void tst_QJSValue::toString()
{
QJSEngine eng;

QJSValue undefined = eng.undefinedValue();
QJSValue undefined = eng.toScriptValue(QVariant());
QCOMPARE(undefined.toString(), QString("undefined"));
QCOMPARE(qjsvalue_cast<QString>(undefined), QString());

Expand Down Expand Up @@ -439,7 +439,7 @@ void tst_QJSValue::toNumber()
{
QJSEngine eng;

QJSValue undefined = eng.undefinedValue();
QJSValue undefined = eng.toScriptValue(QVariant());
QCOMPARE(qIsNaN(undefined.toNumber()), true);
QCOMPARE(qIsNaN(qjsvalue_cast<qreal>(undefined)), true);

Expand Down Expand Up @@ -515,7 +515,7 @@ void tst_QJSValue::toBoolean() // deprecated
{
QJSEngine eng;

QJSValue undefined = eng.undefinedValue();
QJSValue undefined = eng.toScriptValue(QVariant());
QCOMPARE(undefined.toBool(), false);
QCOMPARE(qjsvalue_cast<bool>(undefined), false);

Expand Down Expand Up @@ -615,7 +615,7 @@ void tst_QJSValue::toBool()
{
QJSEngine eng;

QJSValue undefined = eng.undefinedValue();
QJSValue undefined = eng.toScriptValue(QVariant());
QCOMPARE(undefined.toBool(), false);
QCOMPARE(qjsvalue_cast<bool>(undefined), false);

Expand Down Expand Up @@ -987,7 +987,7 @@ void tst_QJSValue::toVariant()
{
QJSEngine eng;

QJSValue undefined = eng.undefinedValue();
QJSValue undefined = eng.toScriptValue(QVariant());
QCOMPARE(undefined.toVariant(), QVariant());
QCOMPARE(qjsvalue_cast<QVariant>(undefined), QVariant());

Expand Down Expand Up @@ -1106,7 +1106,7 @@ void tst_QJSValue::toQObject_nonQObject_data()
QTest::newRow("bool bound(true)") << engine->toScriptValue(true);
QTest::newRow("int bound") << engine->toScriptValue(123);
QTest::newRow("string bound") << engine->toScriptValue(QString::fromLatin1("ciao"));
QTest::newRow("undefined bound") << engine->undefinedValue();
QTest::newRow("undefined bound") << engine->toScriptValue(QVariant());
QTest::newRow("null bound") << engine->evaluate("null");
QTest::newRow("object") << engine->newObject();
QTest::newRow("array") << engine->newArray();
Expand Down Expand Up @@ -1165,7 +1165,7 @@ void tst_QJSValue::toDateTime()
QVERIFY(!QJSValue(123).toDateTime().isValid());
QVERIFY(!QJSValue(false).toDateTime().isValid());
QVERIFY(!eng.evaluate("null").toDateTime().isValid());
QVERIFY(!eng.undefinedValue().toDateTime().isValid());
QVERIFY(!eng.toScriptValue(QVariant()).toDateTime().isValid());
}

void tst_QJSValue::toRegExp()
Expand Down Expand Up @@ -1195,7 +1195,7 @@ void tst_QJSValue::toRegExp()
QVERIFY(qjsvalue_cast<QRegExp>(QJSValue(123)).isEmpty());
QVERIFY(qjsvalue_cast<QRegExp>(QJSValue(false)).isEmpty());
QVERIFY(qjsvalue_cast<QRegExp>(eng.evaluate("null")).isEmpty());
QVERIFY(qjsvalue_cast<QRegExp>(eng.undefinedValue()).isEmpty());
QVERIFY(qjsvalue_cast<QRegExp>(eng.toScriptValue(QVariant())).isEmpty());
}

void tst_QJSValue::isArray_data()
Expand All @@ -1212,7 +1212,7 @@ void tst_QJSValue::isArray_data()
QTest::newRow("number") << QJSValue(123) << false;
QTest::newRow("bool") << QJSValue(false) << false;
QTest::newRow("null") << engine->evaluate("null") << false;
QTest::newRow("undefined") << engine->undefinedValue() << false;
QTest::newRow("undefined") << engine->toScriptValue(QVariant()) << false;
}

void tst_QJSValue::isArray()
Expand All @@ -1238,7 +1238,7 @@ void tst_QJSValue::isDate_data()
QTest::newRow("number") << QJSValue(123) << false;
QTest::newRow("bool") << QJSValue(false) << false;
QTest::newRow("null") << engine->evaluate("null") << false;
QTest::newRow("undefined") << engine->undefinedValue() << false;
QTest::newRow("undefined") << engine->toScriptValue(QVariant()) << false;
}

void tst_QJSValue::isDate()
Expand Down Expand Up @@ -1282,7 +1282,7 @@ void tst_QJSValue::isError_data()
QTest::newRow("number") << QJSValue(123) << false;
QTest::newRow("bool") << QJSValue(false) << false;
QTest::newRow("null") << engine->evaluate("null") << false;
QTest::newRow("undefined") << engine->undefinedValue() << false;
QTest::newRow("undefined") << engine->toScriptValue(QVariant()) << false;
QTest::newRow("newObject") << engine->newObject() << false;
QTest::newRow("new Object") << engine->evaluate("new Object()") << false;
}
Expand Down Expand Up @@ -1310,7 +1310,7 @@ void tst_QJSValue::isRegExp_data()
QTest::newRow("number") << QJSValue(123) << false;
QTest::newRow("bool") << QJSValue(false) << false;
QTest::newRow("null") << engine->evaluate("null") << false;
QTest::newRow("undefined") << engine->undefinedValue() << false;
QTest::newRow("undefined") << engine->toScriptValue(QVariant()) << false;
}

void tst_QJSValue::isRegExp()
Expand Down Expand Up @@ -2114,7 +2114,7 @@ void tst_QJSValue::getSetPrototype_notObjectOrNull()
// undefined
object.setPrototype(QJSValue(QJSValue::UndefinedValue));
QVERIFY(object.prototype().equals(originalProto));
object.setPrototype(eng.evaluate("undefined"));
object.setPrototype(eng.toScriptValue(QVariant()));
QVERIFY(object.prototype().equals(originalProto));
}

Expand Down Expand Up @@ -2207,7 +2207,7 @@ void tst_QJSValue::getSetData_nonObjects_data()

QTest::addColumn<QJSValue>("value");

QTest::newRow("undefined (bound)") << engine->undefinedValue();
QTest::newRow("undefined (bound)") << engine->toScriptValue(QVariant());
QTest::newRow("null (bound)") << engine->evaluate("null");
QTest::newRow("string (bound)") << engine->toScriptValue("Pong");
QTest::newRow("bool (bound)") << engine->toScriptValue(false);
Expand Down Expand Up @@ -2278,7 +2278,7 @@ void tst_QJSValue::getSetScriptClass_emptyClass_data()
QTest::newRow("string") << engine->toScriptValue("pong");
QTest::newRow("bool") << engine->toScriptValue(true);
QTest::newRow("null") << QJSValue(engine->evaluate("null"));
QTest::newRow("undefined") << QJSValue(engine->undefinedValue());
QTest::newRow("undefined") << QJSValue(engine->toScriptValue(QVariant()));
QTest::newRow("object") << QJSValue(engine->newObject());
QTest::newRow("date") << QJSValue(engine->evaluate("new Date()"));
QTest::newRow("qobject") << QJSValue(engine->newQObject(this));
Expand Down Expand Up @@ -2429,29 +2429,29 @@ void tst_QJSValue::call_arguments()
QJSValue fun = eng.evaluate("(function() { return arguments[0]; })");
QCOMPARE(fun.isCallable(), true);
{
QJSValue result = fun.callWithInstance(eng.undefinedValue());
QJSValue result = fun.callWithInstance(eng.toScriptValue(QVariant()));
QCOMPARE(result.isUndefined(), true);
}
{
QJSValueList args;
args << eng.toScriptValue(123.0);
QJSValue result = fun.callWithInstance(eng.undefinedValue(), args);
QJSValue result = fun.callWithInstance(eng.toScriptValue(QVariant()), args);
QCOMPARE(result.isNumber(), true);
QCOMPARE(result.toNumber(), 123.0);
}
// V2 constructors
{
QJSValueList args;
args << QJSValue(123.0);
QJSValue result = fun.callWithInstance(eng.undefinedValue(), args);
QJSValue result = fun.callWithInstance(eng.toScriptValue(QVariant()), args);
QCOMPARE(result.isNumber(), true);
QCOMPARE(result.toNumber(), 123.0);
}
#if 0 // FIXME: The feature of interpreting a passed array as argument list has been removed from the API
{
QJSValue args = eng.newArray();
args.setProperty(0, 123);
QJSValue result = fun.callWithInstance(eng.undefinedValue(), args);
QJSValue result = fun.callWithInstance(eng.toScriptValue(QVariant()), args);
QVERIFY(result.isNumber());
QCOMPARE(result.toNumber(), 123.0);
}
Expand All @@ -2468,7 +2468,7 @@ void tst_QJSValue::call()
{
QJSValueList args;
args << eng.toScriptValue(123.0) << eng.toScriptValue(456.0);
QJSValue result = fun.callWithInstance(eng.undefinedValue(), args);
QJSValue result = fun.callWithInstance(eng.toScriptValue(QVariant()), args);
QCOMPARE(result.isNumber(), true);
QCOMPARE(result.toNumber(), 456.0);
}
Expand All @@ -2477,7 +2477,7 @@ void tst_QJSValue::call()
QJSValue args = eng.newArray();
args.setProperty(0, 123);
args.setProperty(1, 456);
QJSValue result = fun.callWithInstance(eng.undefinedValue(), args);
QJSValue result = fun.callWithInstance(eng.toScriptValue(QVariant()), args);
QVERIFY(result.isNumber());
QCOMPARE(result.toNumber(), 456.0);
}
Expand All @@ -2502,7 +2502,7 @@ void tst_QJSValue::call()
{
QJSValueList args;
args << eng.toScriptValue(123.0);
QJSValue result = fun.callWithInstance(eng.undefinedValue(), args);
QJSValue result = fun.callWithInstance(eng.toScriptValue(QVariant()), args);
QVERIFY(!eng.hasUncaughtException());
QCOMPARE(result.isNumber(), true);
QCOMPARE(result.toNumber(), 123.0);
Expand All @@ -2511,15 +2511,15 @@ void tst_QJSValue::call()
{
QJSValueList args;
args << QJSValue(123.0);
QJSValue result = fun.callWithInstance(eng.undefinedValue(), args);
QJSValue result = fun.callWithInstance(eng.toScriptValue(QVariant()), args);
QCOMPARE(result.isNumber(), true);
QCOMPARE(result.toNumber(), 123.0);
}
#if 0 // FIXME: The feature of interpreting a passed array as argument list has been removed from the API
{
QJSValue args = eng.newArray();
args.setProperty(0, 123);
QJSValue result = fun.callWithInstance(eng.undefinedValue(), args);
QJSValue result = fun.callWithInstance(eng.toScriptValue(QVariant()), args);
QVERIFY(result.isNumber());
QCOMPARE(result.toNumber(), 123.0);
}
Expand All @@ -2530,7 +2530,7 @@ void tst_QJSValue::call()
{
QJSValueList args;
args << eng.toScriptValue(123.0);
QJSValue result = fun.callWithInstance(eng.undefinedValue(), args);
QJSValue result = fun.callWithInstance(eng.toScriptValue(QVariant()), args);
QVERIFY(!eng.hasUncaughtException());
QCOMPARE(result.isNumber(), true);
QCOMPARE(result.toNumber(), 123.0);
Expand Down Expand Up @@ -2648,7 +2648,7 @@ void tst_QJSValue::call_array()
QCOMPARE(ret3.property("length").isNumber(), true);
QCOMPARE(ret3.property("length").toNumber(), 0.0);
// call with undefined as arguments
QJSValue ret4 = fun.call(QJSValue(), eng.undefinedValue());
QJSValue ret4 = fun.call(QJSValue(), eng.toScriptValue(QVariant()));
QCOMPARE(ret4.isError(), false);
QCOMPARE(ret4.property("length").isNumber(), true);
QCOMPARE(ret4.property("length").toNumber(), 0.0);
Expand Down Expand Up @@ -2678,7 +2678,7 @@ void tst_QJSValue::call_nonFunction_data()
QTest::newRow("bool bound") << engine->toScriptValue(false);
QTest::newRow("int bound") << engine->toScriptValue(123);
QTest::newRow("string bound") << engine->toScriptValue(QString::fromLatin1("ciao"));
QTest::newRow("undefined bound") << engine->undefinedValue();
QTest::newRow("undefined bound") << engine->toScriptValue(QVariant());
QTest::newRow("null bound") << engine->evaluate("null");
}

Expand Down Expand Up @@ -2719,7 +2719,7 @@ void tst_QJSValue::construct_nonFunction_data()
QTest::newRow("bool bound") << engine->toScriptValue(false);
QTest::newRow("int bound") << engine->toScriptValue(123);
QTest::newRow("string bound") << engine->toScriptValue(QString::fromLatin1("ciao"));
QTest::newRow("undefined bound") << engine->undefinedValue();
QTest::newRow("undefined bound") << engine->toScriptValue(QVariant());
QTest::newRow("null bound") << engine->evaluate("null");
}

Expand Down Expand Up @@ -2847,7 +2847,7 @@ void tst_QJSValue::construct()
QCOMPARE(ret3.property("length").isNumber(), true);
QCOMPARE(ret3.property("length").toNumber(), 0.0);
// construct with undefined as arguments
QJSValue ret4 = fun.callAsConstructor(eng.undefinedValue());
QJSValue ret4 = fun.callAsConstructor(eng.toScriptValue(QVariant()));
QCOMPARE(ret4.isError(), false);
QCOMPARE(ret4.property("length").isNumber(), true);
QCOMPARE(ret4.property("length").toNumber(), 0.0);
Expand Down Expand Up @@ -3046,7 +3046,7 @@ void tst_QJSValue::equals()
QCOMPARE(date1.equals(date1), true);
QCOMPARE(date2.equals(date2), true);

QJSValue undefined = eng.undefinedValue();
QJSValue undefined = eng.toScriptValue(QVariant());
QJSValue null = eng.evaluate("null");
QCOMPARE(undefined.equals(undefined), true);
QCOMPARE(null.equals(null), true);
Expand Down Expand Up @@ -3186,7 +3186,7 @@ void tst_QJSValue::strictlyEquals()
QCOMPARE(date2.strictlyEquals(date2), true);
QVERIFY(!date1.strictlyEquals(QJSValue()));

QJSValue undefined = eng.undefinedValue();
QJSValue undefined = eng.toScriptValue(QVariant());
QJSValue null = eng.evaluate("null");
QCOMPARE(undefined.strictlyEquals(undefined), true);
QCOMPARE(null.strictlyEquals(null), true);
Expand Down

0 comments on commit 52b77f9

Please sign in to comment.