Remove QJSValue::toInteger() function
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>
This commit is contained in:
parent
1edcf64d28
commit
24bf48e3dd
|
@ -541,7 +541,7 @@ QString QJSValue::toString() const
|
||||||
attempt to convert the object to a primitive value (possibly
|
attempt to convert the object to a primitive value (possibly
|
||||||
resulting in an uncaught script exception).
|
resulting in an uncaught script exception).
|
||||||
|
|
||||||
\sa isNumber(), toInteger(), toInt(), toUInt(), toUInt16()
|
\sa isNumber(), toInt(), toUInt(), toUInt16()
|
||||||
*/
|
*/
|
||||||
double QJSValue::toNumber() const
|
double QJSValue::toNumber() const
|
||||||
{
|
{
|
||||||
|
@ -569,31 +569,6 @@ bool QJSValue::toBool() const
|
||||||
return d->toBool();
|
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
|
Returns the signed 32-bit integer value of this QJSValue, using
|
||||||
the conversion rules described in \l{ECMA-262} section 9.5, "ToInt32".
|
the conversion rules described in \l{ECMA-262} section 9.5, "ToInt32".
|
||||||
|
|
|
@ -140,7 +140,6 @@ public:
|
||||||
|
|
||||||
QT_DEPRECATED bool isValid() const;
|
QT_DEPRECATED bool isValid() const;
|
||||||
QT_DEPRECATED bool isFunction() const;
|
QT_DEPRECATED bool isFunction() const;
|
||||||
QT_DEPRECATED double toInteger() const;
|
|
||||||
QT_DEPRECATED qint32 toInt32() const;
|
QT_DEPRECATED qint32 toInt32() const;
|
||||||
QT_DEPRECATED quint32 toUInt32() const;
|
QT_DEPRECATED quint32 toUInt32() const;
|
||||||
QT_DEPRECATED quint16 toUInt16() const;
|
QT_DEPRECATED quint16 toUInt16() const;
|
||||||
|
|
|
@ -6421,7 +6421,7 @@ public:
|
||||||
QJSEngine firstEngine;
|
QJSEngine firstEngine;
|
||||||
QJSEngine secondEngine;
|
QJSEngine secondEngine;
|
||||||
QJSValue value = firstEngine.evaluate("1");
|
QJSValue value = firstEngine.evaluate("1");
|
||||||
result = secondEngine.evaluate("1 + " + QString::number(value.toInteger())).toInteger();
|
result = secondEngine.evaluate("1 + " + QString::number(value.toInt())).toInt();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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()
|
void tst_QJSValue::toInt()
|
||||||
{
|
{
|
||||||
QJSEngine eng;
|
QJSEngine eng;
|
||||||
|
|
|
@ -83,7 +83,6 @@ private slots:
|
||||||
void toNumber();
|
void toNumber();
|
||||||
void toBoolean();
|
void toBoolean();
|
||||||
void toBool();
|
void toBool();
|
||||||
void toInteger();
|
|
||||||
void toInt();
|
void toInt();
|
||||||
void toUInt();
|
void toUInt();
|
||||||
void toUInt16();
|
void toUInt16();
|
||||||
|
|
Loading…
Reference in New Issue