Skip to content
Permalink
Browse files
[JSC] Update test262
https://bugs.webkit.org/show_bug.cgi?id=231201

Add tests that were somehow cut off in the previous patch.

Patch by Philip Chimento <pchimento@igalia.com> on 2021-10-06
Reviewed by Ross Kirsling.

* test262/test/built-ins/Temporal/Now/*: Added.

Canonical link: https://commits.webkit.org/242606@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@283666 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
ptomato authored and webkit-commit-queue committed Oct 6, 2021
1 parent f0d83f3 commit 1b1e2a9b47b129a019484d5c5d00ca252ddd4957
Showing 24 changed files with 577 additions and 0 deletions.
@@ -1,3 +1,14 @@
2021-10-06 Philip Chimento <pchimento@igalia.com>

[JSC] Update test262
https://bugs.webkit.org/show_bug.cgi?id=231201

Add tests that were somehow cut off in the previous patch.

Reviewed by Ross Kirsling.

* test262/test/built-ins/Temporal/Now/*: Added.

2021-10-06 Philip Chimento <pchimento@igalia.com>

[JSC] Update test262
@@ -0,0 +1,22 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaindate
description: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots
info: |
sec-temporal.now.plaindate step 1:
1. Let _dateTime_ be ? SystemDateTime(_temporalTimeZoneLike_, _calendar_).
sec-temporal-systemdatetime step 3:
3. Let _calendar_ be ? ToTemporalCalendar(_calendarLike_).
sec-temporal-totemporalcalendar step 1.a:
a. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
i. Return _temporalCalendarLike_.[[Calendar]].
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/

TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject, calendar) => {
const result = Temporal.Now.plainDate(temporalObject);
assert.sameValue(result.calendar, calendar, "Temporal object coerced to calendar");
});
@@ -0,0 +1,25 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaindate
description: Temporal.Now.plainDate.length is 1
info: |
Every built-in function object, including constructors, has a "length" property whose value is
an integer. Unless otherwise specified, this value is equal to the largest number of named
arguments shown in the subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
«...name») are not included in the default argument count.
Unless otherwise specified, the "length" property of a built-in function object has the
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/

verifyProperty(Temporal.Now.plainDate, "length", {
value: 1,
writable: false,
enumerable: false,
configurable: true,
});
@@ -0,0 +1,15 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaindate
description: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds
features: [Temporal]
includes: [temporalHelpers.js]
---*/

[3600_000_000_000.5, NaN].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);

assert.throws(RangeError, () => Temporal.Now.plainDate("iso8601", timeZone));
});
@@ -0,0 +1,15 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaindate
description: RangeError thrown if time zone reports an offset that is out of range
features: [Temporal]
includes: [temporalHelpers.js]
---*/

[-86400_000_000_001, 86400_000_000_001, -Infinity, Infinity].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);

assert.throws(RangeError, () => Temporal.Now.plainDate("iso8601", timeZone));
});
@@ -0,0 +1,24 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaindate
description: TypeError thrown if time zone reports an offset that is not a Number
features: [Temporal]
includes: [temporalHelpers.js]
---*/

[
undefined,
null,
true,
"+01:00",
Symbol(),
3600_000_000_000n,
{},
{ valueOf() { return 3600_000_000_000; } },
].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);

assert.throws(TypeError, () => Temporal.Now.plainDate("iso8601", timeZone));
});
@@ -0,0 +1,25 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaindate
description: Conversion of ISO date-time strings to Temporal.TimeZone instances
features: [Temporal]
---*/

let timeZone = "2021-08-19T17:30";
assert.throws(RangeError, () => Temporal.Now.plainDate("iso8601", timeZone), "bare date-time string is not a time zone");
assert.throws(RangeError, () => Temporal.Now.plainDate("iso8601", { timeZone }), "bare date-time string is not a time zone");

// The following are all valid strings so should not throw:

[
"2021-08-19T17:30Z",
"2021-08-19T17:30-07:00",
"2021-08-19T17:30[America/Vancouver]",
"2021-08-19T17:30Z[America/Vancouver]",
"2021-08-19T17:30-07:00[America/Vancouver]",
].forEach((timeZone) => {
Temporal.Now.plainDate("iso8601", timeZone);
Temporal.Now.plainDate("iso8601", { timeZone });
});
@@ -0,0 +1,48 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaindate
description: PlainDateTime.toPlainDate is not observably called
includes: [compareArray.js]
features: [Temporal]
---*/

const actual = [];
const expected = [
"has timeZone.timeZone",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
];

Object.defineProperty(Temporal.PlainDateTime.prototype, "toPlainDate", {
get() {
actual.push("get Temporal.PlainDateTime.prototype.toPlainDate");
return function() {
actual.push("call Temporal.PlainDateTime.prototype.toPlainDate");
};
},
});

const timeZone = new Proxy({
getOffsetNanosecondsFor(instant) {
actual.push("call timeZone.getOffsetNanosecondsFor");
assert.sameValue(instant instanceof Temporal.Instant, true, "Instant");
return 86399_999_999_999;
},
}, {
has(target, property) {
actual.push(`has timeZone.${property}`);
return property in target;
},
get(target, property) {
actual.push(`get timeZone.${property}`);
return target[property];
},
});

const result = Temporal.Now.plainDate("iso8601", timeZone);
assert.notSameValue(result, undefined);
assert.sameValue(result instanceof Temporal.PlainDate, true);

