Skip to content

Commit

Permalink
Remove QJSValue::toInteger() function
Browse files Browse the repository at this point in the history
Rationale: This is a remnant from QtScript. A function called
toInteger() that returns a double looks strange.
Use toInt32() to convert a QJSValue to an integer.

Task-number: QTBUG-23604

Change-Id: I2829704c64b077fca264b660c46248c3f35cb5c0
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 1edcf64 commit 24bf48e
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 116 deletions.
27 changes: 1 addition & 26 deletions src/declarative/qml/v8/qjsvalue.cpp
Expand Up @@ -541,7 +541,7 @@ QString QJSValue::toString() const
attempt to convert the object to a primitive value (possibly
resulting in an uncaught script exception).
\sa isNumber(), toInteger(), toInt(), toUInt(), toUInt16()
\sa isNumber(), toInt(), toUInt(), toUInt16()
*/
double QJSValue::toNumber() const
{
Expand Down Expand Up @@ -569,31 +569,6 @@ bool QJSValue::toBool() const
return d->toBool();
}

#ifdef QT_DEPRECATED

/*!
\obsolete
Returns the integer value of this QJSValue, using the conversion
rules described in \l{ECMA-262} section 9.4, "ToInteger".
Note that if this QJSValue is an object, calling this function
has side effects on the script engine, since the engine will call
the object's valueOf() function (and possibly toString()) in an
attempt to convert the object to a primitive value (possibly
resulting in an uncaught script exception).
\sa toNumber()
*/
double QJSValue::toInteger() const
{
Q_D(const QJSValue);
QScriptIsolate api(d->engine());
return d->toInteger();
}

#endif // QT_DEPRECATED

/*!
Returns the signed 32-bit integer value of this QJSValue, using
the conversion rules described in \l{ECMA-262} section 9.5, "ToInt32".
Expand Down
1 change: 0 additions & 1 deletion src/declarative/qml/v8/qjsvalue.h
Expand Up @@ -140,7 +140,6 @@ class Q_DECLARATIVE_EXPORT QJSValue

QT_DEPRECATED bool isValid() const;
QT_DEPRECATED bool isFunction() const;
QT_DEPRECATED double toInteger() const;
QT_DEPRECATED qint32 toInt32() const;
QT_DEPRECATED quint32 toUInt32() const;
QT_DEPRECATED quint16 toUInt16() const;
Expand Down
2 changes: 1 addition & 1 deletion tests/auto/declarative/qjsengine/tst_qjsengine.cpp
Expand Up @@ -6421,7 +6421,7 @@ class ThreadedTestEngine : public QThread {
QJSEngine firstEngine;
QJSEngine secondEngine;
QJSValue value = firstEngine.evaluate("1");
result = secondEngine.evaluate("1 + " + QString::number(value.toInteger())).toInteger();
result = secondEngine.evaluate("1 + " + QString::number(value.toInt())).toInt();
}
};

Expand Down
87 changes: 0 additions & 87 deletions tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
Expand Up @@ -731,93 +731,6 @@ void tst_QJSValue::toBool()
}
}

void tst_QJSValue::toInteger()
{
QJSEngine eng;

{
QJSValue number = QJSValue(&eng, 123.0);
QCOMPARE(number.toInteger(), 123.0);

QJSValue number2 = QJSValue(&eng, qSNaN());
QCOMPARE(number2.toInteger(), 0.0);

QJSValue number3 = QJSValue(&eng, qInf());
QCOMPARE(qIsInf(number3.toInteger()), true);

QJSValue number4 = QJSValue(&eng, 0.5);
QCOMPARE(number4.toInteger(), 0.0);

QJSValue number5 = QJSValue(&eng, 123.5);
QCOMPARE(number5.toInteger(), 123.0);

QJSValue number6 = QJSValue(&eng, -456.5);
QCOMPARE(number6.toInteger(), -456.0);

QJSValue str = QJSValue(&eng, QLatin1String("123.0"));
QCOMPARE(str.toInteger(), 123.0);

QJSValue str2 = QJSValue(&eng, QLatin1String("NaN"));
QCOMPARE(str2.toInteger(), 0.0);

QJSValue str3 = QJSValue(&eng, QLatin1String("Infinity"));
QCOMPARE(qIsInf(str3.toInteger()), true);

QJSValue str4 = QJSValue(&eng, QLatin1String("0.5"));
QCOMPARE(str4.toInteger(), 0.0);

QJSValue str5 = QJSValue(&eng, QLatin1String("123.5"));
QCOMPARE(str5.toInteger(), 123.0);

QJSValue str6 = QJSValue(&eng, QLatin1String("-456.5"));
QCOMPARE(str6.toInteger(), -456.0);
}
// V2 constructors
{
QJSValue number = QJSValue(123.0);
QCOMPARE(number.toInteger(), 123.0);

QJSValue number2 = QJSValue(qSNaN());
QCOMPARE(number2.toInteger(), 0.0);

QJSValue number3 = QJSValue(qInf());
QCOMPARE(qIsInf(number3.toInteger()), true);

QJSValue number4 = QJSValue(0.5);
QCOMPARE(number4.toInteger(), 0.0);

QJSValue number5 = QJSValue(123.5);
QCOMPARE(number5.toInteger(), 123.0);

QJSValue number6 = QJSValue(-456.5);
QCOMPARE(number6.toInteger(), -456.0);

QJSValue number7 = QJSValue(0x43211234);
QCOMPARE(number7.toInteger(), qreal(0x43211234));

QJSValue str = QJSValue("123.0");
QCOMPARE(str.toInteger(), 123.0);

QJSValue str2 = QJSValue("NaN");
QCOMPARE(str2.toInteger(), 0.0);

QJSValue str3 = QJSValue("Infinity");
QCOMPARE(qIsInf(str3.toInteger()), true);

QJSValue str4 = QJSValue("0.5");
QCOMPARE(str4.toInteger(), 0.0);

QJSValue str5 = QJSValue("123.5");
QCOMPARE(str5.toInteger(), 123.0);

QJSValue str6 = QJSValue("-456.5");
QCOMPARE(str6.toInteger(), -456.0);
}

QJSValue inv;
QCOMPARE(inv.toInteger(), 0.0);
}

void tst_QJSValue::toInt()
{
QJSEngine eng;
Expand Down
1 change: 0 additions & 1 deletion tests/auto/declarative/qjsvalue/tst_qjsvalue.h
Expand Up @@ -83,7 +83,6 @@ private slots:
void toNumber();
void toBoolean();
void toBool();
void toInteger();
void toInt();
void toUInt();
void toUInt16();
Expand Down

0 comments on commit 24bf48e

Please sign in to comment.