Remove QJSValue::toInteger() function
authorKent Hansen <kent.hansen@nokia.com>
Mon, 16 Jan 2012 14:01:29 +0000 (15:01 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 1 Feb 2012 07:37:49 +0000 (08:37 +0100)
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>
src/declarative/qml/v8/qjsvalue.cpp
src/declarative/qml/v8/qjsvalue.h
tests/auto/declarative/qjsengine/tst_qjsengine.cpp
tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
tests/auto/declarative/qjsvalue/tst_qjsvalue.h

index f470973..9fe9bb3 100644 (file)
@@ -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
 {
@@ -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".
index 4e4cfe0..84fe64d 100644 (file)
@@ -140,7 +140,6 @@ public:
 
     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;
index c13f86f..1a0e8a1 100644 (file)
@@ -6421,7 +6421,7 @@ public:
         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();
     }
 };
 
index c02e446..eeae7a3 100644 (file)
@@ -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;
index 978cd92..0750766 100644 (file)
@@ -83,7 +83,6 @@ private slots:
     void toNumber();
     void toBoolean();
     void toBool();
-    void toInteger();
     void toInt();
     void toUInt();
     void toUInt16();