assert.compareArray(actual, expected);
@@ -0,0 +1,25 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaindateiso
description: Temporal.Now.plainDateISO.length is 0
info: |
Every built-in function object, including constructors, has a "length" property whose value is
an integer. Unless otherwise specified, this value is equal to the largest number of named
arguments shown in the subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
«...name») are not included in the default argument count.
Unless otherwise specified, the "length" property of a built-in function object has the
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/

verifyProperty(Temporal.Now.plainDateISO, "length", {
value: 0,
writable: false,
enumerable: false,
configurable: true,
});
@@ -0,0 +1,15 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaindateiso
description: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds
features: [Temporal]
includes: [temporalHelpers.js]
---*/

[3600_000_000_000.5, NaN].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);

assert.throws(RangeError, () => Temporal.Now.plainDateISO(timeZone));
});
@@ -0,0 +1,15 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaindateiso
description: RangeError thrown if time zone reports an offset that is out of range
features: [Temporal]
includes: [temporalHelpers.js]
---*/

[-86400_000_000_001, 86400_000_000_001, -Infinity, Infinity].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);

assert.throws(RangeError, () => Temporal.Now.plainDateISO(timeZone));
});
@@ -0,0 +1,24 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaindateiso
description: TypeError thrown if time zone reports an offset that is not a Number
features: [Temporal]
includes: [temporalHelpers.js]
---*/

[
undefined,
null,
true,
"+01:00",
Symbol(),
3600_000_000_000n,
{},
{ valueOf() { return 3600_000_000_000; } },
].forEach((wrongOffset) => {
const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset);

assert.throws(TypeError, () => Temporal.Now.plainDateISO(timeZone));
});
@@ -0,0 +1,25 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaindateiso
description: Conversion of ISO date-time strings to Temporal.TimeZone instances
features: [Temporal]
---*/

let timeZone = "2021-08-19T17:30";
assert.throws(RangeError, () => Temporal.Now.plainDateISO(timeZone), "bare date-time string is not a time zone");
assert.throws(RangeError, () => Temporal.Now.plainDateISO({ timeZone }), "bare date-time string is not a time zone");

// The following are all valid strings so should not throw:

[
"2021-08-19T17:30Z",
"2021-08-19T17:30-07:00",
"2021-08-19T17:30[America/Vancouver]",
"2021-08-19T17:30Z[America/Vancouver]",
"2021-08-19T17:30-07:00[America/Vancouver]",
].forEach((timeZone) => {
Temporal.Now.plainDateISO(timeZone);
Temporal.Now.plainDateISO({ timeZone });
});
@@ -0,0 +1,25 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaindatetime
description: Conversion of ISO date-time strings to Temporal.TimeZone instances
features: [Temporal]
---*/

let timeZone = "2021-08-19T17:30";
assert.throws(RangeError, () => Temporal.Now.plainDateTime("iso8601", timeZone), "bare date-time string is not a time zone");
assert.throws(RangeError, () => Temporal.Now.plainDateTime("iso8601", { timeZone }), "bare date-time string is not a time zone");

// The following are all valid strings so should not throw:

[
"2021-08-19T17:30Z",
"2021-08-19T17:30-07:00",
"2021-08-19T17:30[America/Vancouver]",
"2021-08-19T17:30Z[America/Vancouver]",
"2021-08-19T17:30-07:00[America/Vancouver]",
].forEach((timeZone) => {
Temporal.Now.plainDateTime("iso8601", timeZone);
Temporal.Now.plainDateTime("iso8601", { timeZone });
});
@@ -0,0 +1,42 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaindatetime
description: The value returned by TimeZone.getOffsetNanosecondsFor affects the result
includes: [compareArray.js]
features: [Temporal]
---*/

const actual = [];
const expected = [
"has timeZone.timeZone",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
];

const timeZone = new Proxy({
getOffsetNanosecondsFor(instant) {
actual.push("call timeZone.getOffsetNanosecondsFor");
assert.sameValue(instant instanceof Temporal.Instant, true, "Instant");
return -Number(instant.epochNanoseconds % 86400_000_000_000n);
},
}, {
has(target, property) {
actual.push(`has timeZone.${property}`);
return property in target;
},
get(target, property) {
actual.push(`get timeZone.${property}`);
return target[property];
},
});

const calendar = Temporal.Calendar.from("iso8601");

const result = Temporal.Now.plainDateTime(calendar, timeZone);
for (const property of ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"]) {
assert.sameValue(result[property], 0, property);
}

assert.compareArray(actual, expected);
@@ -0,0 +1,25 @@
// Copyright (C) 2020 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.now.plaintimeiso
description: Temporal.Now.plainTimeISO.length is 0
info: |
Every built-in function object, including constructors, has a "length" property whose value is
an integer. Unless otherwise specified, this value is equal to the largest number of named
arguments shown in the subclause headings for the function description. Optional parameters
(which are indicated with brackets: [ ]) or rest parameters (which are shown using the form
«...name») are not included in the default argument count.
Unless otherwise specified, the "length" property of a built-in function object has the
attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Temporal]
---*/

verifyProperty(Temporal.Now.plainTimeISO, "length", {
value: 0,
writable: false,
enumerable: false,
configurable: true,
});

0 comments on commit 1b1e2a9

Please sign in to comment.