Skip to content

Commit

Permalink
Remove QJSEngine::toObject() and QJSValue::toObject()
Browse files Browse the repository at this point in the history
Rationale: There is no compelling usecase for these functions.
They are a remnant from QtScript.

Task-number: QTBUG-23604
Change-Id: I6d8b4299956dd8f6284934739c4f1a65e4deb64c
Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
  • Loading branch information
Kent Hansen authored and Qt by Nokia committed Feb 1, 2012
1 parent 6a84390 commit 1edcf64
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 322 deletions.
27 changes: 0 additions & 27 deletions src/declarative/qml/v8/qjsengine.cpp
Expand Up @@ -447,33 +447,6 @@ QJSValue QJSEngine::globalObject() const

#ifdef QT_DEPRECATED

/*!
\obsolete
Converts the given \a value to an object, if such a conversion is
possible; otherwise returns an invalid QJSValue. The conversion
is performed according to the following table:
\table
\header \o Input Type \o Result
\row \o Undefined \o An invalid QJSValue.
\row \o Null \o An invalid QJSValue.
\row \o Boolean \o A new Boolean object whose internal value is set to the value of the boolean.
\row \o Number \o A new Number object whose internal value is set to the value of the number.
\row \o String \o A new String object whose internal value is set to the value of the string.
\row \o Object \o The result is the object itself (no conversion).
\endtable
\sa newObject()
*/
QJSValue QJSEngine::toObject(const QJSValue& value)
{
Q_D(QJSEngine);
QScriptIsolate api(d, QScriptIsolate::NotNullEngine);
v8::HandleScope handleScope;
return QJSValuePrivate::get(QJSValuePrivate::get(value)->toObject(d));
}

/*!
\obsolete
Expand Down
2 changes: 0 additions & 2 deletions src/declarative/qml/v8/qjsengine.h
Expand Up @@ -101,8 +101,6 @@ class Q_DECLARATIVE_EXPORT QJSEngine
QT_DEPRECATED QJSValue newRegExp(const QString &pattern, const QString &flags);
QT_DEPRECATED QJSValue newDate(double value);
QT_DEPRECATED QJSValue newDate(const QDateTime &value);

QT_DEPRECATED QJSValue toObject(const QJSValue &value);
#endif

Q_SIGNALS:
Expand Down
14 changes: 1 addition & 13 deletions src/declarative/qml/v8/qjsvalue.cpp
Expand Up @@ -461,7 +461,7 @@ bool QJSValue::isArray() const
Note that function values, variant values, and QObject values are
objects, so this function returns true for such values.
\sa toObject(), QJSEngine::newObject()
\sa QJSEngine::newObject()
*/
bool QJSValue::isObject() const
{
Expand Down Expand Up @@ -677,18 +677,6 @@ quint16 QJSValue::toUInt16() const
return d->toUInt16();
}

/*!
\obsolete
This function is obsolete; use QJSEngine::toObject() instead.
*/
QJSValue QJSValue::toObject() const
{
Q_D(const QJSValue);
QScriptIsolate api(d->engine());
return QJSValuePrivate::get(d->toObject());
}

#endif // QT_DEPRECATED

/*!
Expand Down
1 change: 0 additions & 1 deletion src/declarative/qml/v8/qjsvalue.h
Expand Up @@ -144,7 +144,6 @@ class Q_DECLARATIVE_EXPORT QJSValue
QT_DEPRECATED qint32 toInt32() const;
QT_DEPRECATED quint32 toUInt32() const;
QT_DEPRECATED quint16 toUInt16() const;
QT_DEPRECATED QJSValue toObject() const;
QT_DEPRECATED QRegExp toRegExp() const;

QT_DEPRECATED bool instanceOf(const QJSValue &other) const;
Expand Down
45 changes: 0 additions & 45 deletions src/declarative/qml/v8/qjsvalue_impl_p.h
Expand Up @@ -256,51 +256,6 @@ double QJSValuePrivate::toNumber() const
return 0; // Avoid compiler warning.
}

QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::toObject(QV8Engine* engine) const
{
Q_ASSERT(engine);
if (this->engine() && engine != this->engine()) {
qWarning("QJSEngine::toObject: cannot convert value created in a different engine");
return InvalidValue();
}

v8::HandleScope scope;
switch (m_state) {
case Invalid:
case CNull:
case CUndefined:
return new QJSValuePrivate;
case CString:
return new QJSValuePrivate(engine, engine->makeJSValue(*u.m_string)->ToObject());
case CNumber:
return new QJSValuePrivate(engine, engine->makeJSValue(u.m_number)->ToObject());
case CBool:
return new QJSValuePrivate(engine, engine->makeJSValue(u.m_bool)->ToObject());
case JSValue:
if (m_value->IsObject())
return const_cast<QJSValuePrivate*>(this);
if (m_value->IsNull() || m_value->IsUndefined()) // avoid "Uncaught TypeError: Cannot convert null to object"
return InvalidValue();
return new QJSValuePrivate(engine, m_value->ToObject());
default:
Q_ASSERT_X(false, Q_FUNC_INFO, "Not all states are included in this switch");
return InvalidValue();
}
}

/*!
This method is created only for QJSValue::toObject() purpose which is obsolete.
\internal
*/
QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::toObject() const
{
if (isJSBased())
return toObject(engine());

// Without an engine there is not much we can do.
return new QJSValuePrivate;
}

