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:
parent
52cc10589a
commit
bc8b25dd91
|
@ -641,7 +641,7 @@ DateObject::DateObject(ExecutionEngine *engine, const QDateTime &date)
|
|||
{
|
||||
vtbl = &static_vtbl;
|
||||
type = Type_DateObject;
|
||||
value = Value::fromDouble(date.toMSecsSinceEpoch());
|
||||
value.setDouble(date.isValid() ? date.toMSecsSinceEpoch() : qSNaN());
|
||||
}
|
||||
|
||||
QDateTime DateObject::toQDateTime() const
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -225,6 +225,16 @@ void MyWorkerObject::doIt()
|
|||
new MyWorkerObjectThread(this);
|
||||
}
|
||||
|
||||
class MyDateClass : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_INVOKABLE QDateTime invalidDate()
|
||||
{
|
||||
return QDateTime();
|
||||
}
|
||||
};
|
||||
|
||||
class MyStringClass : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -317,6 +327,7 @@ void registerTypes()
|
|||
qmlRegisterType<FallbackBindingsTypeObject>("Qt.test.fallbackBindingsObject", 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");
|
||||
|
||||
qmlRegisterSingletonType<testImportOrderApi>("Qt.test.importOrderApi",1,0,"Data",testImportOrder_api);
|
||||
|
|
|
@ -209,6 +209,7 @@ private slots:
|
|||
void assignSequenceTypes();
|
||||
void sequenceSort_data();
|
||||
void sequenceSort();
|
||||
void dateParse();
|
||||
void qtbug_22464();
|
||||
void qtbug_21580();
|
||||
void singleV8BindingDestroyedDuringEvaluation();
|
||||
|
@ -7204,6 +7205,25 @@ void tst_qqmlecmascript::sequenceSort()
|
|||
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()
|
||||
{
|
||||
QQmlComponent component(&engine, testFileUrl("concatenatedStringPropertyAccess.qml"));
|
||||
|
|
Loading…
Reference in New Issue