From: Kent Hansen Date: Wed, 18 Jan 2012 05:53:39 +0000 (+0100) Subject: Remove QJSEngine::nullValue() function X-Git-Tag: qt-v5.0.0-alpha1~526 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fd7fce388e31174a5179d92b56911d974bf11024;p=profile%2Fivi%2Fqtdeclarative.git Remove QJSEngine::nullValue() function Rationale: It's strange to have a null value factory function. There should just be one way of constructing null values: By passing NullValue to the QJSValue constructor. The nullValue() 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 nullValue() calls by evaluate("null") in the autotests. Task-number: QTBUG-23604 Change-Id: Ie40b61fa64e070b90c6245fd21554963073c5f80 Reviewed-by: Jędrzej Nowacki --- diff --git a/src/declarative/qml/v8/qjsengine.cpp b/src/declarative/qml/v8/qjsengine.cpp index 542c20d..b818c18 100644 --- a/src/declarative/qml/v8/qjsengine.cpp +++ b/src/declarative/qml/v8/qjsengine.cpp @@ -314,24 +314,7 @@ QJSValue QJSEngine::evaluate(const QString& program, const QString& fileName, in /*! \obsolete - Returns a QJSValue of the primitive type Null. - - \sa nullValue() -*/ -QJSValue QJSEngine::nullValue() -{ - Q_D(QJSEngine); - QScriptIsolate api(d, QScriptIsolate::NotNullEngine); - v8::HandleScope handleScope; - return QJSValuePrivate::get(new QJSValuePrivate(d, v8::Null())); -} - -/*! - \obsolete - Returns a QJSValue of the primitive type Undefined. - - \sa nullValue() */ QJSValue QJSEngine::undefinedValue() { @@ -380,7 +363,7 @@ QJSValue QJSEngine::newArray(uint length) Signals and slots, properties and children of \a object are available as properties of the created QJSValue. - If \a object is a null pointer, this function returns nullValue(). + If \a object is a null pointer, this function returns a null value. If a default prototype has been registered for the \a object's class (or its superclass, recursively), the prototype of the new script diff --git a/src/declarative/qml/v8/qjsengine.h b/src/declarative/qml/v8/qjsengine.h index f243fda..558d5ed 100644 --- a/src/declarative/qml/v8/qjsengine.h +++ b/src/declarative/qml/v8/qjsengine.h @@ -88,7 +88,6 @@ public: QT_DEPRECATED QJSValue uncaughtException() const; QT_DEPRECATED void clearExceptions(); - QT_DEPRECATED QJSValue nullValue(); QT_DEPRECATED QJSValue undefinedValue(); #endif diff --git a/src/declarative/qml/v8/qjsvalue.cpp b/src/declarative/qml/v8/qjsvalue.cpp index ce0d122..302c768 100644 --- a/src/declarative/qml/v8/qjsvalue.cpp +++ b/src/declarative/qml/v8/qjsvalue.cpp @@ -237,8 +237,6 @@ bool QJSValue::isNumber() const /*! Returns true if this QJSValue is of the primitive type Null; otherwise returns false. - - \sa QJSEngine::nullValue() */ bool QJSValue::isNull() const { diff --git a/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp b/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp index 55ab2c1..cd8680a 100644 --- a/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp +++ b/tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp @@ -331,7 +331,7 @@ void tst_QJSValue::toString() QCOMPARE(undefined.toString(), QString("undefined")); QCOMPARE(qjsvalue_cast(undefined), QString()); - QJSValue null = eng.nullValue(); + QJSValue null = eng.evaluate("null"); QCOMPARE(null.toString(), QString("null")); QCOMPARE(qjsvalue_cast(null), QString()); @@ -443,7 +443,7 @@ void tst_QJSValue::toNumber() QCOMPARE(qIsNaN(undefined.toNumber()), true); QCOMPARE(qIsNaN(qjsvalue_cast(undefined)), true); - QJSValue null = eng.nullValue(); + QJSValue null = eng.evaluate("null"); QCOMPARE(null.toNumber(), 0.0); QCOMPARE(qjsvalue_cast(null), 0.0); @@ -519,7 +519,7 @@ void tst_QJSValue::toBoolean() // deprecated QCOMPARE(undefined.toBool(), false); QCOMPARE(qjsvalue_cast(undefined), false); - QJSValue null = eng.nullValue(); + QJSValue null = eng.evaluate("null"); QCOMPARE(null.toBool(), false); QCOMPARE(qjsvalue_cast(null), false); @@ -619,7 +619,7 @@ void tst_QJSValue::toBool() QCOMPARE(undefined.toBool(), false); QCOMPARE(qjsvalue_cast(undefined), false); - QJSValue null = eng.nullValue(); + QJSValue null = eng.evaluate("null"); QCOMPARE(null.toBool(), false); QCOMPARE(qjsvalue_cast(null), false); @@ -991,7 +991,7 @@ void tst_QJSValue::toVariant() QCOMPARE(undefined.toVariant(), QVariant()); QCOMPARE(qjsvalue_cast(undefined), QVariant()); - QJSValue null = eng.nullValue(); + QJSValue null = eng.evaluate("null"); QCOMPARE(null.toVariant(), QVariant()); QCOMPARE(qjsvalue_cast(null), QVariant()); @@ -1107,7 +1107,7 @@ void tst_QJSValue::toQObject_nonQObject_data() QTest::newRow("int bound") << engine->toScriptValue(123); QTest::newRow("string bound") << engine->toScriptValue(QString::fromLatin1("ciao")); QTest::newRow("undefined bound") << engine->undefinedValue(); - QTest::newRow("null bound") << engine->nullValue(); + QTest::newRow("null bound") << engine->evaluate("null"); QTest::newRow("object") << engine->newObject(); QTest::newRow("array") << engine->newArray(); QTest::newRow("date") << engine->evaluate("new Date(124)"); @@ -1164,7 +1164,7 @@ void tst_QJSValue::toDateTime() QVERIFY(!QJSValue().toDateTime().isValid()); QVERIFY(!QJSValue(123).toDateTime().isValid()); QVERIFY(!QJSValue(false).toDateTime().isValid()); - QVERIFY(!eng.nullValue().toDateTime().isValid()); + QVERIFY(!eng.evaluate("null").toDateTime().isValid()); QVERIFY(!eng.undefinedValue().toDateTime().isValid()); } @@ -1194,7 +1194,7 @@ void tst_QJSValue::toRegExp() QVERIFY(qjsvalue_cast(QJSValue()).isEmpty()); QVERIFY(qjsvalue_cast(QJSValue(123)).isEmpty()); QVERIFY(qjsvalue_cast(QJSValue(false)).isEmpty()); - QVERIFY(qjsvalue_cast(eng.nullValue()).isEmpty()); + QVERIFY(qjsvalue_cast(eng.evaluate("null")).isEmpty()); QVERIFY(qjsvalue_cast(eng.undefinedValue()).isEmpty()); } @@ -1211,7 +1211,7 @@ void tst_QJSValue::isArray_data() QTest::newRow("invalid") << QJSValue() << false; QTest::newRow("number") << QJSValue(123) << false; QTest::newRow("bool") << QJSValue(false) << false; - QTest::newRow("null") << engine->nullValue() << false; + QTest::newRow("null") << engine->evaluate("null") << false; QTest::newRow("undefined") << engine->undefinedValue() << false; } @@ -1237,7 +1237,7 @@ void tst_QJSValue::isDate_data() QTest::newRow("invalid") << QJSValue() << false; QTest::newRow("number") << QJSValue(123) << false; QTest::newRow("bool") << QJSValue(false) << false; - QTest::newRow("null") << engine->nullValue() << false; + QTest::newRow("null") << engine->evaluate("null") << false; QTest::newRow("undefined") << engine->undefinedValue() << false; } @@ -1281,7 +1281,7 @@ void tst_QJSValue::isError_data() QTest::newRow("invalid") << QJSValue() << false; QTest::newRow("number") << QJSValue(123) << false; QTest::newRow("bool") << QJSValue(false) << false; - QTest::newRow("null") << engine->nullValue() << false; + QTest::newRow("null") << engine->evaluate("null") << false; QTest::newRow("undefined") << engine->undefinedValue() << false; QTest::newRow("newObject") << engine->newObject() << false; QTest::newRow("new Object") << engine->evaluate("new Object()") << false; @@ -1309,7 +1309,7 @@ void tst_QJSValue::isRegExp_data() QTest::newRow("invalid") << QJSValue() << false; QTest::newRow("number") << QJSValue(123) << false; QTest::newRow("bool") << QJSValue(false) << false; - QTest::newRow("null") << engine->nullValue() << false; + QTest::newRow("null") << engine->evaluate("null") << false; QTest::newRow("undefined") << engine->undefinedValue() << false; } @@ -2208,7 +2208,7 @@ void tst_QJSValue::getSetData_nonObjects_data() QTest::addColumn("value"); QTest::newRow("undefined (bound)") << engine->undefinedValue(); - QTest::newRow("null (bound)") << engine->nullValue(); + QTest::newRow("null (bound)") << engine->evaluate("null"); QTest::newRow("string (bound)") << engine->toScriptValue("Pong"); QTest::newRow("bool (bound)") << engine->toScriptValue(false); @@ -2277,7 +2277,7 @@ void tst_QJSValue::getSetScriptClass_emptyClass_data() QTest::newRow("number") << engine->toScriptValue(123); QTest::newRow("string") << engine->toScriptValue("pong"); QTest::newRow("bool") << engine->toScriptValue(true); - QTest::newRow("null") << QJSValue(engine->nullValue()); + QTest::newRow("null") << QJSValue(engine->evaluate("null")); QTest::newRow("undefined") << QJSValue(engine->undefinedValue()); QTest::newRow("object") << QJSValue(engine->newObject()); QTest::newRow("date") << QJSValue(engine->evaluate("new Date()")); @@ -2643,7 +2643,7 @@ void tst_QJSValue::call_array() QCOMPARE(ret2.property(1).strictlyEquals(ret.property(1)), true); QCOMPARE(ret2.property(2).strictlyEquals(ret.property(2)), true); // call with null as arguments - QJSValue ret3 = fun.call(QJSValue(), eng.nullValue()); + QJSValue ret3 = fun.call(QJSValue(), eng.evaluate("null")); QCOMPARE(ret3.isError(), false); QCOMPARE(ret3.property("length").isNumber(), true); QCOMPARE(ret3.property("length").toNumber(), 0.0); @@ -2679,7 +2679,7 @@ void tst_QJSValue::call_nonFunction_data() QTest::newRow("int bound") << engine->toScriptValue(123); QTest::newRow("string bound") << engine->toScriptValue(QString::fromLatin1("ciao")); QTest::newRow("undefined bound") << engine->undefinedValue(); - QTest::newRow("null bound") << engine->nullValue(); + QTest::newRow("null bound") << engine->evaluate("null"); } void tst_QJSValue::call_nonFunction() @@ -2720,7 +2720,7 @@ void tst_QJSValue::construct_nonFunction_data() QTest::newRow("int bound") << engine->toScriptValue(123); QTest::newRow("string bound") << engine->toScriptValue(QString::fromLatin1("ciao")); QTest::newRow("undefined bound") << engine->undefinedValue(); - QTest::newRow("null bound") << engine->nullValue(); + QTest::newRow("null bound") << engine->evaluate("null"); } void tst_QJSValue::construct_nonFunction() @@ -2842,7 +2842,7 @@ void tst_QJSValue::construct() QCOMPARE(ret2.property(1).strictlyEquals(ret.property(1)), true); QCOMPARE(ret2.property(2).strictlyEquals(ret.property(2)), true); // construct with null as arguments - QJSValue ret3 = fun.callAsConstructor(eng.nullValue()); + QJSValue ret3 = fun.callAsConstructor(eng.evaluate("null"); QCOMPARE(ret3.isError(), false); QCOMPARE(ret3.property("length").isNumber(), true); QCOMPARE(ret3.property("length").toNumber(), 0.0); @@ -3047,7 +3047,7 @@ void tst_QJSValue::equals() QCOMPARE(date2.equals(date2), true); QJSValue undefined = eng.undefinedValue(); - QJSValue null = eng.nullValue(); + QJSValue null = eng.evaluate("null"); QCOMPARE(undefined.equals(undefined), true); QCOMPARE(null.equals(null), true); QCOMPARE(undefined.equals(null), true); @@ -3187,7 +3187,7 @@ void tst_QJSValue::strictlyEquals() QVERIFY(!date1.strictlyEquals(QJSValue())); QJSValue undefined = eng.undefinedValue(); - QJSValue null = eng.nullValue(); + QJSValue null = eng.evaluate("null"); QCOMPARE(undefined.strictlyEquals(undefined), true); QCOMPARE(null.strictlyEquals(null), true); QCOMPARE(undefined.strictlyEquals(null), false);