Skip to content

Commit

Permalink
Remove QJSValue::toUInt16() function
Browse files Browse the repository at this point in the history
Rationale: Remnant from QtScript. The implementation is just zeroing
the upper 16 bits of the 32-bit integer conversion.

Task-number: QTBUG-23604

Change-Id: I6b4b40883da01713d2a946eb028264f3a351276b
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 24bf48e commit 422e299
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 179 deletions.
21 changes: 1 addition & 20 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(), toInt(), toUInt(), toUInt16()
\sa isNumber(), toInt(), toUInt()
*/
double QJSValue::toNumber() const
{
Expand Down Expand Up @@ -633,25 +633,6 @@ quint32 QJSValue::toUInt32() const
return d->toUInt32();
}

/*!
Returns the unsigned 16-bit integer value of this QJSValue, using
the conversion rules described in \l{ECMA-262} section 9.7, "ToUint16".
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()
*/
quint16 QJSValue::toUInt16() const
{
Q_D(const QJSValue);
QScriptIsolate api(d->engine());
return d->toUInt16();
}

#endif // QT_DEPRECATED

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

QT_DEPRECATED bool instanceOf(const QJSValue &other) const;
Expand Down
157 changes: 0 additions & 157 deletions tests/auto/declarative/qjsvalue/tst_qjsvalue.cpp
Expand Up @@ -999,163 +999,6 @@ void tst_QJSValue::toUInt()
QCOMPARE(qjsvalue_cast<quint32>(inv), quint32(0));
}

