Fix === operator for value types
Fix === comparison for urls and other QML value types. Task-number: QTBUG-33546 Change-Id: I4a7066e6bbc7de7c599fe2c7b2fdfb75e0ff5196 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
parent
d7a876d002
commit
0dc17ae4d8
|
@ -46,6 +46,13 @@ Third party components
|
|||
the engine now truncates instead of rounding. This is consistent with the
|
||||
ECMAScript specification's way of converting doubles to ints.
|
||||
|
||||
- Comparing value based types with the JS strictly equal operator will
|
||||
now behave similar to the corresponding C++ == operator. Ie. two
|
||||
QPoints exposed on the JS side will be strictly equal if their values
|
||||
are equal. This brings the behavior of value based types in JS closer
|
||||
to what one would expect and more inline with primitive values in
|
||||
Javascript.
|
||||
|
||||
****************************************************************************
|
||||
* Library *
|
||||
****************************************************************************
|
||||
|
|
|
@ -722,8 +722,8 @@ Bool __qmljs_strict_equal(const ValueRef x, const ValueRef y)
|
|||
|
||||
if (x->isNumber())
|
||||
return y->isNumber() && x->asDouble() == y->asDouble();
|
||||
if (x->isString())
|
||||
return y->isString() && x->stringValue()->isEqualTo(y->stringValue());
|
||||
if (x->isManaged())
|
||||
return y->isManaged() && x->managed()->isEqualTo(y->managed());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -234,7 +234,10 @@ bool String::isEqualTo(Managed *t, Managed *o)
|
|||
if (t == o)
|
||||
return true;
|
||||
|
||||
Q_ASSERT(t->type == Type_String && o->type == Type_String);
|
||||
if (o->type != Type_String)
|
||||
return false;
|
||||
|
||||
Q_ASSERT(t->type == Type_String);
|
||||
String *that = static_cast<String *>(t);
|
||||
String *other = static_cast<String *>(o);
|
||||
if (that->hashValue() != other->hashValue())
|
||||
|
|
|
@ -2206,7 +2206,7 @@ void tst_QJSValue::strictlyEquals()
|
|||
{
|
||||
QJSValue var1 = eng.toScriptValue(QVariant(QPoint(1, 2)));
|
||||
QJSValue var2 = eng.toScriptValue(QVariant(QPoint(1, 2)));
|
||||
QVERIFY(!var1.strictlyEquals(var2));
|
||||
QVERIFY(var1.strictlyEquals(var2));
|
||||
}
|
||||
{
|
||||
QJSValue var1 = eng.toScriptValue(QVariant(QPoint(1, 2)));
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
import QtQuick 2.0
|
||||
import Qt.test 1.0
|
||||
|
||||
Item {
|
||||
MiscTypeTest {
|
||||
id: mtt
|
||||
}
|
||||
|
||||
function test_invalid_url_equal()
|
||||
{
|
||||
return mtt.invalidUrl() == mtt.invalidUrl();
|
||||
}
|
||||
|
||||
function test_invalid_url_refequal()
|
||||
{
|
||||
return mtt.invalidUrl() === mtt.invalidUrl();
|
||||
}
|
||||
|
||||
function test_valid_url_equal()
|
||||
{
|
||||
return mtt.validUrl() == mtt.validUrl();
|
||||
}
|
||||
|
||||
function test_valid_url_refequal()
|
||||
{
|
||||
return mtt.validUrl() === mtt.validUrl();
|
||||
}
|
||||
}
|
|
@ -235,6 +235,21 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
class MiscTypeTestClass : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_INVOKABLE QUrl invalidUrl()
|
||||
{
|
||||
return QUrl();
|
||||
}
|
||||
|
||||
Q_INVOKABLE QUrl validUrl()
|
||||
{
|
||||
return QUrl("http://wwww.qt-project.org");
|
||||
}
|
||||
};
|
||||
|
||||
class MyStringClass : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -353,6 +368,7 @@ void registerTypes()
|
|||
|
||||
qmlRegisterType<MyDateClass>("Qt.test", 1, 0, "MyDateClass");
|
||||
qmlRegisterType<MyStringClass>("Qt.test", 1, 0, "MyStringClass");
|
||||
qmlRegisterType<MiscTypeTestClass>("Qt.test", 1, 0, "MiscTypeTest");
|
||||
|
||||
qmlRegisterSingletonType<testImportOrderApi>("Qt.test.importOrderApi",1,0,"Data",testImportOrder_api);
|
||||
qmlRegisterSingletonType<testImportOrderApi>("NamespaceAndType",1,0,"NamespaceAndType",testImportOrder_api);
|
||||
|
|
|
@ -312,6 +312,7 @@ private slots:
|
|||
void qtbug_34493();
|
||||
void singletonFromQMLToCpp();
|
||||
void setPropertyOnInvalid();
|
||||
void miscTypeTest();
|
||||
|
||||
private:
|
||||
// static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
|
||||
|
@ -7383,6 +7384,29 @@ void tst_qqmlecmascript::setPropertyOnInvalid()
|
|||
}
|
||||
}
|
||||
|
||||
void tst_qqmlecmascript::miscTypeTest()
|
||||
{
|
||||
QQmlComponent component(&engine, testFileUrl("misctypetest.qml"));
|
||||
|
||||
QObject *object = component.create();
|
||||
if (object == 0)
|
||||
qDebug() << component.errorString();
|
||||
QVERIFY(object != 0);
|
||||
|
||||
QVariant q;
|
||||
QMetaObject::invokeMethod(object, "test_invalid_url_equal", Q_RETURN_ARG(QVariant, q));
|
||||
QVERIFY(q.toBool() == true);
|
||||
QMetaObject::invokeMethod(object, "test_invalid_url_strictequal", Q_RETURN_ARG(QVariant, q));
|
||||
QVERIFY(q.toBool() == true);
|
||||
QMetaObject::invokeMethod(object, "test_valid_url_equal", Q_RETURN_ARG(QVariant, q));
|
||||
QVERIFY(q.toBool() == true);
|
||||
QMetaObject::invokeMethod(object, "test_valid_url_strictequal", Q_RETURN_ARG(QVariant, q));
|
||||
QVERIFY(q.toBool() == true);
|
||||
|
||||
delete object;
|
||||
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_qqmlecmascript)
|
||||
|
||||
#include "tst_qqmlecmascript.moc"
|
||||
|
|
Loading…
Reference in New Issue