-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`.
- Loading branch information
1 parent
92a9eca
commit e8bbfe7
Showing
7 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...ns/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-id-wrong-type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 })); | ||
}); |
38 changes: 38 additions & 0 deletions
38
...ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-timezone-id-wrong-type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 37 additions & 0 deletions
37
test/built-ins/Temporal/ZonedDateTime/prototype/timeZoneId/timezone-id-wrong-type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 37 additions & 0 deletions
37
test/built-ins/Temporal/ZonedDateTime/prototype/toJSON/timezone-id-wrong-type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 37 additions & 0 deletions
37
test/built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/timezone-id-wrong-type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 37 additions & 0 deletions
37
test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezone-id-wrong-type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
}); |
38 changes: 38 additions & 0 deletions
38
...ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-timezone-id-wrong-type.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" })); | ||
}); |