void tst_QJSValue::toUInt16()
{
QJSEngine eng;

{
QJSValue zer0 = QJSValue(&eng, 0.0);
QCOMPARE(zer0.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(zer0), quint16(0));

QJSValue number = QJSValue(&eng, 123.0);
QCOMPARE(number.toUInt16(), quint16(123));
QCOMPARE(qjsvalue_cast<quint16>(number), quint16(123));

QJSValue number2 = QJSValue(&eng, qSNaN());
QCOMPARE(number2.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(number2), quint16(0));

QJSValue number3 = QJSValue(&eng, +qInf());
QCOMPARE(number3.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(number3), quint16(0));

QJSValue number3_2 = QJSValue(&eng, -qInf());
QCOMPARE(number3_2.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(number3_2), quint16(0));

QJSValue number4 = QJSValue(&eng, 0.5);
QCOMPARE(number4.toUInt16(), quint16(0));

QJSValue number5 = QJSValue(&eng, 123.5);
QCOMPARE(number5.toUInt16(), quint16(123));

QJSValue number6 = QJSValue(&eng, -456.5);
QCOMPARE(number6.toUInt16(), quint16(-456));
QCOMPARE(qjsvalue_cast<quint16>(number6), quint16(-456));

QJSValue number7 = QJSValue(&eng, 0x10000);
QCOMPARE(number7.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(number7), quint16(0));

QJSValue number8 = QJSValue(&eng, 0x10001);
QCOMPARE(number8.toUInt16(), quint16(1));
QCOMPARE(qjsvalue_cast<quint16>(number8), quint16(1));

QJSValue str = QJSValue(&eng, QLatin1String("123.0"));
QCOMPARE(str.toUInt16(), quint16(123));
QCOMPARE(qjsvalue_cast<quint16>(str), quint16(123));

QJSValue str2 = QJSValue(&eng, QLatin1String("NaN"));
QCOMPARE(str2.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(str2), quint16(0));

QJSValue str3 = QJSValue(&eng, QLatin1String("Infinity"));
QCOMPARE(str3.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(str3), quint16(0));

QJSValue str3_2 = QJSValue(&eng, QLatin1String("-Infinity"));
QCOMPARE(str3_2.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(str3_2), quint16(0));

QJSValue str4 = QJSValue(&eng, QLatin1String("0.5"));
QCOMPARE(str4.toUInt16(), quint16(0));

QJSValue str5 = QJSValue(&eng, QLatin1String("123.5"));
QCOMPARE(str5.toUInt16(), quint16(123));

QJSValue str6 = QJSValue(&eng, QLatin1String("-456.5"));
QCOMPARE(str6.toUInt16(), quint16(-456));
QCOMPARE(qjsvalue_cast<quint16>(str6), quint16(-456));

QJSValue str7 = QJSValue(&eng, QLatin1String("0x10000"));
QCOMPARE(str7.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(str7), quint16(0));

QJSValue str8 = QJSValue(&eng, QLatin1String("0x10001"));
QCOMPARE(str8.toUInt16(), quint16(1));
QCOMPARE(qjsvalue_cast<quint16>(str8), quint16(1));
}
// V2 constructors
{
QJSValue zer0 = QJSValue(0.0);
QCOMPARE(zer0.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(zer0), quint16(0));

QJSValue number = QJSValue(123.0);
QCOMPARE(number.toUInt16(), quint16(123));
QCOMPARE(qjsvalue_cast<quint16>(number), quint16(123));

QJSValue number2 = QJSValue(qSNaN());
QCOMPARE(number2.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(number2), quint16(0));

QJSValue number3 = QJSValue(+qInf());
QCOMPARE(number3.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(number3), quint16(0));

QJSValue number3_2 = QJSValue(-qInf());
QCOMPARE(number3_2.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(number3_2), quint16(0));

QJSValue number4 = QJSValue(0.5);
QCOMPARE(number4.toUInt16(), quint16(0));

QJSValue number5 = QJSValue(123.5);
QCOMPARE(number5.toUInt16(), quint16(123));

QJSValue number6 = QJSValue(-456.5);
QCOMPARE(number6.toUInt16(), quint16(-456));
QCOMPARE(qjsvalue_cast<quint16>(number6), quint16(-456));

QJSValue number7 = QJSValue(0x10000);
QCOMPARE(number7.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(number7), quint16(0));

QJSValue number8 = QJSValue(0x10001);
QCOMPARE(number8.toUInt16(), quint16(1));
QCOMPARE(qjsvalue_cast<quint16>(number8), quint16(1));

QJSValue str = QJSValue(QLatin1String("123.0"));
QCOMPARE(str.toUInt16(), quint16(123));
QCOMPARE(qjsvalue_cast<quint16>(str), quint16(123));

QJSValue str2 = QJSValue(QLatin1String("NaN"));
QCOMPARE(str2.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(str2), quint16(0));

QJSValue str3 = QJSValue(QLatin1String("Infinity"));
QCOMPARE(str3.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(str3), quint16(0));

QJSValue str3_2 = QJSValue(QLatin1String("-Infinity"));
QCOMPARE(str3_2.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(str3_2), quint16(0));

QJSValue str4 = QJSValue("0.5");
QCOMPARE(str4.toUInt16(), quint16(0));

QJSValue str5 = QJSValue("123.5");
QCOMPARE(str5.toUInt16(), quint16(123));

QJSValue str6 = QJSValue("-456.5");
QCOMPARE(str6.toUInt16(), quint16(-456));
QCOMPARE(qjsvalue_cast<quint16>(str6), quint16(-456));

QJSValue str7 = QJSValue("0x10000");
QCOMPARE(str7.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(str7), quint16(0));

QJSValue str8 = QJSValue("0x10001");
QCOMPARE(str8.toUInt16(), quint16(1));
QCOMPARE(qjsvalue_cast<quint16>(str8), quint16(1));
}

QJSValue inv;
QCOMPARE(inv.toUInt16(), quint16(0));
QCOMPARE(qjsvalue_cast<quint16>(inv), quint16(0));
}

#if defined Q_CC_MSVC && _MSC_VER < 1300
Q_DECLARE_METATYPE(QVariant)
#endif
Expand Down
1 change: 0 additions & 1 deletion tests/auto/declarative/qjsvalue/tst_qjsvalue.h
Expand Up @@ -85,7 +85,6 @@ private slots:
void toBool();
void toInt();
void toUInt();
void toUInt16();
void toVariant();
void toQObject_nonQObject_data();
void toQObject_nonQObject();
Expand Down

0 comments on commit 422e299

Please sign in to comment.