mirror of https://github.com/tc39/test262.git
Ensure that non-string TimeZone IDs will throw
This commit fills a test hole found by Codecov: we weren't checking for the case of a custom time zone whose `id` property returns a non-string value. Note that the `id` property is only read in a few places, all on the ZonedDateTime prototype: `until`, `since`, `equals`, `toString`, `toLocaleString`, `toJSON`, and `timeZoneId`.
This commit is contained in:
parent
92a9eca159
commit
e8bbfe704f
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2023 Justin Grant. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.equals
|
||||
description: TypeError thrown if time zone reports an id that is not a String
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
class CustomTimeZone extends Temporal.TimeZone {
|
||||
constructor(id) {
|
||||
super("UTC");
|
||||
this._id = id;
|
||||
}
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
undefined,
|
||||
null,
|
||||
true,
|
||||
-1000,
|
||||
Symbol(),
|
||||
3600_000_000_000n,
|
||||
{},
|
||||
{
|
||||
valueOf() {
|
||||
return 3600_000_000_000;
|
||||
}
|
||||
}
|
||||
].forEach((wrongId) => {
|
||||
const timeZone = new CustomTimeZone(wrongId);
|
||||
const datetime = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
assert.throws(TypeError, () => datetime.equals({ year: 1970, month: 1, day: 1, timeZone }));
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2023 Justin Grant. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.since
|
||||
description: TypeError thrown if time zone reports an id that is not a String
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
class CustomTimeZone extends Temporal.TimeZone {
|
||||
constructor(id) {
|
||||
super("UTC");
|
||||
this._id = id;
|
||||
}
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
undefined,
|
||||
null,
|
||||
true,
|
||||
-1000,
|
||||
Symbol(),
|
||||
3600_000_000_000n,
|
||||
{},
|
||||
{
|
||||
valueOf() {
|
||||
return 3600_000_000_000;
|
||||
}
|
||||
}
|
||||
].forEach((wrongId) => {
|
||||
const timeZone = new CustomTimeZone(wrongId);
|
||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
|
||||
const properties = { year: 2004, month: 11, day: 9, hour: 11, minute: 33, second: 20, timeZone };
|
||||
assert.throws(TypeError, () => datetime.since(properties, { largestUnit: "days" }));
|
||||
});
|
37
test/built-ins/Temporal/ZonedDateTime/prototype/timeZoneId/timezone-id-wrong-type.js
vendored
Normal file
37
test/built-ins/Temporal/ZonedDateTime/prototype/timeZoneId/timezone-id-wrong-type.js
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2023 Justin Grant. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.equals
|
||||
description: TypeError thrown if time zone reports an id that is not a String
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
class CustomTimeZone extends Temporal.TimeZone {
|
||||
constructor(id) {
|
||||
super("UTC");
|
||||
this._id = id;
|
||||
}
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
undefined,
|
||||
null,
|
||||
true,
|
||||
-1000,
|
||||
Symbol(),
|
||||
3600_000_000_000n,
|
||||
{},
|
||||
{
|
||||
valueOf() {
|
||||
return 3600_000_000_000;
|
||||
}
|
||||
}
|
||||
].forEach((wrongId) => {
|
||||
const timeZone = new CustomTimeZone(wrongId);
|
||||
const zdt = Temporal.ZonedDateTime.from({ year: 1970, month: 1, day: 1, timeZone });
|
||||
assert.throws(TypeError, () => zdt.timeZoneId);
|
||||
});
|
37
test/built-ins/Temporal/ZonedDateTime/prototype/toJSON/timezone-id-wrong-type.js
vendored
Normal file
37
test/built-ins/Temporal/ZonedDateTime/prototype/toJSON/timezone-id-wrong-type.js
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2023 Justin Grant. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.equals
|
||||
description: TypeError thrown if time zone reports an id that is not a String
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
class CustomTimeZone extends Temporal.TimeZone {
|
||||
constructor(id) {
|
||||
super("UTC");
|
||||
this._id = id;
|
||||
}
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
undefined,
|
||||
null,
|
||||
true,
|
||||
-1000,
|
||||
Symbol(),
|
||||
3600_000_000_000n,
|
||||
{},
|
||||
{
|
||||
valueOf() {
|
||||
return 3600_000_000_000;
|
||||
}
|
||||
}
|
||||
].forEach((wrongId) => {
|
||||
const timeZone = new CustomTimeZone(wrongId);
|
||||
const zdt = Temporal.ZonedDateTime.from({ year: 1970, month: 1, day: 1, timeZone });
|
||||
assert.throws(TypeError, () => zdt.toJSON());
|
||||
});
|
37
test/built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/timezone-id-wrong-type.js
vendored
Normal file
37
test/built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/timezone-id-wrong-type.js
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2023 Justin Grant. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.equals
|
||||
description: TypeError thrown if time zone reports an id that is not a String
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
class CustomTimeZone extends Temporal.TimeZone {
|
||||
constructor(id) {
|
||||
super("UTC");
|
||||
this._id = id;
|
||||
}
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
undefined,
|
||||
null,
|
||||
true,
|
||||
-1000,
|
||||
Symbol(),
|
||||
3600_000_000_000n,
|
||||
{},
|
||||
{
|
||||
valueOf() {
|
||||
return 3600_000_000_000;
|
||||
}
|
||||
}
|
||||
].forEach((wrongId) => {
|
||||
const timeZone = new CustomTimeZone(wrongId);
|
||||
const zdt = Temporal.ZonedDateTime.from({ year: 1970, month: 1, day: 1, timeZone });
|
||||
assert.throws(TypeError, () => zdt.toLocaleString());
|
||||
});
|
37
test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezone-id-wrong-type.js
vendored
Normal file
37
test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezone-id-wrong-type.js
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2023 Justin Grant. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.equals
|
||||
description: TypeError thrown if time zone reports an id that is not a String
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
class CustomTimeZone extends Temporal.TimeZone {
|
||||
constructor(id) {
|
||||
super("UTC");
|
||||
this._id = id;
|
||||
}
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
undefined,
|
||||
null,
|
||||
true,
|
||||
-1000,
|
||||
Symbol(),
|
||||
3600_000_000_000n,
|
||||
{},
|
||||
{
|
||||
valueOf() {
|
||||
return 3600_000_000_000;
|
||||
}
|
||||
}
|
||||
].forEach((wrongId) => {
|
||||
const timeZone = new CustomTimeZone(wrongId);
|
||||
const zdt = Temporal.ZonedDateTime.from({ year: 1970, month: 1, day: 1, timeZone });
|
||||
assert.throws(TypeError, () => zdt.toString());
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2023 Justin Grant. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.until
|
||||
description: TypeError thrown if time zone reports an id that is not a String
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
class CustomTimeZone extends Temporal.TimeZone {
|
||||
constructor(id) {
|
||||
super("UTC");
|
||||
this._id = id;
|
||||
}
|
||||
get id() {
|
||||
return this._id;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
undefined,
|
||||
null,
|
||||
true,
|
||||
-1000,
|
||||
Symbol(),
|
||||
3600_000_000_000n,
|
||||
{},
|
||||
{
|
||||
valueOf() {
|
||||
return 3600_000_000_000;
|
||||
}
|
||||
}
|
||||
].forEach((wrongId) => {
|
||||
const timeZone = new CustomTimeZone(wrongId);
|
||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
|
||||
const properties = { year: 2004, month: 11, day: 9, hour: 11, minute: 33, second: 20, timeZone };
|
||||
assert.throws(TypeError, () => datetime.until(properties, { largestUnit: "days" }));
|
||||
});
|
Loading…
Reference in New Issue