Correctly convert an invalid QDateTime to JS

Task-number: QTBUG-33539

Change-Id: I645db2e12e3b46731c0bef04e2d48abb71650974
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
Lars Knoll 2013-09-18 13:29:38 +02:00 committed by The Qt Project
parent 52cc10589a
commit bc8b25dd91
4 changed files with 52 additions and 1 deletions

View File

@ -641,7 +641,7 @@ DateObject::DateObject(ExecutionEngine *engine, const QDateTime &date)
{ {
vtbl = &static_vtbl; vtbl = &static_vtbl;
type = Type_DateObject; type = Type_DateObject;
value = Value::fromDouble(date.toMSecsSinceEpoch()); value.setDouble(date.isValid() ? date.toMSecsSinceEpoch() : qSNaN());
} }
QDateTime DateObject::toQDateTime() const QDateTime DateObject::toQDateTime() const

View File

@ -0,0 +1,20 @@
import QtQuick 2.0
import Qt.test 1.0
Item {
MyDateClass {
id: mdc
}
function test_is_invalid_qtDateTime()
{
var dt = mdc.invalidDate();
return isNaN(dt);
}
function test_is_invalid_jsDateTime()
{
var dt = new Date("");
return isNaN(dt);
}
}

View File

@ -225,6 +225,16 @@ void MyWorkerObject::doIt()
new MyWorkerObjectThread(this); new MyWorkerObjectThread(this);
} }
class MyDateClass : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE QDateTime invalidDate()
{
return QDateTime();
}
};
class MyStringClass : public QObject class MyStringClass : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -317,6 +327,7 @@ void registerTypes()
qmlRegisterType<FallbackBindingsTypeObject>("Qt.test.fallbackBindingsObject", 1, 0, "FallbackBindingsType"); qmlRegisterType<FallbackBindingsTypeObject>("Qt.test.fallbackBindingsObject", 1, 0, "FallbackBindingsType");
qmlRegisterType<FallbackBindingsTypeDerived>("Qt.test.fallbackBindingsDerived", 1, 0, "FallbackBindingsType"); qmlRegisterType<FallbackBindingsTypeDerived>("Qt.test.fallbackBindingsDerived", 1, 0, "FallbackBindingsType");
qmlRegisterType<MyDateClass>("Qt.test", 1, 0, "MyDateClass");
qmlRegisterType<MyStringClass>("Qt.test", 1, 0, "MyStringClass"); qmlRegisterType<MyStringClass>("Qt.test", 1, 0, "MyStringClass");
qmlRegisterSingletonType<testImportOrderApi>("Qt.test.importOrderApi",1,0,"Data",testImportOrder_api); qmlRegisterSingletonType<testImportOrderApi>("Qt.test.importOrderApi",1,0,"Data",testImportOrder_api);

View File

@ -209,6 +209,7 @@ private slots:
void assignSequenceTypes(); void assignSequenceTypes();
void sequenceSort_data(); void sequenceSort_data();
void sequenceSort(); void sequenceSort();
void dateParse();
void qtbug_22464(); void qtbug_22464();
void qtbug_21580(); void qtbug_21580();
void singleV8BindingDestroyedDuringEvaluation(); void singleV8BindingDestroyedDuringEvaluation();
@ -7204,6 +7205,25 @@ void tst_qqmlecmascript::sequenceSort()
delete object; delete object;
} }
void tst_qqmlecmascript::dateParse()
{
QQmlComponent component(&engine, testFileUrl("date.qml"));
QObject *object = component.create();
if (object == 0)
qDebug() << component.errorString();
QVERIFY(object != 0);
QVariant q;
QMetaObject::invokeMethod(object, "test_is_invalid_jsDateTime", Q_RETURN_ARG(QVariant, q));
QVERIFY(q.toBool() == true);
QMetaObject::invokeMethod(object, "test_is_invalid_qtDateTime", Q_RETURN_ARG(QVariant, q));
QVERIFY(q.toBool() == true);
}
void tst_qqmlecmascript::concatenatedStringPropertyAccess() void tst_qqmlecmascript::concatenatedStringPropertyAccess()
{ {
QQmlComponent component(&engine, testFileUrl("concatenatedStringPropertyAccess.qml")); QQmlComponent component(&engine, testFileUrl("concatenatedStringPropertyAccess.qml"));