diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-id-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-id-wrong-type.js new file mode 100644 index 0000000000..38883faca6 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-id-wrong-type.js @@ -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 })); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-timezone-id-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-timezone-id-wrong-type.js new file mode 100644 index 0000000000..490702bc76 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-timezone-id-wrong-type.js @@ -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" })); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/timeZoneId/timezone-id-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/timeZoneId/timezone-id-wrong-type.js new file mode 100644 index 0000000000..2301386f14 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/timeZoneId/timezone-id-wrong-type.js @@ -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); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toJSON/timezone-id-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toJSON/timezone-id-wrong-type.js new file mode 100644 index 0000000000..b6ac702a9a --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toJSON/timezone-id-wrong-type.js @@ -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()); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/timezone-id-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/timezone-id-wrong-type.js new file mode 100644 index 0000000000..8b9c856054 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/timezone-id-wrong-type.js @@ -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()); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezone-id-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezone-id-wrong-type.js new file mode 100644 index 0000000000..c2cf7f92ec --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/timezone-id-wrong-type.js @@ -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()); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-timezone-id-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-timezone-id-wrong-type.js new file mode 100644 index 0000000000..9ad8e073f9 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-timezone-id-wrong-type.js @@ -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" })); +});