QString QJSValuePrivate::toString() const
{
switch (m_state) {
Expand Down
2 changes: 0 additions & 2 deletions src/declarative/qml/v8/qjsvalue_p.h
Expand Up @@ -84,8 +84,6 @@ class QJSValuePrivate

inline bool toBool() const;
inline double toNumber() const;
inline QScriptPassPointer<QJSValuePrivate> toObject() const;
inline QScriptPassPointer<QJSValuePrivate> toObject(QV8Engine *engine) const;
inline QString toString() const;
inline double toInteger() const;
inline qint32 toInt32() const;
Expand Down
83 changes: 1 addition & 82 deletions tests/auto/declarative/qjsengine/tst_qjsengine.cpp
Expand Up @@ -235,7 +235,6 @@ private slots:
#endif
void jsContinueInSwitch();
void jsShadowReadOnlyPrototypeProperty();
void toObject();
void jsReservedWords_data();
void jsReservedWords();
void jsFutureReservedWords_data();
Expand Down Expand Up @@ -4366,7 +4365,7 @@ void tst_QJSEngine::stringObjects()
QString str("ciao");
// in C++
{
QJSValue obj = QJSValue(&eng, str).toObject();
QJSValue obj = eng.evaluate(QString::fromLatin1("new String('%0')").arg(str));
QCOMPARE(obj.property("length").toInt(), str.length());
QCOMPARE(obj.propertyFlags("length"), QJSValue::PropertyFlags(QJSValue::Undeletable | QJSValue::SkipInEnumeration | QJSValue::ReadOnly));
for (int i = 0; i < str.length(); ++i) {
Expand All @@ -4390,7 +4389,6 @@ void tst_QJSEngine::stringObjects()
QVERIFY(obj.property("100").strictlyEquals(val));
}

// in script
{
QJSValue ret = eng.evaluate("s = new String('ciao'); r = []; for (var p in s) r.push(p); r");
QVERIFY(ret.isArray());
Expand Down Expand Up @@ -4677,85 +4675,6 @@ void tst_QJSEngine::jsShadowReadOnlyPrototypeProperty()
QVERIFY(eng.evaluate("o.hasOwnProperty('length')").toBool());
}

void tst_QJSEngine::toObject()
{
QJSEngine eng;

QVERIFY(!eng.toObject(eng.undefinedValue()).isValid());

QVERIFY(!eng.toObject(eng.nullValue()).isValid());

QJSValue falskt(false);
{
QJSValue tmp = eng.toObject(falskt);
QVERIFY(tmp.isObject());
QCOMPARE(tmp.toNumber(), falskt.toNumber());
}
QVERIFY(falskt.isBool());

QJSValue sant(true);
{
QJSValue tmp = eng.toObject(sant);
QVERIFY(tmp.isObject());
QCOMPARE(tmp.toNumber(), sant.toNumber());
}
QVERIFY(sant.isBool());

QJSValue number(123.0);
{
QJSValue tmp = eng.toObject(number);
QVERIFY(tmp.isObject());
QCOMPARE(tmp.toNumber(), number.toNumber());
}
QVERIFY(number.isNumber());

QJSValue str = QJSValue(&eng, QString("ciao"));
{
QJSValue tmp = eng.toObject(str);
QVERIFY(tmp.isObject());
QCOMPARE(tmp.toString(), str.toString());
}
QVERIFY(str.isString());

QJSValue object = eng.newObject();
{
QJSValue tmp = eng.toObject(object);
QVERIFY(tmp.isObject());
QVERIFY(tmp.strictlyEquals(object));
}

QJSValue qobject = eng.newQObject(this);
QVERIFY(eng.toObject(qobject).strictlyEquals(qobject));

QVERIFY(!eng.toObject(QJSValue()).isValid());

// v1 constructors

QJSValue boolValue(&eng, true);
{
QJSValue ret = eng.toObject(boolValue);
QVERIFY(ret.isObject());
QCOMPARE(ret.toBool(), boolValue.toBool());
}
QVERIFY(boolValue.isBool());

QJSValue numberValue(&eng, 123.0);
{
QJSValue ret = eng.toObject(numberValue);
QVERIFY(ret.isObject());
QCOMPARE(ret.toNumber(), numberValue.toNumber());
}
QVERIFY(numberValue.isNumber());

QJSValue stringValue(&eng, QString::fromLatin1("foo"));
{
QJSValue ret = eng.toObject(stringValue);
QVERIFY(ret.isObject());
QCOMPARE(ret.toString(), stringValue.toString());
}
QVERIFY(stringValue.isString());
}

void tst_QJSEngine::jsReservedWords_data()
{
QTest::addColumn<QString>("word");
Expand Down

0 comments on commit 1edcf64

Please sign in to comment.