Date.prototype: Fixes for ES6 compliance

* Don't return -0 from TimeClip (20.3.1.15, 1)
* Mark length configurable (19.2.4.1)
* toUTCString and toGMTString must be the the same object (B.2.4.3)

Brings us a bit closer to passing tests. Still some failures in other
areas.

Change-Id: I905216b8653ac0b33cb27e6b773616521fbb5daa
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Robin Burchell 2017-02-03 19:38:16 +01:00
parent 7af9656e78
commit 8779521704
3 changed files with 22 additions and 6 deletions

View File

@ -340,7 +340,9 @@ static inline double TimeClip(double t)
{
if (! qt_is_finite(t) || fabs(t) > 8.64e15)
return qt_qnan();
return Primitive::toInteger(t);
// +0 looks weird, but is correct. See ES6 20.3.1.15. We must not return -0.
return Primitive::toInteger(t) + 0;
}
static inline double ParseString(const QString &s)
@ -724,7 +726,7 @@ void DatePrototype::init(ExecutionEngine *engine, Object *ctor)
Scope scope(engine);
ScopedObject o(scope);
ctor->defineReadonlyProperty(engine->id_prototype(), (o = this));
ctor->defineReadonlyProperty(engine->id_length(), Primitive::fromInt32(7));
ctor->defineReadonlyConfigurableProperty(engine->id_length(), Primitive::fromInt32(7));
LocalTZA = getLocalTZA();
ctor->defineDefaultProperty(QStringLiteral("parse"), method_parse, 1);
@ -774,8 +776,21 @@ void DatePrototype::init(ExecutionEngine *engine, Object *ctor)
defineDefaultProperty(QStringLiteral("setYear"), method_setYear, 1);
defineDefaultProperty(QStringLiteral("setFullYear"), method_setFullYear, 3);
defineDefaultProperty(QStringLiteral("setUTCFullYear"), method_setUTCFullYear, 3);
defineDefaultProperty(QStringLiteral("toUTCString"), method_toUTCString, 0);
defineDefaultProperty(QStringLiteral("toGMTString"), method_toUTCString, 0);
// ES6: B.2.4.3 & 20.3.4.43:
// We have to use the *same object* for toUTCString and toGMTString
{
QString toUtcString(QStringLiteral("toUTCString"));
QString toGmtString(QStringLiteral("toGMTString"));
ScopedString us(scope, engine->newIdentifier(toUtcString));
ScopedString gs(scope, engine->newIdentifier(toGmtString));
ExecutionContext *global = engine->rootContext();
ScopedFunctionObject toUtcGmtStringFn(scope, BuiltinFunction::create(global, us, method_toUTCString));
toUtcGmtStringFn->defineReadonlyConfigurableProperty(engine->id_length(), Primitive::fromInt32(0));
defineDefaultProperty(us, toUtcGmtStringFn);
defineDefaultProperty(gs, toUtcGmtStringFn);
}
defineDefaultProperty(QStringLiteral("toISOString"), method_toISOString, 0);
defineDefaultProperty(QStringLiteral("toJSON"), method_toJSON, 1);
}

View File

@ -1099,7 +1099,7 @@ void tst_QJSEngine::builtinFunctionNames_data()
QTest::newRow("Date.prototype.setFullYear") << QString("Date.prototype.setFullYear") << QString("setFullYear");
QTest::newRow("Date.prototype.setUTCFullYear") << QString("Date.prototype.setUTCFullYear") << QString("setUTCFullYear");
QTest::newRow("Date.prototype.toUTCString") << QString("Date.prototype.toUTCString") << QString("toUTCString");
QTest::newRow("Date.prototype.toGMTString") << QString("Date.prototype.toGMTString") << QString("toGMTString");
QTest::newRow("Date.prototype.toGMTString") << QString("Date.prototype.toGMTString") << QString("toUTCString"); // yes, this is per spec
QTest::newRow("Error") << QString("Error") << QString("Error");
// QTest::newRow("Error.prototype.backtrace") << QString("Error.prototype.backtrace") << QString("backtrace");

View File

@ -30,7 +30,7 @@ Sbp_12.6.1_A13_T3 failing
Sbp_12.6.2_A13_T3 failing
Sbp_12.6.4_A13_T3 failing
# function length attributes are configurable in es6
# es6: function length attributes are configurable, wasn't in es5
S15.1.2.2_A9.2 failing
S15.1.3.1_A5.2 failing
S15.1.3.2_A5.2 failing
@ -86,6 +86,7 @@ S15.9.5.2_A3_T2 failing
S15.9.5.3_A3_T2 failing
S15.9.5.4_A3_T2 failing
S15.9.5.5_A3_T2 failing
S15.9.5.1_A3_T2 failing
S15.9.5.10_A3_T2 failing
S15.9.5.11_A3_T2 failing
S15.9.5.12_A3_T2 failing