diff --git a/test/built-ins/Temporal/Calendar/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/argument-wrong-type.js new file mode 100644 index 00000000000..f4fc7c41792 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/argument-wrong-type.js @@ -0,0 +1,30 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar +description: RangeError thrown when constructor invoked with the wrong type +features: [Temporal] +---*/ + +const tests = [ + [null, "null"], + [true, "boolean"], + ["", "empty string"], + [1, "number that doesn't convert to a valid ISO string"], + [19761118, "number that would convert to a valid ISO string in other contexts"], + [1n, "bigint"], + [Symbol(), "symbol"], + [{}, "object not implementing any protocol"], + [new Temporal.Calendar("iso8601"), "calendar instance"], + [new Temporal.TimeZone("UTC"), "time zone instance"], + [Temporal.ZonedDateTime.from("2020-01-01T00:00Z[UTC]"), "ZonedDateTime instance"], +]; + +for (const [arg, description] of tests) { + assert.throws( + typeof (arg) === "string" ? RangeError : TypeError, + () => new Temporal.Calendar(arg), + `${description} is not accepted by this constructor` + ); +} diff --git a/test/built-ins/Temporal/Calendar/from/calendar-number.js b/test/built-ins/Temporal/Calendar/from/calendar-number.js index b6977f2f5ac..aefa45255a2 100644 --- a/test/built-ins/Temporal/Calendar/from/calendar-number.js +++ b/test/built-ins/Temporal/Calendar/from/calendar-number.js @@ -3,25 +3,21 @@ /*--- esid: sec-temporal.calendar.from -description: A number is converted to a string, then to Temporal.Calendar +description: A number is not allowed to be a calendar features: [Temporal] ---*/ -const arg = 19761118; - -const result = Temporal.Calendar.from(arg); -assert.sameValue(result.id, "iso8601", "19761118 is a valid ISO string for Calendar"); - const numbers = [ 1, -19761118, + 19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => Temporal.Calendar.from(arg), - `Number ${arg} does not convert to a valid ISO string for Calendar` + "A number is not a valid ISO string for Calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/from/calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/from/calendar-wrong-type.js index 6a558698854..b2d24a7831d 100644 --- a/test/built-ins/Temporal/Calendar/from/calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/from/calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,8 +17,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.Calendar.from(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.Calendar.from(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/missing-arguments.js b/test/built-ins/Temporal/Calendar/missing-arguments.js index ce0dd2fdbdf..a35ab3f8d1a 100644 --- a/test/built-ins/Temporal/Calendar/missing-arguments.js +++ b/test/built-ins/Temporal/Calendar/missing-arguments.js @@ -7,5 +7,5 @@ description: RangeError thrown when constructor invoked with no argument features: [Temporal] ---*/ -assert.throws(RangeError, () => new Temporal.Calendar()); -assert.throws(RangeError, () => new Temporal.Calendar(undefined)); +assert.throws(TypeError, () => new Temporal.Calendar()); +assert.throws(TypeError, () => new Temporal.Calendar(undefined)); diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-number.js index d1ff94276db..02f745942db 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-number.js @@ -3,28 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.dateadd -description: A number is converted to a string, then to Temporal.PlainDate -includes: [temporalHelpers.js] +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.dateAdd(arg, new Temporal.Duration()); -TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.dateAdd(arg, new Temporal.Duration()), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-number.js index ca13276933b..9af992bec5f 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-number.js @@ -3,30 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.dateadd -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const instance = new Temporal.Calendar("iso8601"); - -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.dateAdd(arg, new Temporal.Duration()); -TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, "19970327 is a valid ISO string for calendar"); +const instance = new Temporal.PlainDate(1976, 11, 18); const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; - for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.dateAdd(arg, new Temporal.Duration()), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-wrong-type.js index c0632bc6d10..be4a7935ab8 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.dateAdd(arg, new Temporal.Duration()), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-wrong-type.js index adde5eb0eaf..a5730ee91d6 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.dateAdd(arg, new Temporal.Duration()), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.dateAdd(arg, new Temporal.Duration()), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-number.js index 343b06553b4..945826da088 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-number.js @@ -3,35 +3,28 @@ /*--- esid: sec-temporal.calendar.prototype.dateuntil -description: A number is converted to a string, then to Temporal.PlainDate -includes: [temporalHelpers.js] +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result1 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19)); -TemporalHelpers.assertDuration(result1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDate (first argument)"); -const result2 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg); -TemporalHelpers.assertDuration(result2, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDate (second argument)"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 18)), - `Number ${arg} does not convert to a valid ISO string for PlainDate (first argument)` + "A number is not a valid ISO string for PlainDate (first argument)" ); assert.throws( - RangeError, + TypeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 18), arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate (second argument)` + "A number is not a valid ISO string for PlainDate (second argument)" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-number.js index 9efada773e7..9a0106aaa89 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-number.js @@ -3,23 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.dateuntil -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result1 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19)); -TemporalHelpers.assertDuration(result1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (first argument)"); -const result2 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg); -TemporalHelpers.assertDuration(result2, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (second argument)"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -27,13 +19,13 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), - `Number ${calendar} does not convert to a valid ISO string for calendar (first argument)` + "A number is not a valid ISO string for calendar (first argument)" ); assert.throws( - RangeError, + TypeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), - `Number ${calendar} does not convert to a valid ISO string for calendar (second argument)` + "A number is not a valid ISO string for calendar (second argument)" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-wrong-type.js index 2ed2dbc256f..30902127664 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,10 +20,18 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `${description} does not convert to a valid ISO string (first argument)`); - assert.throws(RangeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), `${description} does not convert to a valid ISO string (second argument)`); + assert.throws( + typeof calendar === "string" ? RangeError : TypeError, + () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), + `${description} does not convert to a valid ISO string (first argument)` + ); + assert.throws( + typeof calendar === "string" ? RangeError : TypeError, + () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), + `${description} does not convert to a valid ISO string (second argument)` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-wrong-type.js index 425b3007f9f..79d344baab0 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -21,9 +21,17 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `${description} does not convert to a valid ISO string (first argument)`); - assert.throws(RangeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), `${description} does not convert to a valid ISO string (first argument)`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), + `${description} does not convert to a valid ISO string (first argument)` + ); + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), + `${description} does not convert to a valid ISO string (second argument)` + ); } const typeErrorTests = [ @@ -34,6 +42,6 @@ const typeErrorTests = [ ]; for (const [arg, description] of typeErrorTests) { - assert.throws(TypeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `${description} is not a valid property bag and does not convert to a string (second argument)`); + assert.throws(TypeError, () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), `${description} is not a valid property bag and does not convert to a string (first argument)`); assert.throws(TypeError, () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), `${description} is not a valid property bag and does not convert to a string (second argument)`); } diff --git a/test/built-ins/Temporal/Calendar/prototype/day/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/day/argument-number.js index 61562a4da60..576fa745a1c 100644 --- a/test/built-ins/Temporal/Calendar/prototype/day/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/day/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.day -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.day(arg); -assert.sameValue(result, 18, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.day(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/day/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/day/argument-propertybag-calendar-number.js index d269d715b75..728e4d36303 100644 --- a/test/built-ins/Temporal/Calendar/prototype/day/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/day/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.day -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.day(arg); -assert.sameValue(result, 18, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.day(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/day/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/day/argument-propertybag-calendar-wrong-type.js index 60436f37507..a71dcd28d6f 100644 --- a/test/built-ins/Temporal/Calendar/prototype/day/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/day/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.day(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.day(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/day/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/day/argument-wrong-type.js index 78e120896ee..cdc27390301 100644 --- a/test/built-ins/Temporal/Calendar/prototype/day/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/day/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.day(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.day(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-number.js index 026642fdee4..d9e2640c0a8 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.dayofweek -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.dayOfWeek(arg); -assert.sameValue(result, 4, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.dayOfWeek(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-propertybag-calendar-number.js index 2f63aaac8ef..9841269b65f 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.dayofweek -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.dayOfWeek(arg); -assert.sameValue(result, 4, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.dayOfWeek(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-propertybag-calendar-wrong-type.js index c06e3be28de..eea8ddc492e 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.dayOfWeek(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.dayOfWeek(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-wrong-type.js index d44886ea32d..2ffc506ca67 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.dayOfWeek(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.dayOfWeek(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-number.js index 0794df0f4c0..c147954c580 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.dayofyear -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.dayOfYear(arg); -assert.sameValue(result, 323, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.dayOfYear(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-propertybag-calendar-number.js index 0e1536d43be..1c621af7b79 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.dayofyear -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.dayOfYear(arg); -assert.sameValue(result, 323, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.dayOfYear(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-propertybag-calendar-wrong-type.js index fb9ba328058..452c1216020 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.dayOfYear(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.dayOfYear(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-wrong-type.js index e906d79bee0..bd7d078b791 100644 --- a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.dayOfYear(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.dayOfYear(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-number.js index 5020046bf4f..69a369ae85c 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.daysinmonth -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.daysInMonth(arg); -assert.sameValue(result, 30, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.daysInMonth(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-propertybag-calendar-number.js index 1f22a0391bd..fe4e8d04a62 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.daysinmonth -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.daysInMonth(arg); -assert.sameValue(result, 30, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.daysInMonth(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-propertybag-calendar-wrong-type.js index 973239dde56..45ad76393a4 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.daysInMonth(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.daysInMonth(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-wrong-type.js index 33ad7cc3b82..e41fdfe7b78 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.daysInMonth(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.daysInMonth(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-number.js index 889f44f8ba9..d6b7bb535de 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.daysinweek -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.daysInWeek(arg); -assert.sameValue(result, 7, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.daysInWeek(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-propertybag-calendar-number.js index 59d1722bae7..32f26e66e68 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.daysinweek -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.daysInWeek(arg); -assert.sameValue(result, 7, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.daysInWeek(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-propertybag-calendar-wrong-type.js index c4775217539..4a289448570 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.daysInWeek(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.daysInWeek(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-wrong-type.js index c08d2bf1330..3cdfb3c1de1 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.daysInWeek(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.daysInWeek(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-number.js index 84492ddf2bf..db378618444 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.daysinyear -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.daysInYear(arg); -assert.sameValue(result, 366, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.daysInYear(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-propertybag-calendar-number.js index 51148e0501a..2679323a38c 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.daysinyear -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.daysInYear(arg); -assert.sameValue(result, 366, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.daysInYear(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-propertybag-calendar-wrong-type.js index 269a2b866a2..5b155d42ada 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.daysInYear(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.daysInYear(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-wrong-type.js index c57754bcbfe..eec826312f6 100644 --- a/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.daysInYear(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.daysInYear(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-number.js index 1b9f0dde66a..03b89c68b98 100644 --- a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.inleapyear -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.inLeapYear(arg); -assert.sameValue(result, true, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.inLeapYear(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-propertybag-calendar-number.js index 22e411c99a1..f2010c4ccba 100644 --- a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.inleapyear -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.inLeapYear(arg); -assert.sameValue(result, true, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.inLeapYear(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-propertybag-calendar-wrong-type.js index 10f3bd720e9..6b0002ca25e 100644 --- a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.inLeapYear(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.inLeapYear(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-wrong-type.js index 02c8477cbf1..fe8718eaa2b 100644 --- a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.inLeapYear(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.inLeapYear(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/month/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/month/argument-number.js index f63c215e3d2..563801d4930 100644 --- a/test/built-ins/Temporal/Calendar/prototype/month/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/month/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.month -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.month(arg); -assert.sameValue(result, 11, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.month(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-number.js index fbb66575602..923cf5ac890 100644 --- a/test/built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.month -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.month(arg); -assert.sameValue(result, 11, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.month(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-wrong-type.js index fea4186a6bc..443a6f1d601 100644 --- a/test/built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.month(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.month(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/month/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/month/argument-wrong-type.js index deede47c06b..cff3d85132f 100644 --- a/test/built-ins/Temporal/Calendar/prototype/month/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/month/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.month(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.month(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-number.js index dfd779c38bc..038a0b6632b 100644 --- a/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.monthcode -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.monthCode(arg); -assert.sameValue(result, "M11", "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.monthCode(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-number.js index 2d44db82f79..79864d0bf7c 100644 --- a/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.monthcode -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.monthCode(arg); -assert.sameValue(result, "M11", "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.monthCode(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-wrong-type.js index 9aeba9cb55f..b75ba9606d7 100644 --- a/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.monthCode(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.monthCode(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-wrong-type.js index 939933db944..629ae17ef50 100644 --- a/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.monthCode(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.monthCode(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-number.js index 9e2513cc767..252ae005cd5 100644 --- a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.monthsinyear -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.monthsInYear(arg); -assert.sameValue(result, 12, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.monthsInYear(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-number.js index 8790243fbe1..169e31b8255 100644 --- a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.monthsinyear -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.monthsInYear(arg); -assert.sameValue(result, 12, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.monthsInYear(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-wrong-type.js index 7e8647a1d66..5ff6ccaed0b 100644 --- a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.monthsInYear(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.monthsInYear(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-wrong-type.js index 827b460413b..9e785c1fdee 100644 --- a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.monthsInYear(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.monthsInYear(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-number.js index d0259e9038c..538df916a88 100644 --- a/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.weekofyear -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.weekOfYear(arg); -assert.sameValue(result, 47, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.weekOfYear(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-propertybag-calendar-number.js index 73f81f7c8da..fa14a87025c 100644 --- a/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.weekofyear -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.weekOfYear(arg); -assert.sameValue(result, 47, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.weekOfYear(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-propertybag-calendar-wrong-type.js index f3c8160d01c..0ffb5492a60 100644 --- a/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.weekOfYear(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.weekOfYear(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-wrong-type.js index a801e6aec59..bf623233e7e 100644 --- a/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.weekOfYear(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.weekOfYear(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/year/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/year/argument-number.js index 212c2ac82e5..3b824b599af 100644 --- a/test/built-ins/Temporal/Calendar/prototype/year/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/year/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.year -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.year(arg); -assert.sameValue(result, 1976, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.year(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/year/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/year/argument-propertybag-calendar-number.js index bc475da624d..7ec6061ba06 100644 --- a/test/built-ins/Temporal/Calendar/prototype/year/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/year/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.year -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.year(arg); -assert.sameValue(result, 1976, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.year(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/year/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/year/argument-propertybag-calendar-wrong-type.js index a06cd4c751e..c6af001a5f3 100644 --- a/test/built-ins/Temporal/Calendar/prototype/year/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/year/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.year(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.year(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/year/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/year/argument-wrong-type.js index 3ffcb6becc3..8bed19608a3 100644 --- a/test/built-ins/Temporal/Calendar/prototype/year/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/year/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.year(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.year(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-number.js index fdb18c05526..ae2823d1a54 100644 --- a/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.yearofweek -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.yearOfWeek(arg); -assert.sameValue(result, 1976, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.yearOfWeek(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-propertybag-calendar-number.js index 885f48f1202..d833eaaf7c4 100644 --- a/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.yearofweek -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.yearOfWeek(arg); -assert.sameValue(result, 1976, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.yearOfWeek(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-propertybag-calendar-wrong-type.js index 9c8e0c113fc..04d7a210cbc 100644 --- a/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.yearOfWeek(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.yearOfWeek(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-wrong-type.js b/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-wrong-type.js index 1b9cb9fc985..9181113b59d 100644 --- a/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-wrong-type.js +++ b/test/built-ins/Temporal/Calendar/prototype/yearOfWeek/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.yearOfWeek(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.yearOfWeek(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Duration/compare/relativeto-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/Duration/compare/relativeto-propertybag-invalid-offset-string.js index 108c773a7b1..c1dfe588e1d 100644 --- a/test/built-ins/Temporal/Duration/compare/relativeto-propertybag-invalid-offset-string.js +++ b/test/built-ins/Temporal/Duration/compare/relativeto-propertybag-invalid-offset-string.js @@ -15,9 +15,16 @@ const badOffsets = [ "00:00", // missing sign "+0", // too short "-000:00", // too long - 0, // converts to a string that is invalid + 1000, // must be a string + null, // must be a string + true, // must be a string + 1000n, // must be a string ]; badOffsets.forEach((offset) => { const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; - assert.throws(RangeError, () => Temporal.Duration.compare(d1, d2, { relativeTo }), `"${offset} is not a valid offset string`); + assert.throws( + typeof(offset) === 'string' ? RangeError : TypeError, + () => Temporal.Duration.compare(d1, d2, { relativeTo }), + `"${offset} is not a valid offset string` + ); }); diff --git a/test/built-ins/Temporal/Duration/compare/relativeto-propertybag-timezone-wrong-type.js b/test/built-ins/Temporal/Duration/compare/relativeto-propertybag-timezone-wrong-type.js index b37aa4e60a6..a52117f0fdd 100644 --- a/test/built-ins/Temporal/Duration/compare/relativeto-propertybag-timezone-wrong-type.js +++ b/test/built-ins/Temporal/Duration/compare/relativeto-propertybag-timezone-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.Duration.compare(new Temporal.Duration(), new Temporal.Duration(), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => Temporal.Duration.compare(new Temporal.Duration(), new Temporal.Duration(), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Duration/from/argument-non-string.js b/test/built-ins/Temporal/Duration/from/argument-non-string.js index 5b5a41211c3..5c7562a4eb9 100644 --- a/test/built-ins/Temporal/Duration/from/argument-non-string.js +++ b/test/built-ins/Temporal/Duration/from/argument-non-string.js @@ -7,9 +7,9 @@ description: Appropriate error thrown if primitive input cannot convert to a val features: [Temporal] ---*/ -assert.throws(RangeError, () => Temporal.Duration.from(undefined), "undefined"); -assert.throws(RangeError, () => Temporal.Duration.from(null), "null"); -assert.throws(RangeError, () => Temporal.Duration.from(true), "boolean"); +assert.throws(TypeError, () => Temporal.Duration.from(undefined), "undefined"); +assert.throws(TypeError, () => Temporal.Duration.from(null), "null"); +assert.throws(TypeError, () => Temporal.Duration.from(true), "boolean"); assert.throws(TypeError, () => Temporal.Duration.from(Symbol()), "Symbol"); -assert.throws(RangeError, () => Temporal.Duration.from(5), "number"); -assert.throws(RangeError, () => Temporal.Duration.from(5n), "bigint"); +assert.throws(TypeError, () => Temporal.Duration.from(5), "number"); +assert.throws(TypeError, () => Temporal.Duration.from(5n), "bigint"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/argument-not-object.js b/test/built-ins/Temporal/Duration/prototype/add/argument-not-object.js index 9e96ed318aa..78e9c8d807e 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/argument-not-object.js +++ b/test/built-ins/Temporal/Duration/prototype/add/argument-not-object.js @@ -8,12 +8,12 @@ features: [Symbol, Temporal] ---*/ const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); -assert.throws(RangeError, () => instance.add(undefined), "undefined"); -assert.throws(RangeError, () => instance.add(null), "null"); -assert.throws(RangeError, () => instance.add(true), "boolean"); +assert.throws(TypeError, () => instance.add(undefined), "undefined"); +assert.throws(TypeError, () => instance.add(null), "null"); +assert.throws(TypeError, () => instance.add(true), "boolean"); assert.throws(RangeError, () => instance.add(""), "empty string"); assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); -assert.throws(RangeError, () => instance.add(7), "number"); -assert.throws(RangeError, () => instance.add(7n), "bigint"); +assert.throws(TypeError, () => instance.add(7), "number"); +assert.throws(TypeError, () => instance.add(7n), "bigint"); assert.throws(TypeError, () => instance.add([]), "array"); assert.throws(TypeError, () => instance.add(() => {}), "function"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-number.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-number.js index ecdce2d3eb6..c1da71b211d 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-number.js +++ b/test/built-ins/Temporal/Duration/prototype/add/relativeto-number.js @@ -4,7 +4,6 @@ /*--- esid: sec-temporal.duration.prototype.add description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate -includes: [temporalHelpers.js] features: [Temporal] ---*/ @@ -12,18 +11,16 @@ const instance = new Temporal.Duration(1, 0, 0, 1); const relativeTo = 20191101; -const result = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "20191101 is a valid ISO string for relativeTo"); - const numbers = [ 1, -20191101, + 20191101, 1234567890, ]; for (const relativeTo of numbers) { assert.throws( - RangeError, + TypeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), `Number ${relativeTo} does not convert to a valid ISO string for relativeTo` ); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-number.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-number.js index 73641f977d2..925d3cc3173 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-number.js @@ -4,20 +4,14 @@ /*--- esid: sec-temporal.duration.prototype.add description: A number as calendar in relativeTo property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] features: [Temporal] ---*/ const instance = new Temporal.Duration(1, 0, 0, 1); -const calendar = 19970327; - -const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; -const result = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for relativeTo.calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -25,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; assert.throws( - RangeError, + TypeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), - `Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar` + "A number is not a valid ISO string for relativeTo.calendar" ); } diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-wrong-type.js index 91cc575b54c..c916e994f78 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Duration(1, 0, 0, 1); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-invalid-offset-string.js index 3eda03336fb..17b1f87f212 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-invalid-offset-string.js +++ b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-invalid-offset-string.js @@ -14,9 +14,16 @@ const badOffsets = [ "00:00", // missing sign "+0", // too short "-000:00", // too long - 0, // converts to a string that is invalid + 0, // must be a string + null, // must be a string + true, // must be a string + 1000n, // must be a string ]; badOffsets.forEach((offset) => { const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; - assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), `"${offset} is not a valid offset string`); + assert.throws( + typeof(offset) === 'string' ? RangeError : TypeError, + () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), + `"${offset} is not a valid offset string` + ); }); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-wrong-type.js index 3b33c578509..3fb01906043 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-wrong-type.js +++ b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Duration(1); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-wrong-type.js index bead251d02d..80e7507074e 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-wrong-type.js +++ b/test/built-ins/Temporal/Duration/prototype/add/relativeto-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Duration(1, 0, 0, 1); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -21,8 +21,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [relativeTo, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), `${description} does not convert to a valid ISO string`); +for (const [relativeTo, description] of primitiveTests) { + assert.throws( + typeof relativeTo === 'string' || typeof relativeTo === 'undefined' ? RangeError : TypeError, + () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), + `${description} does not convert to a valid ISO string (first argument)` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Duration/prototype/round/relativeto-number.js b/test/built-ins/Temporal/Duration/prototype/round/relativeto-number.js index 9ec36f6775f..fef28c58c8a 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/relativeto-number.js +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-number.js @@ -4,7 +4,6 @@ /*--- esid: sec-temporal.duration.prototype.round description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate -includes: [temporalHelpers.js] features: [Temporal] ---*/ @@ -12,18 +11,16 @@ const instance = new Temporal.Duration(1, 0, 0, 0, 24); const relativeTo = 20191101; -const result = instance.round({ largestUnit: "years", relativeTo }); -TemporalHelpers.assertDuration(result, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "20191101 is a valid ISO string for relativeTo"); - const numbers = [ 1, + 20191101, -20191101, 1234567890, ]; for (const relativeTo of numbers) { assert.throws( - RangeError, + TypeError, () => instance.round({ largestUnit: "years", relativeTo }), `Number ${relativeTo} does not convert to a valid ISO string for relativeTo` ); diff --git a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-number.js b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-number.js index 682e48a490c..46cd5d4a167 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-number.js @@ -3,21 +3,15 @@ /*--- esid: sec-temporal.duration.prototype.round -description: A number as calendar in relativeTo property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in relativeTo property bag is invalid features: [Temporal] ---*/ const instance = new Temporal.Duration(1, 0, 0, 0, 24); -const calendar = 19970327; - -const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; -const result = instance.round({ largestUnit: "years", relativeTo }); -TemporalHelpers.assertDuration(result, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for relativeTo.calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -25,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; assert.throws( - RangeError, + TypeError, () => instance.round({ largestUnit: "years", relativeTo }), - `Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar` + "A number is not a valid ISO string for relativeTo.calendar" ); } diff --git a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-wrong-type.js index 0a6adffc589..ee0b727846d 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Duration(1, 0, 0, 0, 24); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.round({ largestUnit: "years", relativeTo }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-invalid-offset-string.js index 109e22b3e74..92729decd6a 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-invalid-offset-string.js +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-invalid-offset-string.js @@ -14,9 +14,16 @@ const badOffsets = [ "00:00", // missing sign "+0", // too short "-000:00", // too long - 0, // converts to a string that is invalid + 0, // must be a string + null, // must be a string + true, // must be a string + 1000n, // must be a string ]; badOffsets.forEach((offset) => { const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; - assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), `"${offset} is not a valid offset string`); + assert.throws( + typeof(offset) === 'string' ? RangeError : TypeError, + () => instance.round({ largestUnit: "years", relativeTo }), + `"${offset} is not a valid offset string` + ); }); diff --git a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-timezone-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-timezone-wrong-type.js index 8c055719610..57490a501f6 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-timezone-wrong-type.js +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Duration(1); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.round({ largestUnit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => instance.round({ largestUnit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Duration/prototype/round/relativeto-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/round/relativeto-wrong-type.js index 32fba37a5a0..d4b7af3f679 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/relativeto-wrong-type.js +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-wrong-type.js @@ -9,31 +9,39 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const timeZone = new Temporal.TimeZone("UTC"); +const timeZone = new Temporal.TimeZone('UTC'); const instance = new Temporal.Duration(1, 0, 0, 0, 24); -const rangeErrorTests = [ - [undefined, "undefined"], - [null, "null"], - [true, "boolean"], - ["", "empty string"], +const primitiveTests = [ + [undefined, 'undefined'], + [null, 'null'], + [true, 'boolean'], + ['', 'empty string'], [1, "number that doesn't convert to a valid ISO string"], - [1n, "bigint"], + [1n, 'bigint'] ]; -for (const [relativeTo, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), `${description} does not convert to a valid ISO string`); +for (const [relativeTo, description] of primitiveTests) { + assert.throws( + typeof relativeTo === 'string' || typeof relativeTo === 'undefined' ? RangeError : TypeError, + () => instance.round({ largestUnit: 'years', relativeTo }), + `${description} does not convert to a valid ISO string (first argument)` + ); } const typeErrorTests = [ - [Symbol(), "symbol"], - [{}, "plain object"], - [Temporal.PlainDate, "Temporal.PlainDate, object"], - [Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"], - [Temporal.ZonedDateTime, "Temporal.ZonedDateTime, object"], - [Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"], + [Symbol(), 'symbol'], + [{}, 'plain object'], + [Temporal.PlainDate, 'Temporal.PlainDate, object'], + [Temporal.PlainDate.prototype, 'Temporal.PlainDate.prototype, object'], + [Temporal.ZonedDateTime, 'Temporal.ZonedDateTime, object'], + [Temporal.ZonedDateTime.prototype, 'Temporal.ZonedDateTime.prototype, object'] ]; for (const [relativeTo, description] of typeErrorTests) { - assert.throws(TypeError, () => instance.round({ largestUnit: "years", relativeTo }), `${description} is not a valid property bag and does not convert to a string`); + assert.throws( + TypeError, + () => instance.round({ largestUnit: 'years', relativeTo }), + `${description} is not a valid property bag and does not convert to a string` + ); } diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/argument-not-object.js b/test/built-ins/Temporal/Duration/prototype/subtract/argument-not-object.js index 813213c210e..ae78dbfc6eb 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/argument-not-object.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/argument-not-object.js @@ -8,12 +8,12 @@ features: [Symbol, Temporal] ---*/ const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); -assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); -assert.throws(RangeError, () => instance.subtract(null), "null"); -assert.throws(RangeError, () => instance.subtract(true), "boolean"); +assert.throws(TypeError, () => instance.subtract(undefined), "undefined"); +assert.throws(TypeError, () => instance.subtract(null), "null"); +assert.throws(TypeError, () => instance.subtract(true), "boolean"); assert.throws(RangeError, () => instance.subtract(""), "empty string"); assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); -assert.throws(RangeError, () => instance.subtract(7), "number"); -assert.throws(RangeError, () => instance.subtract(7n), "bigint"); +assert.throws(TypeError, () => instance.subtract(7), "number"); +assert.throws(TypeError, () => instance.subtract(7n), "bigint"); assert.throws(TypeError, () => instance.subtract([]), "array"); assert.throws(TypeError, () => instance.subtract(() => {}), "function"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-number.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-number.js index 40d11706650..05b38ccd46e 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-number.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-number.js @@ -4,7 +4,6 @@ /*--- esid: sec-temporal.duration.prototype.subtract description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate -includes: [temporalHelpers.js] features: [Temporal] ---*/ @@ -12,18 +11,16 @@ const instance = new Temporal.Duration(1, 0, 0, 1); const relativeTo = 20191101; -const result = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "20191101 is a valid ISO string for relativeTo"); - const numbers = [ 1, + 20191101, -20191101, 1234567890, ]; for (const relativeTo of numbers) { assert.throws( - RangeError, + TypeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), `Number ${relativeTo} does not convert to a valid ISO string for relativeTo` ); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-number.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-number.js index ff3b452eb29..0c21296c7a6 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-number.js @@ -3,8 +3,7 @@ /*--- esid: sec-temporal.duration.prototype.subtract -description: A number as calendar in relativeTo property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in relativeTo property bag is invalid features: [Temporal] ---*/ @@ -12,12 +11,9 @@ const instance = new Temporal.Duration(1, 0, 0, 1); const calendar = 19970327; -const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; -const result = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for relativeTo.calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -25,8 +21,8 @@ const numbers = [ for (const calendar of numbers) { const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; assert.throws( - RangeError, + TypeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), - `Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar` + "A number is not a valid ISO string for relativeTo.calendar" ); } diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-wrong-type.js index 5a9b7ca1278..120b8925c5a 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Duration(1, 0, 0, 1); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-invalid-offset-string.js index 8043830d667..9f16c9f60e3 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-invalid-offset-string.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-invalid-offset-string.js @@ -14,9 +14,16 @@ const badOffsets = [ "00:00", // missing sign "+0", // too short "-000:00", // too long - 0, // converts to a string that is invalid + 0, // must be a string + null, // must be a string + true, // must be a string + 1000n, // must be a string ]; badOffsets.forEach((offset) => { const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; - assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), `"${offset} is not a valid offset string`); + assert.throws( + typeof(offset) === 'string' ? RangeError : TypeError, + () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), + { relativeTo }), `"${offset} is not a valid offset string` + ); }); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-wrong-type.js index 61ad351a607..53eb7876073 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-wrong-type.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Duration(1); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-wrong-type.js index 45118c033d9..343fe7b182a 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-wrong-type.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-wrong-type.js @@ -9,31 +9,39 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const timeZone = new Temporal.TimeZone("UTC"); +const timeZone = new Temporal.TimeZone('UTC'); const instance = new Temporal.Duration(1, 0, 0, 1); -const rangeErrorTests = [ - [undefined, "undefined"], - [null, "null"], - [true, "boolean"], - ["", "empty string"], +const primitiveTests = [ + [undefined, 'undefined'], + [null, 'null'], + [true, 'boolean'], + ['', 'empty string'], [1, "number that doesn't convert to a valid ISO string"], - [1n, "bigint"], + [1n, 'bigint'] ]; -for (const [relativeTo, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), `${description} does not convert to a valid ISO string`); +for (const [relativeTo, description] of primitiveTests) { + assert.throws( + typeof relativeTo === 'string' || typeof relativeTo === 'undefined' ? RangeError : TypeError, + () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), + `${description} does not convert to a valid ISO string (first argument)` + ); } const typeErrorTests = [ - [Symbol(), "symbol"], - [{}, "plain object"], - [Temporal.PlainDate, "Temporal.PlainDate, object"], - [Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"], - [Temporal.ZonedDateTime, "Temporal.ZonedDateTime, object"], - [Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"], + [Symbol(), 'symbol'], + [{}, 'plain object'], + [Temporal.PlainDate, 'Temporal.PlainDate, object'], + [Temporal.PlainDate.prototype, 'Temporal.PlainDate.prototype, object'], + [Temporal.ZonedDateTime, 'Temporal.ZonedDateTime, object'], + [Temporal.ZonedDateTime.prototype, 'Temporal.ZonedDateTime.prototype, object'] ]; for (const [relativeTo, description] of typeErrorTests) { - assert.throws(TypeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), `${description} is not a valid property bag and does not convert to a string`); + assert.throws( + TypeError, + () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), + `${description} is not a valid property bag and does not convert to a string` + ); } diff --git a/test/built-ins/Temporal/Duration/prototype/total/relativeto-number.js b/test/built-ins/Temporal/Duration/prototype/total/relativeto-number.js index 6825c00ce43..c96fce82d1a 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/relativeto-number.js +++ b/test/built-ins/Temporal/Duration/prototype/total/relativeto-number.js @@ -11,18 +11,16 @@ const instance = new Temporal.Duration(1, 0, 0, 0, 24); const relativeTo = 20191101; -const result = instance.total({ unit: "days", relativeTo }); -assert.sameValue(result, 367, "20191101 is a valid ISO string for relativeTo"); - const numbers = [ 1, + 20191101, -20191101, 1234567890, ]; for (const relativeTo of numbers) { assert.throws( - RangeError, + TypeError, () => instance.total({ unit: "days", relativeTo }), `Number ${relativeTo} does not convert to a valid ISO string for relativeTo` ); diff --git a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-number.js b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-number.js index 6633ab616cd..9a7ecee7542 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.duration.prototype.total -description: A number as calendar in relativeTo property bag is converted to a string, then to a calendar +description: A number as calendar in relativeTo property bag is invalid features: [Temporal] ---*/ const instance = new Temporal.Duration(1, 0, 0, 0, 24); -const calendar = 19970327; - -const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; -const result = instance.total({ unit: "days", relativeTo }); -assert.sameValue(result, 367, "19970327 is a valid ISO string for relativeTo.calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; assert.throws( - RangeError, + TypeError, () => instance.total({ unit: "days", relativeTo }), - `Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar` + "A number is not a valid ISO string for relativeTo.calendar" ); } diff --git a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-wrong-type.js index a495c04dd01..aba5db54ef0 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Duration(1, 0, 0, 0, 24); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.total({ unit: "days", relativeTo }), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.total({ unit: "days", relativeTo }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-invalid-offset-string.js index a36594be83f..50b44cb62a7 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-invalid-offset-string.js +++ b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-invalid-offset-string.js @@ -14,9 +14,16 @@ const badOffsets = [ "00:00", // missing sign "+0", // too short "-000:00", // too long - 0, // converts to a string that is invalid + 0, // must be a string + null, // must be a string + true, // must be a string + 1000n, // must be a string ]; badOffsets.forEach((offset) => { const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; - assert.throws(RangeError, () => instance.total({ unit: "days", relativeTo }), `"${offset} is not a valid offset string`); + assert.throws( + typeof(offset) === 'string' ? RangeError : TypeError, + () => instance.total({ unit: "days", relativeTo }), + `"${offset} is not a valid offset string` + ); }); diff --git a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-timezone-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-timezone-wrong-type.js index b19bec2af7a..86548389775 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-timezone-wrong-type.js +++ b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Duration(1); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.total({ unit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => instance.total({ unit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Duration/prototype/total/relativeto-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/total/relativeto-wrong-type.js index 84d4d889abf..d90ba1dc141 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/relativeto-wrong-type.js +++ b/test/built-ins/Temporal/Duration/prototype/total/relativeto-wrong-type.js @@ -9,31 +9,39 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const timeZone = new Temporal.TimeZone("UTC"); +const timeZone = new Temporal.TimeZone('UTC'); const instance = new Temporal.Duration(1, 0, 0, 0, 24); -const rangeErrorTests = [ - [undefined, "undefined"], - [null, "null"], - [true, "boolean"], - ["", "empty string"], +const primitiveTests = [ + [undefined, 'undefined'], + [null, 'null'], + [true, 'boolean'], + ['', 'empty string'], [1, "number that doesn't convert to a valid ISO string"], - [1n, "bigint"], + [1n, 'bigint'] ]; -for (const [relativeTo, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.total({ unit: "days", relativeTo }), `${description} does not convert to a valid ISO string`); +for (const [relativeTo, description] of primitiveTests) { + assert.throws( + typeof relativeTo === 'string' || typeof relativeTo === 'undefined' ? RangeError : TypeError, + () => instance.total({ unit: 'days', relativeTo }), + `${description} does not convert to a valid ISO string (first argument)` + ); } const typeErrorTests = [ - [Symbol(), "symbol"], - [{}, "plain object"], - [Temporal.PlainDate, "Temporal.PlainDate, object"], - [Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"], - [Temporal.ZonedDateTime, "Temporal.ZonedDateTime, object"], - [Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"], + [Symbol(), 'symbol'], + [{}, 'plain object'], + [Temporal.PlainDate, 'Temporal.PlainDate, object'], + [Temporal.PlainDate.prototype, 'Temporal.PlainDate.prototype, object'], + [Temporal.ZonedDateTime, 'Temporal.ZonedDateTime, object'], + [Temporal.ZonedDateTime.prototype, 'Temporal.ZonedDateTime.prototype, object'] ]; for (const [relativeTo, description] of typeErrorTests) { - assert.throws(TypeError, () => instance.total({ unit: "days", relativeTo }), `${description} is not a valid property bag and does not convert to a string`); + assert.throws( + TypeError, + () => instance.total({ unit: 'days', relativeTo }), + `${description} is not a valid property bag and does not convert to a string` + ); } diff --git a/test/built-ins/Temporal/Instant/compare/argument-wrong-type.js b/test/built-ins/Temporal/Instant/compare/argument-wrong-type.js index cf4c5931bf9..849636f4670 100644 --- a/test/built-ins/Temporal/Instant/compare/argument-wrong-type.js +++ b/test/built-ins/Temporal/Instant/compare/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const other = new Temporal.Instant(0n); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,20 +20,40 @@ const rangeErrorTests = [ [19761118, "number that would convert to a valid ISO string in other contexts"], [1n, "bigint"], [{}, "plain object"], - [Temporal.Instant, "Temporal.Instant, object"], + [Temporal.Instant, "Temporal.Instant, object"] ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.Instant.compare(arg, other), `${description} does not convert to a valid ISO string (first argument)`); - assert.throws(RangeError, () => Temporal.Instant.compare(other, arg), `${description} does not convert to a valid ISO string (second argument)`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === "string" || (typeof arg === "object" && arg !== null) || typeof arg === "function" + ? RangeError + : TypeError, + () => Temporal.Instant.compare(arg, other), + `${description} does not convert to a valid ISO string (first argument)` + ); + assert.throws( + typeof arg === "string" || (typeof arg === "object" && arg !== null) || typeof arg === "function" + ? RangeError + : TypeError, + () => Temporal.Instant.compare(other, arg), + `${description} does not convert to a valid ISO string (second argument)` + ); } const typeErrorTests = [ [Symbol(), "symbol"], - [Temporal.Instant.prototype, "Temporal.Instant.prototype, object"], // fails brand check in toString() + [Temporal.Instant.prototype, "Temporal.Instant.prototype, object"] // fails brand check in toString() ]; for (const [arg, description] of typeErrorTests) { - assert.throws(TypeError, () => Temporal.Instant.compare(arg, other), `${description} does not convert to a string (first argument)`); - assert.throws(TypeError, () => Temporal.Instant.compare(other, arg), `${description} does not convert to a string (second argument)`); + assert.throws( + TypeError, + () => Temporal.Instant.compare(arg, other), + `${description} does not convert to a string (first argument)` + ); + assert.throws( + TypeError, + () => Temporal.Instant.compare(other, arg), + `${description} does not convert to a string (second argument)` + ); } diff --git a/test/built-ins/Temporal/Instant/from/argument-wrong-type.js b/test/built-ins/Temporal/Instant/from/argument-wrong-type.js index ec746029317..606729da451 100644 --- a/test/built-ins/Temporal/Instant/from/argument-wrong-type.js +++ b/test/built-ins/Temporal/Instant/from/argument-wrong-type.js @@ -9,25 +9,31 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ - [undefined, "undefined"], - [null, "null"], - [true, "boolean"], - ["", "empty string"], +const primitiveTests = [ + [undefined, 'undefined'], + [null, 'null'], + [true, 'boolean'], + ['', 'empty string'], [1, "number that doesn't convert to a valid ISO string"], - [19761118, "number that would convert to a valid ISO string in other contexts"], - [1n, "bigint"], - [{}, "plain object"], - [Temporal.Instant, "Temporal.Instant, object"], + [19761118, 'number that would convert to a valid ISO string in other contexts'], + [1n, 'bigint'], + [{}, 'plain object'], + [Temporal.Instant, 'Temporal.Instant, object'] ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.Instant.from(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' || (typeof arg === 'object' && arg !== null) || typeof arg === 'function' + ? RangeError + : TypeError, + () => Temporal.Instant.from(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ - [Symbol(), "symbol"], - [Temporal.Instant.prototype, "Temporal.Instant.prototype, object"], // fails brand check in toString() + [Symbol(), 'symbol'], + [Temporal.Instant.prototype, 'Temporal.Instant.prototype, object'] // fails brand check in toString() ]; for (const [arg, description] of typeErrorTests) { diff --git a/test/built-ins/Temporal/Instant/prototype/add/argument-not-object.js b/test/built-ins/Temporal/Instant/prototype/add/argument-not-object.js index 6e7f79c57e5..08de0898ef2 100644 --- a/test/built-ins/Temporal/Instant/prototype/add/argument-not-object.js +++ b/test/built-ins/Temporal/Instant/prototype/add/argument-not-object.js @@ -8,12 +8,12 @@ features: [Symbol, Temporal] ---*/ const instance = new Temporal.Instant(1_000_000_000_000_000_000n); -assert.throws(RangeError, () => instance.add(undefined), "undefined"); -assert.throws(RangeError, () => instance.add(null), "null"); -assert.throws(RangeError, () => instance.add(true), "boolean"); +assert.throws(TypeError, () => instance.add(undefined), "undefined"); +assert.throws(TypeError, () => instance.add(null), "null"); +assert.throws(TypeError, () => instance.add(true), "boolean"); assert.throws(RangeError, () => instance.add(""), "empty string"); assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); -assert.throws(RangeError, () => instance.add(7), "number"); -assert.throws(RangeError, () => instance.add(7n), "bigint"); +assert.throws(TypeError, () => instance.add(7), "number"); +assert.throws(TypeError, () => instance.add(7n), "bigint"); assert.throws(TypeError, () => instance.add([]), "array"); assert.throws(TypeError, () => instance.add(() => {}), "function"); diff --git a/test/built-ins/Temporal/Instant/prototype/equals/argument-wrong-type.js b/test/built-ins/Temporal/Instant/prototype/equals/argument-wrong-type.js index d195169c908..11b32c24d81 100644 --- a/test/built-ins/Temporal/Instant/prototype/equals/argument-wrong-type.js +++ b/test/built-ins/Temporal/Instant/prototype/equals/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Instant(0n); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -23,8 +23,14 @@ const rangeErrorTests = [ [Temporal.Instant, "Temporal.Instant, object"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.equals(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === "string" || (typeof arg === "object" && arg !== null) || typeof arg === "function" + ? RangeError + : TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Instant/prototype/since/argument-wrong-type.js b/test/built-ins/Temporal/Instant/prototype/since/argument-wrong-type.js index 499623d4f76..78c286b3d16 100644 --- a/test/built-ins/Temporal/Instant/prototype/since/argument-wrong-type.js +++ b/test/built-ins/Temporal/Instant/prototype/since/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Instant(0n); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -23,8 +23,14 @@ const rangeErrorTests = [ [Temporal.Instant, "Temporal.Instant, object"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.since(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === "string" || (typeof arg === "object" && arg !== null) || typeof arg === "function" + ? RangeError + : TypeError, + () => instance.since(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Instant/prototype/subtract/argument-not-object.js b/test/built-ins/Temporal/Instant/prototype/subtract/argument-not-object.js index af8fd963c8e..bb064491794 100644 --- a/test/built-ins/Temporal/Instant/prototype/subtract/argument-not-object.js +++ b/test/built-ins/Temporal/Instant/prototype/subtract/argument-not-object.js @@ -8,12 +8,12 @@ features: [Symbol, Temporal] ---*/ const instance = new Temporal.Instant(1_000_000_000_000_000_000n); -assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); -assert.throws(RangeError, () => instance.subtract(null), "null"); -assert.throws(RangeError, () => instance.subtract(true), "boolean"); +assert.throws(TypeError, () => instance.subtract(undefined), "undefined"); +assert.throws(TypeError, () => instance.subtract(null), "null"); +assert.throws(TypeError, () => instance.subtract(true), "boolean"); assert.throws(RangeError, () => instance.subtract(""), "empty string"); assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); -assert.throws(RangeError, () => instance.subtract(7), "number"); -assert.throws(RangeError, () => instance.subtract(7n), "bigint"); +assert.throws(TypeError, () => instance.subtract(7), "number"); +assert.throws(TypeError, () => instance.subtract(7n), "bigint"); assert.throws(TypeError, () => instance.subtract([]), "array"); assert.throws(TypeError, () => instance.subtract(() => {}), "function"); diff --git a/test/built-ins/Temporal/Instant/prototype/toString/timezone-wrong-type.js b/test/built-ins/Temporal/Instant/prototype/toString/timezone-wrong-type.js index 7ca0cc0a2d6..c7ed824feaa 100644 --- a/test/built-ins/Temporal/Instant/prototype/toString/timezone-wrong-type.js +++ b/test/built-ins/Temporal/Instant/prototype/toString/timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Instant(0n); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.toString({ timeZone }), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => instance.toString({ timeZone }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/calendar-number.js b/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/calendar-number.js index 21a496debea..4e8bf461b24 100644 --- a/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/calendar-number.js +++ b/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/calendar-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.instant.prototype.tozoneddatetime -description: A number is converted to a string, then to Temporal.Calendar +description: A number is not allowed to be a calendar features: [Temporal] ---*/ const instance = new Temporal.Instant(1_000_000_000_000_000_000n); -const arg = 19761118; - -const result = instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" }); -assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar"); - const numbers = [ 1, -19761118, + 19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" }), - `Number ${arg} does not convert to a valid ISO string for Calendar` + "A number is not a valid ISO string for Calendar" ); } diff --git a/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/calendar-wrong-type.js b/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/calendar-wrong-type.js index 515f292b0ea..ae69f1c28d9 100644 --- a/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/calendar-wrong-type.js +++ b/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/calendar-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Instant(1_000_000_000_000_000_000n); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -19,8 +19,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" }), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/timezone-wrong-type.js b/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/timezone-wrong-type.js index 0b3dd555e86..ae088849314 100644 --- a/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/timezone-wrong-type.js +++ b/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Instant(0n); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.toZonedDateTime({ timeZone, calendar: "iso8601" }), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => instance.toZonedDateTime({ timeZone, calendar: "iso8601" }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-wrong-type.js b/test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-wrong-type.js index 7f09d939a8e..f6b83f9481d 100644 --- a/test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-wrong-type.js +++ b/test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Instant(0n); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.toZonedDateTimeISO(timeZone), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => instance.toZonedDateTimeISO(timeZone), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Instant/prototype/until/argument-wrong-type.js b/test/built-ins/Temporal/Instant/prototype/until/argument-wrong-type.js index a4de0bae40d..8f62ecc5042 100644 --- a/test/built-ins/Temporal/Instant/prototype/until/argument-wrong-type.js +++ b/test/built-ins/Temporal/Instant/prototype/until/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Instant(0n); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -23,8 +23,14 @@ const rangeErrorTests = [ [Temporal.Instant, "Temporal.Instant, object"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.until(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === "string" || (typeof arg === "object" && arg !== null) || typeof arg === "function" + ? RangeError + : TypeError, + () => instance.until(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Now/plainDate/calendar-number.js b/test/built-ins/Temporal/Now/plainDate/calendar-number.js index a82a0f8c072..1858e009405 100644 --- a/test/built-ins/Temporal/Now/plainDate/calendar-number.js +++ b/test/built-ins/Temporal/Now/plainDate/calendar-number.js @@ -3,25 +3,21 @@ /*--- esid: sec-temporal.now.plaindate -description: A number is converted to a string, then to Temporal.Calendar +description: A number is not allowed to be a calendar features: [Temporal] ---*/ -const arg = 19761118; - -const result = Temporal.Now.plainDate(arg); -assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar"); - const numbers = [ 1, -19761118, + 19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => Temporal.Now.plainDate(arg), - `Number ${arg} does not convert to a valid ISO string for Calendar` + "A number is not a valid ISO string for Calendar" ); } diff --git a/test/built-ins/Temporal/Now/plainDate/calendar-undefined.js b/test/built-ins/Temporal/Now/plainDate/calendar-undefined.js index d2a5cecd2d0..8ebfe37d343 100644 --- a/test/built-ins/Temporal/Now/plainDate/calendar-undefined.js +++ b/test/built-ins/Temporal/Now/plainDate/calendar-undefined.js @@ -7,5 +7,5 @@ description: Throws when the calendar argument is undefined features: [Temporal] ---*/ -assert.throws(RangeError, () => Temporal.Now.plainDate(), "implicit"); -assert.throws(RangeError, () => Temporal.Now.plainDate(undefined), "implicit"); +assert.throws(TypeError, () => Temporal.Now.plainDate(), "implicit"); +assert.throws(TypeError, () => Temporal.Now.plainDate(undefined), "implicit"); diff --git a/test/built-ins/Temporal/Now/plainDate/calendar-wrong-type.js b/test/built-ins/Temporal/Now/plainDate/calendar-wrong-type.js index e45fa6a81b5..867da7e7595 100644 --- a/test/built-ins/Temporal/Now/plainDate/calendar-wrong-type.js +++ b/test/built-ins/Temporal/Now/plainDate/calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,8 +17,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.Now.plainDate(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.Now.plainDate(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Now/plainDate/timezone-wrong-type.js b/test/built-ins/Temporal/Now/plainDate/timezone-wrong-type.js index 18ec9b628e3..6480a237192 100644 --- a/test/built-ins/Temporal/Now/plainDate/timezone-wrong-type.js +++ b/test/built-ins/Temporal/Now/plainDate/timezone-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.Now.plainDate("iso8601", timeZone), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => Temporal.Now.plainDate("iso8601", timeZone), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Now/plainDateISO/timezone-wrong-type.js b/test/built-ins/Temporal/Now/plainDateISO/timezone-wrong-type.js index 1478b5303ab..92d84f597b6 100644 --- a/test/built-ins/Temporal/Now/plainDateISO/timezone-wrong-type.js +++ b/test/built-ins/Temporal/Now/plainDateISO/timezone-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.Now.plainDateISO(timeZone), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => Temporal.Now.plainDateISO(timeZone), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Now/plainDateTime/calendar-number.js b/test/built-ins/Temporal/Now/plainDateTime/calendar-number.js index 57d2e796728..93e7d6f3644 100644 --- a/test/built-ins/Temporal/Now/plainDateTime/calendar-number.js +++ b/test/built-ins/Temporal/Now/plainDateTime/calendar-number.js @@ -3,25 +3,21 @@ /*--- esid: sec-temporal.now.plaindatetime -description: A number is converted to a string, then to Temporal.Calendar +description: A number is not allowed to be a calendar features: [Temporal] ---*/ -const arg = 19761118; - -const result = Temporal.Now.plainDateTime(arg); -assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar"); - const numbers = [ 1, -19761118, + 19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => Temporal.Now.plainDateTime(arg), - `Number ${arg} does not convert to a valid ISO string for Calendar` + "A number is not a valid ISO string for Calendar" ); } diff --git a/test/built-ins/Temporal/Now/plainDateTime/calendar-undefined.js b/test/built-ins/Temporal/Now/plainDateTime/calendar-undefined.js index 6a2784051b4..6e3c60f55a0 100644 --- a/test/built-ins/Temporal/Now/plainDateTime/calendar-undefined.js +++ b/test/built-ins/Temporal/Now/plainDateTime/calendar-undefined.js @@ -7,5 +7,5 @@ description: Throws when the calendar argument is undefined features: [Temporal] ---*/ -assert.throws(RangeError, () => Temporal.Now.plainDateTime(), "implicit"); -assert.throws(RangeError, () => Temporal.Now.plainDateTime(undefined), "implicit"); +assert.throws(TypeError, () => Temporal.Now.plainDateTime(), "implicit"); +assert.throws(TypeError, () => Temporal.Now.plainDateTime(undefined), "implicit"); diff --git a/test/built-ins/Temporal/Now/plainDateTime/calendar-wrong-type.js b/test/built-ins/Temporal/Now/plainDateTime/calendar-wrong-type.js index aa561c82c5b..b94c5d048ee 100644 --- a/test/built-ins/Temporal/Now/plainDateTime/calendar-wrong-type.js +++ b/test/built-ins/Temporal/Now/plainDateTime/calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,8 +17,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.Now.plainDateTime(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.Now.plainDateTime(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Now/plainDateTime/timezone-wrong-type.js b/test/built-ins/Temporal/Now/plainDateTime/timezone-wrong-type.js index d68dc04aa01..fb3b647be0f 100644 --- a/test/built-ins/Temporal/Now/plainDateTime/timezone-wrong-type.js +++ b/test/built-ins/Temporal/Now/plainDateTime/timezone-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.Now.plainDateTime("iso8601", timeZone), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => Temporal.Now.plainDateTime("iso8601", timeZone), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-wrong-type.js b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-wrong-type.js index 5fde195e2a0..ceefe1ca645 100644 --- a/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-wrong-type.js +++ b/test/built-ins/Temporal/Now/plainDateTimeISO/timezone-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.Now.plainDateTimeISO(timeZone), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => Temporal.Now.plainDateTimeISO(timeZone), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Now/plainTimeISO/timezone-wrong-type.js b/test/built-ins/Temporal/Now/plainTimeISO/timezone-wrong-type.js index 09be7bb6964..11458e6061f 100644 --- a/test/built-ins/Temporal/Now/plainTimeISO/timezone-wrong-type.js +++ b/test/built-ins/Temporal/Now/plainTimeISO/timezone-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.Now.plainTimeISO(timeZone), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => Temporal.Now.plainTimeISO(timeZone), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Now/zonedDateTime/calendar-number.js b/test/built-ins/Temporal/Now/zonedDateTime/calendar-number.js index 6a6578db32b..ad7789ffafa 100644 --- a/test/built-ins/Temporal/Now/zonedDateTime/calendar-number.js +++ b/test/built-ins/Temporal/Now/zonedDateTime/calendar-number.js @@ -3,25 +3,21 @@ /*--- esid: sec-temporal.now.zoneddatetime -description: A number is converted to a string, then to Temporal.Calendar +description: A number is not allowed to be a calendar features: [Temporal] ---*/ -const arg = 19761118; - -const result = Temporal.Now.zonedDateTime(arg); -assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar"); - const numbers = [ 1, -19761118, + 19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => Temporal.Now.zonedDateTime(arg), - `Number ${arg} does not convert to a valid ISO string for Calendar` + "A number is not a valid ISO string for Calendar" ); } diff --git a/test/built-ins/Temporal/Now/zonedDateTime/calendar-undefined.js b/test/built-ins/Temporal/Now/zonedDateTime/calendar-undefined.js index ddcc4bb7883..9f48bf6fe36 100644 --- a/test/built-ins/Temporal/Now/zonedDateTime/calendar-undefined.js +++ b/test/built-ins/Temporal/Now/zonedDateTime/calendar-undefined.js @@ -7,5 +7,5 @@ description: Throws when the calendar argument is undefined features: [Temporal] ---*/ -assert.throws(RangeError, () => Temporal.Now.zonedDateTime(), "implicit"); -assert.throws(RangeError, () => Temporal.Now.zonedDateTime(undefined), "implicit"); +assert.throws(TypeError, () => Temporal.Now.zonedDateTime(), "implicit"); +assert.throws(TypeError, () => Temporal.Now.zonedDateTime(undefined), "implicit"); diff --git a/test/built-ins/Temporal/Now/zonedDateTime/calendar-wrong-type.js b/test/built-ins/Temporal/Now/zonedDateTime/calendar-wrong-type.js index ce7bbc1b791..3f0004b9fcf 100644 --- a/test/built-ins/Temporal/Now/zonedDateTime/calendar-wrong-type.js +++ b/test/built-ins/Temporal/Now/zonedDateTime/calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,8 +17,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.Now.zonedDateTime(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.Now.zonedDateTime(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Now/zonedDateTime/timezone-wrong-type.js b/test/built-ins/Temporal/Now/zonedDateTime/timezone-wrong-type.js index 12fd8c4204c..d2e1c95cbd3 100644 --- a/test/built-ins/Temporal/Now/zonedDateTime/timezone-wrong-type.js +++ b/test/built-ins/Temporal/Now/zonedDateTime/timezone-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.Now.zonedDateTime("iso8601", timeZone), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => Temporal.Now.zonedDateTime("iso8601", timeZone), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/Now/zonedDateTimeISO/timezone-wrong-type.js b/test/built-ins/Temporal/Now/zonedDateTimeISO/timezone-wrong-type.js index 5b75622ed16..d3475fd48e3 100644 --- a/test/built-ins/Temporal/Now/zonedDateTimeISO/timezone-wrong-type.js +++ b/test/built-ins/Temporal/Now/zonedDateTimeISO/timezone-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.Now.zonedDateTimeISO(timeZone), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => Temporal.Now.zonedDateTimeISO(timeZone), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/calendar-number.js b/test/built-ins/Temporal/PlainDate/calendar-number.js index be222b1c4c2..59ccc266149 100644 --- a/test/built-ins/Temporal/PlainDate/calendar-number.js +++ b/test/built-ins/Temporal/PlainDate/calendar-number.js @@ -3,25 +3,21 @@ /*--- esid: sec-temporal.plaindate -description: A number is converted to a string, then to Temporal.Calendar +description: A number is not allowed to be a calendar features: [Temporal] ---*/ -const arg = 19761118; - -const result = new Temporal.PlainDate(2000, 5, 2, arg); -assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar"); - const numbers = [ 1, -19761118, + 19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => new Temporal.PlainDate(2000, 5, 2, arg), - `Number ${arg} does not convert to a valid ISO string for Calendar` + "A number is not a valid ISO string for Calendar" ); } diff --git a/test/built-ins/Temporal/PlainDate/calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/calendar-wrong-type.js index f79b226b84f..294267ecba4 100644 --- a/test/built-ins/Temporal/PlainDate/calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,8 +17,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => new Temporal.PlainDate(2000, 5, 2, arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => new Temporal.PlainDate(2000, 5, 2, arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/compare/argument-number.js b/test/built-ins/Temporal/PlainDate/compare/argument-number.js index cf93daf7a16..dd48fcb028c 100644 --- a/test/built-ins/Temporal/PlainDate/compare/argument-number.js +++ b/test/built-ins/Temporal/PlainDate/compare/argument-number.js @@ -3,32 +3,26 @@ /*--- esid: sec-temporal.plaindate.compare -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ -const arg = 19761118; - -const result1 = Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)); -assert.sameValue(result1, 0, "19761118 is a valid ISO string for PlainDate (first argument)"); -const result2 = Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg); -assert.sameValue(result2, 0, "19761118 is a valid ISO string for PlainDate (second argument)"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), - `Number ${arg} does not convert to a valid ISO string for PlainDate (first argument)` + "A number is not a valid ISO string for PlainDate (first argument)" ); assert.throws( - RangeError, + TypeError, () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate (second argument)` + "A number is not a valid ISO string for PlainDate (second argument)" ); } diff --git a/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-number.js index 6e85dcc654d..12475bcdb9e 100644 --- a/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-number.js @@ -3,20 +3,13 @@ /*--- esid: sec-temporal.plaindate.compare -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result1 = Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)); -assert.sameValue(result1, 0, "19970327 is a valid ISO string for calendar (first argument)"); -const result2 = Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg); -assert.sameValue(result2, 0, "19970327 is a valid ISO string for calendar (first argument)"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,13 +17,13 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), - `Number ${calendar} does not convert to a valid ISO string for calendar (first argument)` + "A number is not a valid ISO string for calendar (first argument)" ); assert.throws( - RangeError, + TypeError, () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), - `Number ${calendar} does not convert to a valid ISO string for calendar (second argument)` + "A number is not a valid ISO string for calendar (second argument)" ); } diff --git a/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-wrong-type.js index 964b88e9d83..d2181107483 100644 --- a/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,10 +17,18 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), `${description} does not convert to a valid ISO string (first argument)`); - assert.throws(RangeError, () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), `${description} does not convert to a valid ISO string (second argument)`); + assert.throws( + typeof calendar === "string" ? RangeError : TypeError, + () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), + `${description} does not convert to a valid ISO string (first argument)` + ); + assert.throws( + typeof calendar === "string" ? RangeError : TypeError, + () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), + `${description} does not convert to a valid ISO string (second argument)` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/compare/argument-wrong-type.js b/test/built-ins/Temporal/PlainDate/compare/argument-wrong-type.js index c25dc6772b1..11a1a3993b0 100644 --- a/test/built-ins/Temporal/PlainDate/compare/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/compare/argument-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -18,9 +18,17 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), `${description} does not convert to a valid ISO string (first argument)`); - assert.throws(RangeError, () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), `${description} does not convert to a valid ISO string (second argument)`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), + `${description} does not convert to a valid ISO string (first argument)` + ); + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), + `${description} does not convert to a valid ISO string (second argument)` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/from/argument-number.js b/test/built-ins/Temporal/PlainDate/from/argument-number.js index 519b3ba7f39..c24535fec19 100644 --- a/test/built-ins/Temporal/PlainDate/from/argument-number.js +++ b/test/built-ins/Temporal/PlainDate/from/argument-number.js @@ -3,26 +3,21 @@ /*--- esid: sec-temporal.plaindate.from -description: A number is converted to a string, then to Temporal.PlainDate -includes: [temporalHelpers.js] +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ -const arg = 19761118; - -const result = Temporal.PlainDate.from(arg); -TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => Temporal.PlainDate.from(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-number.js index 9a1079efd13..6e8f9cef37e 100644 --- a/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-number.js @@ -3,19 +3,13 @@ /*--- esid: sec-temporal.plaindate.from -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = Temporal.PlainDate.from(arg); -TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -23,8 +17,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => Temporal.PlainDate.from(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-wrong-type.js index c2e3954b752..0d26ebb5660 100644 --- a/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,9 +17,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => Temporal.PlainDate.from(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => Temporal.PlainDate.from(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/from/argument-wrong-type.js b/test/built-ins/Temporal/PlainDate/from/argument-wrong-type.js index d662976f5c3..32ed3749469 100644 --- a/test/built-ins/Temporal/PlainDate/from/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/from/argument-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.PlainDate.from(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.PlainDate.from(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string.js b/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string.js index 5c4c306bb9b..c4f6599b6c5 100644 --- a/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string.js +++ b/test/built-ins/Temporal/PlainDate/from/observable-get-overflow-argument-string.js @@ -29,5 +29,5 @@ assert.compareArray(actual, expected, "Successful call"); TemporalHelpers.assertPlainDate(result, 2021, 5, "M05", 17); actual.splice(0); // empty it for the next check -assert.throws(RangeError, () => Temporal.PlainDate.from(7, object)); +assert.throws(TypeError, () => Temporal.PlainDate.from(7, object)); assert.compareArray(actual, expected, "Failing call"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/add/argument-not-object.js b/test/built-ins/Temporal/PlainDate/prototype/add/argument-not-object.js index cad57d97350..919eb3564b9 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/add/argument-not-object.js +++ b/test/built-ins/Temporal/PlainDate/prototype/add/argument-not-object.js @@ -8,12 +8,12 @@ features: [Symbol, Temporal] ---*/ const instance = new Temporal.PlainDate(2000, 5, 2); -assert.throws(RangeError, () => instance.add(undefined), "undefined"); -assert.throws(RangeError, () => instance.add(null), "null"); -assert.throws(RangeError, () => instance.add(true), "boolean"); +assert.throws(TypeError, () => instance.add(undefined), "undefined"); +assert.throws(TypeError, () => instance.add(null), "null"); +assert.throws(TypeError, () => instance.add(true), "boolean"); assert.throws(RangeError, () => instance.add(""), "empty string"); assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); -assert.throws(RangeError, () => instance.add(7), "number"); -assert.throws(RangeError, () => instance.add(7n), "bigint"); +assert.throws(TypeError, () => instance.add(7), "number"); +assert.throws(TypeError, () => instance.add(7n), "bigint"); assert.throws(TypeError, () => instance.add([]), "array"); assert.throws(TypeError, () => instance.add(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-number.js b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-number.js index 2f06b86c7f9..577dab758eb 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-number.js +++ b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.plaindate.prototype.equals -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.PlainDate(1976, 11, 18); -const arg = 19761118; - -const result = instance.equals(arg); -assert.sameValue(result, true, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.equals(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-number.js index c8ebd39e1f4..c835461bc5f 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.plaindate.prototype.equals -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.PlainDate(1976, 11, 18); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.equals(arg); -assert.sameValue(result, true, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.equals(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-wrong-type.js index 13863fc0ea8..1cab7c1e23a 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.PlainDate(2000, 5, 2); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.equals(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-wrong-type.js index d90b83024af..131d6ad4b1a 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDate(2000, 5, 2); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.equals(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/argument-number.js b/test/built-ins/Temporal/PlainDate/prototype/since/argument-number.js index 734eec3be3e..6b15068d345 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/argument-number.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/argument-number.js @@ -3,28 +3,23 @@ /*--- esid: sec-temporal.plaindate.prototype.since -description: A number is converted to a string, then to Temporal.PlainDate -includes: [temporalHelpers.js] +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.PlainDate(1976, 11, 18); -const arg = 19761118; - -const result = instance.since(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.since(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-number.js index 8625ceb456c..2a05d60d01b 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-number.js @@ -3,30 +3,23 @@ /*--- esid: sec-temporal.plaindate.prototype.since -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.PlainDate(1976, 11, 18); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.since(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; - for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.since(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-wrong-type.js index 13329b62700..cabc64bba19 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.PlainDate(2000, 5, 2); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.since(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.since(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/argument-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/since/argument-wrong-type.js index e54867c7c69..dceb50a3796 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDate(2000, 5, 2); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.since(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.since(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-not-object.js b/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-not-object.js index bf2435ca21c..acaf4a0714a 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-not-object.js +++ b/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-not-object.js @@ -8,12 +8,12 @@ features: [Symbol, Temporal] ---*/ const instance = new Temporal.PlainDate(2000, 5, 2); -assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); -assert.throws(RangeError, () => instance.subtract(null), "null"); -assert.throws(RangeError, () => instance.subtract(true), "boolean"); +assert.throws(TypeError, () => instance.subtract(undefined), "undefined"); +assert.throws(TypeError, () => instance.subtract(null), "null"); +assert.throws(TypeError, () => instance.subtract(true), "boolean"); assert.throws(RangeError, () => instance.subtract(""), "empty string"); assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); -assert.throws(RangeError, () => instance.subtract(7), "number"); -assert.throws(RangeError, () => instance.subtract(7n), "bigint"); +assert.throws(TypeError, () => instance.subtract(7), "number"); +assert.throws(TypeError, () => instance.subtract(7n), "bigint"); assert.throws(TypeError, () => instance.subtract([]), "array"); assert.throws(TypeError, () => instance.subtract(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-number.js b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-number.js index 79d13f0b7fa..ddba97d033b 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-number.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-number.js @@ -3,18 +3,12 @@ /*--- esid: sec-temporal.plaindate.prototype.toplaindatetime -description: A number is converted to a string, then to Temporal.PlainTime -includes: [temporalHelpers.js] +description: A number is invalid in place of an ISO string for Temporal.PlainTime features: [Temporal] ---*/ const instance = new Temporal.PlainDate(2000, 5, 2); -const arg = 123456.987654321; - -const result = instance.toPlainDateTime(arg); -TemporalHelpers.assertPlainDateTime(result, 2000, 5, "M05", 2, 12, 34, 56, 987, 654, 321, "123456.987654321 is a valid ISO string for PlainTime"); - const numbers = [ 1, -123456.987654321, @@ -24,8 +18,8 @@ const numbers = [ for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.toPlainDateTime(arg), - `Number ${arg} does not convert to a valid ISO string for PlainTime` + "A number is not a valid ISO string for PlainTime" ); } diff --git a/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-wrong-type.js index 2caa82b2eb2..5176c2e564a 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDate(2000, 5, 2); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -19,8 +19,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.toPlainDateTime(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.toPlainDateTime(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-number.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-number.js index b25efbb22b1..ca8330368c1 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-number.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-number.js @@ -3,17 +3,12 @@ /*--- esid: sec-temporal.plaindate.prototype.tozoneddatetime -description: A number is converted to a string, then to Temporal.PlainTime +description: A number is invalid in place of an ISO string for Temporal.PlainTime features: [Temporal] ---*/ const instance = new Temporal.PlainDate(2000, 5, 2); -const arg = 123456.987654321; - -const result = instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }); -assert.sameValue(result.epochNanoseconds, 957270896_987_654_321n, "123456.987654321 is a valid ISO string for PlainTime"); - const numbers = [ 1, -123456.987654321, @@ -23,8 +18,8 @@ const numbers = [ for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }), - `Number ${arg} does not convert to a valid ISO string for PlainTime` + "A number is not a valid ISO string for PlainTime" ); } diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-wrong-type.js index 02e3410e195..df5aea609c7 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDate(2000, 5, 2); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -19,8 +19,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-wrong-type.js index a54d302728b..6163db000ae 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDate(2000, 5, 2); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.toZonedDateTime(timeZone), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => instance.toZonedDateTime(timeZone), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/argument-number.js b/test/built-ins/Temporal/PlainDate/prototype/until/argument-number.js index 04e1567d764..d9fbac329db 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/argument-number.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/argument-number.js @@ -3,28 +3,23 @@ /*--- esid: sec-temporal.plaindate.prototype.until -description: A number is converted to a string, then to Temporal.PlainDate -includes: [temporalHelpers.js] +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.PlainDate(1976, 11, 18); -const arg = 19761118; - -const result = instance.until(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.until(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-number.js index c050c717b01..a1af7e8ef9e 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-number.js @@ -3,30 +3,23 @@ /*--- esid: sec-temporal.plaindate.prototype.until -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.PlainDate(1976, 11, 18); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.until(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; - for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.until(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-wrong-type.js index 9b59cff47da..e0383ce83ef 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.PlainDate(2000, 5, 2); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.until(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.until(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/argument-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/until/argument-wrong-type.js index 6c1c8372428..2014f460be8 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDate(2000, 5, 2); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.until(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.until(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js index 750acb3230d..370ebb6af83 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js +++ b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js @@ -3,7 +3,7 @@ /*--- esid: sec-temporal.plaindate.prototype.withcalendar -description: A number is converted to a string, then to Temporal.Calendar +description: A number is not allowed to be a calendar features: [Temporal] ---*/ @@ -31,21 +31,17 @@ const instance = new Temporal.PlainDate(1976, 11, 18, { yearOfWeek() {}, }); -const arg = 19761118; - -const result = instance.withCalendar(arg); -assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar"); - const numbers = [ 1, -19761118, + 19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.withCalendar(arg), - `Number ${arg} does not convert to a valid ISO string for Calendar` + "A number is not a valid ISO string for Calendar" ); } diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-wrong-type.js index 95df5e7cc59..a637c317fc5 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-wrong-type.js @@ -33,7 +33,7 @@ const instance = new Temporal.PlainDate(1976, 11, 18, { yearOfWeek() {}, }); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -41,8 +41,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.withCalendar(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.withCalendar(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/missing-argument.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/missing-argument.js index d5b014c1b2e..f3931af7d9d 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/missing-argument.js +++ b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/missing-argument.js @@ -3,10 +3,10 @@ /*--- esid: sec-temporal.plaindate.prototype.withcalendar -description: RangeError thrown when calendar argument not given +description: TypeError thrown when calendar argument not given features: [Temporal] ---*/ const plainDate = Temporal.PlainDate.from("1976-11-18"); -assert.throws(RangeError, () => plainDate.withCalendar(), "missing argument"); -assert.throws(RangeError, () => plainDate.withCalendar(undefined), "undefined argument"); +assert.throws(TypeError, () => plainDate.withCalendar(), "missing argument"); +assert.throws(TypeError, () => plainDate.withCalendar(undefined), "undefined argument"); diff --git a/test/built-ins/Temporal/PlainDateTime/calendar-number.js b/test/built-ins/Temporal/PlainDateTime/calendar-number.js index b2299491932..0c80c0d7599 100644 --- a/test/built-ins/Temporal/PlainDateTime/calendar-number.js +++ b/test/built-ins/Temporal/PlainDateTime/calendar-number.js @@ -3,25 +3,21 @@ /*--- esid: sec-temporal.plaindatetime -description: A number is converted to a string, then to Temporal.Calendar +description: A number is not allowed to be a calendar features: [Temporal] ---*/ -const arg = 19761118; - -const result = new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg); -assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar"); - const numbers = [ 1, -19761118, + 19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg), - `Number ${arg} does not convert to a valid ISO string for Calendar` + "A number is not a valid ISO string for Calendar" ); } diff --git a/test/built-ins/Temporal/PlainDateTime/calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/calendar-wrong-type.js index 4cdea027e47..531a710f6e2 100644 --- a/test/built-ins/Temporal/PlainDateTime/calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,8 +17,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/compare/argument-number.js b/test/built-ins/Temporal/PlainDateTime/compare/argument-number.js index 8bf6b2caac2..ba930aee3db 100644 --- a/test/built-ins/Temporal/PlainDateTime/compare/argument-number.js +++ b/test/built-ins/Temporal/PlainDateTime/compare/argument-number.js @@ -3,32 +3,26 @@ /*--- esid: sec-temporal.plaindatetime.compare -description: A number is converted to a string, then to Temporal.PlainDateTime +description: A number cannot be used in place of a Temporal.PlainDateTime features: [Temporal] ---*/ -let arg = 19761118; - -const result1 = Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)); -assert.sameValue(result1, 0, "19761118 is a valid ISO string for PlainDateTime (first argument)"); -const result2 = Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg); -assert.sameValue(result2, 0, "19761118 is a valid ISO string for PlainDateTime (second argument)"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), - `Number ${arg} does not convert to a valid ISO string for PlainDateTime (first argument)` + "A number is not a valid ISO string for PlainDateTime (first argument)" ); assert.throws( - RangeError, + TypeError, () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), - `Number ${arg} does not convert to a valid ISO string for PlainDateTime (second argument)` + "A number is not a valid ISO string for PlainDateTime (second argument)" ); } diff --git a/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-number.js index 1a765d6bf19..46de71cba46 100644 --- a/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-number.js @@ -3,20 +3,13 @@ /*--- esid: sec-temporal.plaindatetime.compare -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result1 = Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)); -assert.sameValue(result1, 0, "19970327 is a valid ISO string for calendar (first argument)"); -const result2 = Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg); -assert.sameValue(result2, 0, "19970327 is a valid ISO string for calendar (second argument)"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,13 +17,13 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), - `Number ${calendar} does not convert to a valid ISO string for calendar (first argument)` + "A number is not a valid ISO string for calendar (first argument)" ); assert.throws( - RangeError, + TypeError, () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), - `Number ${calendar} does not convert to a valid ISO string for calendar (second argument)` + "A number is not a valid ISO string for calendar (second argument)" ); } diff --git a/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-wrong-type.js index a1c9159a0a7..f91c49c253f 100644 --- a/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,10 +17,18 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), `${description} does not convert to a valid ISO string (first argument)`); - assert.throws(RangeError, () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), `${description} does not convert to a valid ISO string (second argument)`); + assert.throws( + typeof calendar === "string" ? RangeError : TypeError, + () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), + `${description} does not convert to a valid ISO string (first argument)` + ); + assert.throws( + typeof calendar === "string" ? RangeError : TypeError, + () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), + `${description} does not convert to a valid ISO string (second argument)` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/compare/argument-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/compare/argument-wrong-type.js index 5136e87f29a..cfa9aaf4568 100644 --- a/test/built-ins/Temporal/PlainDateTime/compare/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/compare/argument-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -18,9 +18,17 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), `${description} does not convert to a valid ISO string (first argument)`); - assert.throws(RangeError, () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), `${description} does not convert to a valid ISO string (second argument)`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), + `${description} does not convert to a valid ISO string (first argument)` + ); + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), + `${description} does not convert to a valid ISO string (second argument)` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/from/argument-number.js b/test/built-ins/Temporal/PlainDateTime/from/argument-number.js index 0c1d2a5fdf3..3e9156f66c1 100644 --- a/test/built-ins/Temporal/PlainDateTime/from/argument-number.js +++ b/test/built-ins/Temporal/PlainDateTime/from/argument-number.js @@ -3,26 +3,21 @@ /*--- esid: sec-temporal.plaindatetime.from -description: A number is converted to a string, then to Temporal.PlainDateTime -includes: [temporalHelpers.js] +description: A number cannot be used in place of a Temporal.PlainDateTime features: [Temporal] ---*/ -let arg = 19761118; - -const result = Temporal.PlainDateTime.from(arg); -TemporalHelpers.assertPlainDateTime(result, 1976, 11, "M11", 18, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDateTime"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => Temporal.PlainDateTime.from(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDateTime` + "A number is not a valid ISO string for PlainDateTime" ); } diff --git a/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-number.js index 7de68bd5c77..fad7828da9a 100644 --- a/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-number.js @@ -3,19 +3,13 @@ /*--- esid: sec-temporal.plaindatetime.from -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = Temporal.PlainDateTime.from(arg); -TemporalHelpers.assertPlainDateTime(result, 1976, 11, "M11", 18, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -23,8 +17,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => Temporal.PlainDateTime.from(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-wrong-type.js index 095682c77b2..108f2862e4d 100644 --- a/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,9 +17,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => Temporal.PlainDateTime.from(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => Temporal.PlainDateTime.from(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/from/argument-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/from/argument-wrong-type.js index 99b167fc2cd..727a5c9ab5e 100644 --- a/test/built-ins/Temporal/PlainDateTime/from/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/from/argument-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.PlainDateTime.from(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.PlainDateTime.from(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-not-object.js b/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-not-object.js index d47cbe93ae3..b004957b188 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-not-object.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-not-object.js @@ -8,12 +8,12 @@ features: [Symbol, Temporal] ---*/ const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321); -assert.throws(RangeError, () => instance.add(undefined), "undefined"); -assert.throws(RangeError, () => instance.add(null), "null"); -assert.throws(RangeError, () => instance.add(true), "boolean"); +assert.throws(TypeError, () => instance.add(undefined), "undefined"); +assert.throws(TypeError, () => instance.add(null), "null"); +assert.throws(TypeError, () => instance.add(true), "boolean"); assert.throws(RangeError, () => instance.add(""), "empty string"); assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); -assert.throws(RangeError, () => instance.add(7), "number"); -assert.throws(RangeError, () => instance.add(7n), "bigint"); +assert.throws(TypeError, () => instance.add(7), "number"); +assert.throws(TypeError, () => instance.add(7n), "bigint"); assert.throws(TypeError, () => instance.add([]), "array"); assert.throws(TypeError, () => instance.add(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-number.js index 3b5f54af880..92d61f0b223 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-number.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.plaindatetime.prototype.equals -description: A number is converted to a string, then to Temporal.PlainDateTime +description: A number cannot be used in place of a Temporal.PlainDateTime features: [Temporal] ---*/ const instance = new Temporal.PlainDateTime(1976, 11, 18); -let arg = 19761118; - -const result = instance.equals(arg); -assert.sameValue(result, true, "19761118 is a valid ISO string for PlainDateTime"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.equals(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDateTime` + "A number is not a valid ISO string for PlainDateTime" ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-number.js index 65f079bfd66..beecb8c0f5e 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.plaindatetime.prototype.equals -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.PlainDateTime(1976, 11, 18); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.equals(arg); -assert.sameValue(result, true, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.equals(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js index b98b48b43ea..6825ff3d19a 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.equals(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-wrong-type.js index 686d371b9ae..9b466954a0b 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.equals(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-number.js index 5c0179d5a5d..021aed9431d 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-number.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-number.js @@ -3,28 +3,23 @@ /*--- esid: sec-temporal.plaindatetime.prototype.since -description: A number is converted to a string, then to Temporal.PlainDateTime -includes: [temporalHelpers.js] +description: A number cannot be used in place of a Temporal.PlainDateTime features: [Temporal] ---*/ const instance = new Temporal.PlainDateTime(1976, 11, 18); -let arg = 19761118; - -const result = instance.since(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDateTime"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.since(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDateTime` + "A number is not a valid ISO string for PlainDateTime" ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js index 3f116e5ade9..809a68f3caf 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js @@ -3,30 +3,23 @@ /*--- esid: sec-temporal.plaindatetime.prototype.since -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const instance = new Temporal.PlainDateTime(1976, 11, 18); - -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.since(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); +const instance = new Temporal.PlainDate(1976, 11, 18); const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; - for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.since(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js index 65d510b3a23..6e17c616a01 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.since(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.since(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-wrong-type.js index 535326bbd63..86cac2a21a6 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.since(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.since(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-not-object.js b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-not-object.js index d0e0797d872..911e3d8a68b 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-not-object.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-not-object.js @@ -8,12 +8,12 @@ features: [Symbol, Temporal] ---*/ const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321); -assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); -assert.throws(RangeError, () => instance.subtract(null), "null"); -assert.throws(RangeError, () => instance.subtract(true), "boolean"); +assert.throws(TypeError, () => instance.subtract(undefined), "undefined"); +assert.throws(TypeError, () => instance.subtract(null), "null"); +assert.throws(TypeError, () => instance.subtract(true), "boolean"); assert.throws(RangeError, () => instance.subtract(""), "empty string"); assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); -assert.throws(RangeError, () => instance.subtract(7), "number"); -assert.throws(RangeError, () => instance.subtract(7n), "bigint"); +assert.throws(TypeError, () => instance.subtract(7), "number"); +assert.throws(TypeError, () => instance.subtract(7n), "bigint"); assert.throws(TypeError, () => instance.subtract([]), "array"); assert.throws(TypeError, () => instance.subtract(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/timezone-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/timezone-wrong-type.js index 4538ced085f..1caf19363d4 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/timezone-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toZonedDateTime/timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDateTime(2000, 5, 2); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.toZonedDateTime(timeZone), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => instance.toZonedDateTime(timeZone), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-number.js index e6c05841d80..c7baeacb757 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-number.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-number.js @@ -3,28 +3,23 @@ /*--- esid: sec-temporal.plaindatetime.prototype.until -description: A number is converted to a string, then to Temporal.PlainDateTime -includes: [temporalHelpers.js] +description: A number cannot be used in place of a Temporal.PlainDateTime features: [Temporal] ---*/ const instance = new Temporal.PlainDateTime(1976, 11, 18); -let arg = 19761118; - -const result = instance.until(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDateTime"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.until(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDateTime` + "A number is not a valid ISO string for PlainDateTime" ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js index 2ebeeaf9960..96077077da0 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js @@ -3,30 +3,23 @@ /*--- esid: sec-temporal.plaindatetime.prototype.until -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const instance = new Temporal.PlainDateTime(1976, 11, 18); - -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.until(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); +const instance = new Temporal.PlainDate(1976, 11, 18); const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; - for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.until(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js index 12be4ae7ef2..0f1dd41ef12 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.until(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.until(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-wrong-type.js index 66c4439bf94..8ecb474a94f 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.until(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.until(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js index e06e31bd52d..6b333b46429 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js @@ -3,7 +3,7 @@ /*--- esid: sec-temporal.plaindatetime.prototype.withcalendar -description: A number is converted to a string, then to Temporal.Calendar +description: A number is not allowed to be a calendar features: [Temporal] ---*/ @@ -31,21 +31,17 @@ const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, yearOfWeek() {}, }); -const arg = 19761118; - -const result = instance.withCalendar(arg); -assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar"); - const numbers = [ 1, -19761118, + 19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.withCalendar(arg), - `Number ${arg} does not convert to a valid ISO string for Calendar` + "A number is not a valid ISO string for Calendar" ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-wrong-type.js index a6c8fdd6e4e..2d4c1958dd5 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-wrong-type.js @@ -33,7 +33,7 @@ const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, yearOfWeek() {}, }); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -41,8 +41,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.withCalendar(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.withCalendar(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/missing-argument.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/missing-argument.js index de83f7c9977..5250bd292aa 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/missing-argument.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/missing-argument.js @@ -3,10 +3,10 @@ /*--- esid: sec-temporal.plaindatetime.prototype.withcalendar -description: RangeError thrown when calendar argument not given +description: TypeError thrown when calendar argument not given features: [Temporal] ---*/ const plainDateTime = Temporal.PlainDateTime.from("1976-11-18T14:00:00"); -assert.throws(RangeError, () => plainDateTime.withCalendar(), "missing argument"); -assert.throws(RangeError, () => plainDateTime.withCalendar(undefined), "undefined argument"); +assert.throws(TypeError, () => plainDateTime.withCalendar(), "missing argument"); +assert.throws(TypeError, () => plainDateTime.withCalendar(undefined), "undefined argument"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-number.js index cb2c9337a3d..aa3a0ad1975 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-number.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-number.js @@ -3,28 +3,23 @@ /*--- esid: sec-temporal.plaindatetime.prototype.withplaindate -description: A number is converted to a string, then to Temporal.PlainDate -includes: [temporalHelpers.js] +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); -const arg = 19761118; - -const result = instance.withPlainDate(arg); -TemporalHelpers.assertPlainDateTime(result, 1976, 11, "M11", 18, 12, 34, 56, 987, 654, 321, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.withPlainDate(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js index af4f9cc7f17..3a403956fda 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js @@ -3,30 +3,23 @@ /*--- esid: sec-temporal.plaindatetime.prototype.withplaindate -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); - -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.withPlainDate(arg); -TemporalHelpers.assertPlainDateTime(result, 1976, 11, "M11", 18, 12, 34, 56, 987, 654, 321, "19970327 is a valid ISO string for calendar"); +const instance = new Temporal.PlainDate(1976, 11, 18); const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; - for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.withPlainDate(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-wrong-type.js index 9d5c5491ec7..a03d09483fb 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.withPlainDate(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.withPlainDate(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-wrong-type.js index 37daa75ccd4..5704bb5a01e 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.withPlainDate(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.withPlainDate(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-number.js index a2dc97347de..e37fbba82a7 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-number.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-number.js @@ -3,18 +3,12 @@ /*--- esid: sec-temporal.plaindatetime.prototype.withplaintime -description: A number is converted to a string, then to Temporal.PlainTime -includes: [temporalHelpers.js] +description: A number is invalid in place of an ISO string for Temporal.PlainTime features: [Temporal] ---*/ const instance = new Temporal.PlainDateTime(2000, 5, 2); -const arg = 123456.987654321; - -const result = instance.withPlainTime(arg); -TemporalHelpers.assertPlainDateTime(result, 2000, 5, "M05", 2, 12, 34, 56, 987, 654, 321, "123456.987654321 is a valid ISO string for PlainTime"); - const numbers = [ 1, -123456.987654321, @@ -24,8 +18,8 @@ const numbers = [ for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.withPlainTime(arg), - `Number ${arg} does not convert to a valid ISO string for PlainTime` + "A number is not a valid ISO string for PlainTime" ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-wrong-type.js index b8308b37f53..bce0f123d98 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -19,8 +19,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.withPlainTime(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.withPlainTime(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainMonthDay/calendar-number.js b/test/built-ins/Temporal/PlainMonthDay/calendar-number.js index 99f99d9c2b4..48d42b4ddc6 100644 --- a/test/built-ins/Temporal/PlainMonthDay/calendar-number.js +++ b/test/built-ins/Temporal/PlainMonthDay/calendar-number.js @@ -3,25 +3,21 @@ /*--- esid: sec-temporal.plainmonthday -description: A number is converted to a string, then to Temporal.Calendar +description: A number is not allowed to be a calendar features: [Temporal] ---*/ -const arg = 19761118; - -const result = new Temporal.PlainMonthDay(12, 15, arg, 1972); -assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar"); - const numbers = [ 1, -19761118, + 19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => new Temporal.PlainMonthDay(12, 15, arg, 1972), - `Number ${arg} does not convert to a valid ISO string for Calendar` + "A number is not a valid ISO string for Calendar" ); } diff --git a/test/built-ins/Temporal/PlainMonthDay/calendar-wrong-type.js b/test/built-ins/Temporal/PlainMonthDay/calendar-wrong-type.js index f05d07c4e94..5bd4a613e84 100644 --- a/test/built-ins/Temporal/PlainMonthDay/calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainMonthDay/calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,8 +17,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => new Temporal.PlainMonthDay(12, 15, arg, 1972), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => new Temporal.PlainMonthDay(12, 15, arg, 1972), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainMonthDay/from/argument-number.js b/test/built-ins/Temporal/PlainMonthDay/from/argument-number.js index e9b0edcbf45..47ece43883d 100644 --- a/test/built-ins/Temporal/PlainMonthDay/from/argument-number.js +++ b/test/built-ins/Temporal/PlainMonthDay/from/argument-number.js @@ -3,26 +3,23 @@ /*--- esid: sec-temporal.plainmonthday.from -description: A number is converted to a string, then to Temporal.PlainMonthDay -includes: [temporalHelpers.js] +description: A number is invalid in place of an ISO string for Temporal.PlainMonthDay features: [Temporal] ---*/ const arg = 1118; -const result = Temporal.PlainMonthDay.from(arg); -TemporalHelpers.assertPlainMonthDay(result, "M11", 18, "1118 is a valid ISO string for PlainMonthDay"); - const numbers = [ 1, + 1118, -1118, 12345, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => Temporal.PlainMonthDay.from(arg), - `Number ${arg} does not convert to a valid ISO string for PlainMonthDay` + "A number is not a valid ISO string for PlainMonthDay" ); } diff --git a/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-number.js index 0b666497232..08a4c371b7a 100644 --- a/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-number.js @@ -3,19 +3,13 @@ /*--- esid: sec-temporal.plainmonthday.from -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const calendar = 19970327; - -const arg = { monthCode: "M11", day: 18, calendar }; -const result = Temporal.PlainMonthDay.from(arg); -TemporalHelpers.assertPlainMonthDay(result, "M11", 18, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -23,8 +17,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => Temporal.PlainMonthDay.from(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-wrong-type.js index 8464fa0729a..8dc29c766d3 100644 --- a/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,9 +17,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => Temporal.PlainMonthDay.from(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => Temporal.PlainMonthDay.from(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainMonthDay/from/argument-wrong-type.js b/test/built-ins/Temporal/PlainMonthDay/from/argument-wrong-type.js index 42ea70dfd26..9f512299569 100644 --- a/test/built-ins/Temporal/PlainMonthDay/from/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainMonthDay/from/argument-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.PlainMonthDay.from(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.PlainMonthDay.from(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-number.js b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-number.js index b24f80790fe..733cb81750f 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-number.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.plainmonthday.prototype.equals -description: A number is converted to a string, then to Temporal.PlainMonthDay +description: A number is invalid in place of an ISO string for Temporal.PlainMonthDay features: [Temporal] ---*/ const instance = new Temporal.PlainMonthDay(11, 18); -const arg = 1118; - -const result = instance.equals(arg); -assert.sameValue(result, true, "1118 is a valid ISO string for PlainMonthDay"); - const numbers = [ 1, + 1118, -1118, 12345, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.equals(arg), - `Number ${arg} does not convert to a valid ISO string for PlainMonthDay` + "A number is not a valid ISO string for PlainMonthDay" ); } diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-number.js index b558e4612ef..7f49e1922db 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.plainmonthday.prototype.equals -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.PlainMonthDay(11, 18); -const calendar = 19970327; - -const arg = { monthCode: "M11", day: 18, calendar }; -const result = instance.equals(arg); -assert.sameValue(result, true, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.equals(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-wrong-type.js index 57b2933e85b..850d9008249 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.PlainMonthDay(5, 2); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.equals(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-wrong-type.js b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-wrong-type.js index 8c91b61fc4b..6869c18237a 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainMonthDay(5, 2); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.equals(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainTime/compare/argument-number.js b/test/built-ins/Temporal/PlainTime/compare/argument-number.js index aedb3f9b84d..810bb617849 100644 --- a/test/built-ins/Temporal/PlainTime/compare/argument-number.js +++ b/test/built-ins/Temporal/PlainTime/compare/argument-number.js @@ -3,17 +3,10 @@ /*--- esid: sec-temporal.plaintime.compare -description: A number is converted to a string, then to Temporal.PlainTime +description: A number is invalid in place of an ISO string for Temporal.PlainTime features: [Temporal] ---*/ -const arg = 123456.987654321; - -const result1 = Temporal.PlainTime.compare(arg, new Temporal.PlainTime(12, 34, 56, 987, 654, 321)); -assert.sameValue(result1, 0, "123456.987654321 is a valid ISO string for PlainTime (first argument)"); -const result2 = Temporal.PlainTime.compare(new Temporal.PlainTime(12, 34, 56, 987, 654, 321), arg); -assert.sameValue(result2, 0, "123456.987654321 is a valid ISO string for PlainTime (second argument)"); - const numbers = [ 1, -123456.987654321, @@ -23,13 +16,13 @@ const numbers = [ for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => Temporal.PlainTime.compare(arg, new Temporal.PlainTime(12, 34, 56, 987, 654, 321)), - `Number ${arg} does not convert to a valid ISO string for PlainTime (first argument)` + "A number is not a valid ISO string for PlainTime (first argument)" ); assert.throws( - RangeError, + TypeError, () => Temporal.PlainTime.compare(new Temporal.PlainTime(12, 34, 56, 987, 654, 321), arg), - `Number ${arg} does not convert to a valid ISO string for PlainTime (second argument)` + "A number is not a valid ISO string for PlainTime (second argument)" ); } diff --git a/test/built-ins/Temporal/PlainTime/compare/argument-wrong-type.js b/test/built-ins/Temporal/PlainTime/compare/argument-wrong-type.js index 9efa7f69f00..14ea849f26e 100644 --- a/test/built-ins/Temporal/PlainTime/compare/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainTime/compare/argument-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -18,9 +18,17 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.PlainTime.compare(arg, new Temporal.PlainTime(12, 34, 56, 987, 654, 321)), `${description} does not convert to a valid ISO string (first argument)`); - assert.throws(RangeError, () => Temporal.PlainTime.compare(new Temporal.PlainTime(12, 34, 56, 987, 654, 321), arg), `${description} does not convert to a valid ISO string (second argument)`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.PlainTime.compare(arg, new Temporal.PlainTime(12, 34, 56, 987, 654, 321)), + `${description} does not convert to a valid ISO string (first argument)` + ); + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.PlainTime.compare(new Temporal.PlainTime(12, 34, 56, 987, 654, 321), arg), + `${description} does not convert to a valid ISO string (second argument)` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainTime/from/argument-number.js b/test/built-ins/Temporal/PlainTime/from/argument-number.js index bc83036e0f8..39f0a62fad4 100644 --- a/test/built-ins/Temporal/PlainTime/from/argument-number.js +++ b/test/built-ins/Temporal/PlainTime/from/argument-number.js @@ -3,16 +3,10 @@ /*--- esid: sec-temporal.plaintime.from -description: A number is converted to a string, then to Temporal.PlainTime -includes: [temporalHelpers.js] +description: A number is invalid in place of an ISO string for Temporal.PlainTime features: [Temporal] ---*/ -const arg = 123456.987654321; - -const result = Temporal.PlainTime.from(arg); -TemporalHelpers.assertPlainTime(result, 12, 34, 56, 987, 654, 321, "123456.987654321 is a valid ISO string for PlainTime"); - const numbers = [ 1, -123456.987654321, @@ -22,8 +16,8 @@ const numbers = [ for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => Temporal.PlainTime.from(arg), - `Number ${arg} does not convert to a valid ISO string for PlainTime` + "A number is not a valid ISO string for PlainTime" ); } diff --git a/test/built-ins/Temporal/PlainTime/from/argument-wrong-type.js b/test/built-ins/Temporal/PlainTime/from/argument-wrong-type.js index 9786937f329..0701cf26d05 100644 --- a/test/built-ins/Temporal/PlainTime/from/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainTime/from/argument-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.PlainTime.from(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.PlainTime.from(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainTime/prototype/add/argument-not-object.js b/test/built-ins/Temporal/PlainTime/prototype/add/argument-not-object.js index 71412647723..5cfa75cdb5c 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/add/argument-not-object.js +++ b/test/built-ins/Temporal/PlainTime/prototype/add/argument-not-object.js @@ -8,12 +8,12 @@ features: [Symbol, Temporal] ---*/ const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321); -assert.throws(RangeError, () => instance.add(undefined), "undefined"); -assert.throws(RangeError, () => instance.add(null), "null"); -assert.throws(RangeError, () => instance.add(true), "boolean"); +assert.throws(TypeError, () => instance.add(undefined), "undefined"); +assert.throws(TypeError, () => instance.add(null), "null"); +assert.throws(TypeError, () => instance.add(true), "boolean"); assert.throws(RangeError, () => instance.add(""), "empty string"); assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); -assert.throws(RangeError, () => instance.add(7), "number"); -assert.throws(RangeError, () => instance.add(7n), "bigint"); +assert.throws(TypeError, () => instance.add(7), "number"); +assert.throws(TypeError, () => instance.add(7n), "bigint"); assert.throws(TypeError, () => instance.add([]), "array"); assert.throws(TypeError, () => instance.add(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/equals/argument-number.js b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-number.js index 4894d5934e4..57cf4f90bec 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/equals/argument-number.js +++ b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-number.js @@ -3,17 +3,12 @@ /*--- esid: sec-temporal.plaintime.prototype.equals -description: A number is converted to a string, then to Temporal.PlainTime +description: A number is invalid in place of an ISO string for Temporal.PlainTime features: [Temporal] ---*/ const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); -const arg = 123456.987654321; - -const result = instance.equals(arg); -assert.sameValue(result, true, "123456.987654321 is a valid ISO string for PlainTime"); - const numbers = [ 1, -123456.987654321, @@ -23,8 +18,8 @@ const numbers = [ for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.equals(arg), - `Number ${arg} does not convert to a valid ISO string for PlainTime` + "A number is not a valid ISO string for PlainTime" ); } diff --git a/test/built-ins/Temporal/PlainTime/prototype/equals/argument-wrong-type.js b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-wrong-type.js index 70bb470a9e5..38ccd602c3b 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/equals/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.equals(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/argument-number.js b/test/built-ins/Temporal/PlainTime/prototype/since/argument-number.js index 3ca4003a0b2..388013e0fee 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/since/argument-number.js +++ b/test/built-ins/Temporal/PlainTime/prototype/since/argument-number.js @@ -3,18 +3,12 @@ /*--- esid: sec-temporal.plaintime.prototype.since -description: A number is converted to a string, then to Temporal.PlainTime -includes: [temporalHelpers.js] +description: A number is invalid in place of an ISO string for Temporal.PlainTime features: [Temporal] ---*/ const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); -const arg = 123456.987654321; - -const result = instance.since(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "123456.987654321 is a valid ISO string for PlainTime"); - const numbers = [ 1, -123456.987654321, @@ -24,8 +18,8 @@ const numbers = [ for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.since(arg), - `Number ${arg} does not convert to a valid ISO string for PlainTime` + "A number is not a valid ISO string for PlainTime" ); } diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/argument-wrong-type.js b/test/built-ins/Temporal/PlainTime/prototype/since/argument-wrong-type.js index ee7142c89d2..e980efbcbff 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/since/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainTime/prototype/since/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.since(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.since(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-not-object.js b/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-not-object.js index fd202ca8056..b769a0568c9 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-not-object.js +++ b/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-not-object.js @@ -8,12 +8,12 @@ features: [Symbol, Temporal] ---*/ const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321); -assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); -assert.throws(RangeError, () => instance.subtract(null), "null"); -assert.throws(RangeError, () => instance.subtract(true), "boolean"); +assert.throws(TypeError, () => instance.subtract(undefined), "undefined"); +assert.throws(TypeError, () => instance.subtract(null), "null"); +assert.throws(TypeError, () => instance.subtract(true), "boolean"); assert.throws(RangeError, () => instance.subtract(""), "empty string"); assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); -assert.throws(RangeError, () => instance.subtract(7), "number"); -assert.throws(RangeError, () => instance.subtract(7n), "bigint"); +assert.throws(TypeError, () => instance.subtract(7), "number"); +assert.throws(TypeError, () => instance.subtract(7n), "bigint"); assert.throws(TypeError, () => instance.subtract([]), "array"); assert.throws(TypeError, () => instance.subtract(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-number.js b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-number.js index 1742c9a9d3e..73096305c66 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-number.js +++ b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-number.js @@ -3,28 +3,23 @@ /*--- esid: sec-temporal.plaintime.prototype.toplaindatetime -description: A number is converted to a string, then to Temporal.PlainDate -includes: [temporalHelpers.js] +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); -const arg = 19761118; - -const result = instance.toPlainDateTime(arg); -TemporalHelpers.assertPlainDateTime(result, 1976, 11, "M11", 18, 12, 34, 56, 987, 654, 321, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.toPlainDateTime(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-propertybag-calendar-number.js index 2d642c11ce6..2b2a6d8b318 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-propertybag-calendar-number.js @@ -3,30 +3,23 @@ /*--- esid: sec-temporal.plaintime.prototype.toplaindatetime -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); - -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.toPlainDateTime(arg); -TemporalHelpers.assertPlainDateTime(result, 1976, 11, "M11", 18, 12, 34, 56, 987, 654, 321, "19970327 is a valid ISO string for calendar"); +const instance = new Temporal.PlainDate(1976, 11, 18); const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; - for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.toPlainDateTime(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-propertybag-calendar-wrong-type.js index 14aaad26d48..e01decab47c 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.toPlainDateTime(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.toPlainDateTime(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-wrong-type.js b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-wrong-type.js index 888760b50de..913093c44d1 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.toPlainDateTime(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.toPlainDateTime(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-number.js b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-number.js index e466ad4e48c..073eda26cdc 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-number.js +++ b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.plaintime.prototype.tozoneddatetime -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); -const arg = 19761118; - -const result = instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }); -assert.sameValue(result.epochNanoseconds, 217_168_496_987_654_321n, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-propertybag-calendar-number.js index 0dab910df75..7c47cd39183 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.plaintime.prototype.tozoneddatetime -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }); -assert.sameValue(result.epochNanoseconds, 217_168_496_987_654_321n, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-propertybag-calendar-wrong-type.js index 6b05bed91d7..310fb0569ce 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-wrong-type.js b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-wrong-type.js index f668689be54..aefa92f3af3 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -19,8 +19,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/timezone-wrong-type.js b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/timezone-wrong-type.js index 7aa204395e2..b1575599709 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/timezone-wrong-type.js +++ b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainTime(); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.toZonedDateTime({ plainDate: new Temporal.PlainDate(2000, 5, 2), timeZone }), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => instance.toZonedDateTime({ plainDate: new Temporal.PlainDate(2000, 5, 2), timeZone }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/argument-number.js b/test/built-ins/Temporal/PlainTime/prototype/until/argument-number.js index 0ce8dcf2949..fc277bd86ff 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/until/argument-number.js +++ b/test/built-ins/Temporal/PlainTime/prototype/until/argument-number.js @@ -3,18 +3,12 @@ /*--- esid: sec-temporal.plaintime.prototype.until -description: A number is converted to a string, then to Temporal.PlainTime -includes: [temporalHelpers.js] +description: A number is invalid in place of an ISO string for Temporal.PlainTime features: [Temporal] ---*/ const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); -const arg = 123456.987654321; - -const result = instance.until(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "123456.987654321 is a valid ISO string for PlainTime"); - const numbers = [ 1, -123456.987654321, @@ -24,8 +18,8 @@ const numbers = [ for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.until(arg), - `Number ${arg} does not convert to a valid ISO string for PlainTime` + "A number is not a valid ISO string for PlainTime" ); } diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/argument-wrong-type.js b/test/built-ins/Temporal/PlainTime/prototype/until/argument-wrong-type.js index 2e9c5e29e23..9f612334362 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/until/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainTime/prototype/until/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.until(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.until(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainYearMonth/calendar-number.js b/test/built-ins/Temporal/PlainYearMonth/calendar-number.js index 4b22e59ebfe..2c8875bef04 100644 --- a/test/built-ins/Temporal/PlainYearMonth/calendar-number.js +++ b/test/built-ins/Temporal/PlainYearMonth/calendar-number.js @@ -3,25 +3,21 @@ /*--- esid: sec-temporal.plainyearmonth -description: A number is converted to a string, then to Temporal.Calendar +description: A number is not allowed to be a calendar features: [Temporal] ---*/ -const arg = 19761118; - -const result = new Temporal.PlainYearMonth(2000, 5, arg, 1); -assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar"); - const numbers = [ 1, -19761118, + 19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => new Temporal.PlainYearMonth(2000, 5, arg, 1), - `Number ${arg} does not convert to a valid ISO string for Calendar` + "A number is not a valid ISO string for Calendar" ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/calendar-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/calendar-wrong-type.js index 0df4de7aeec..efe81bbdf66 100644 --- a/test/built-ins/Temporal/PlainYearMonth/calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,8 +17,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => new Temporal.PlainYearMonth(2000, 5, arg, 1), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => new Temporal.PlainYearMonth(2000, 5, arg, 1), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/argument-number.js b/test/built-ins/Temporal/PlainYearMonth/compare/argument-number.js index c34aa67e146..007d8625a36 100644 --- a/test/built-ins/Temporal/PlainYearMonth/compare/argument-number.js +++ b/test/built-ins/Temporal/PlainYearMonth/compare/argument-number.js @@ -3,32 +3,28 @@ /*--- esid: sec-temporal.plainyearmonth.compare -description: A number is converted to a string, then to Temporal.PlainYearMonth +description: A number is invalid in place of an ISO string for Temporal.PlainYearMonth features: [Temporal] ---*/ const arg = 201906; -const result1 = Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)); -assert.sameValue(result1, 0, "201906 is a valid ISO string for PlainYearMonth (first argument)"); -const result2 = Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg); -assert.sameValue(result2, 0, "201906 is a valid ISO string for PlainYearMonth (second argument)"); - const numbers = [ 1, + 201906, -201906, 1234567, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), - `Number ${arg} does not convert to a valid ISO string for PlainYearMonth (first argument)` + "A number is not a valid ISO string for PlainYearMonth (first argument)" ); assert.throws( - RangeError, + TypeError, () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), - `Number ${arg} does not convert to a valid ISO string for PlainYearMonth (first argument)` + "A number is not a valid ISO string for PlainYearMonth (first argument)" ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-number.js index cfa815ea481..1a7884cf799 100644 --- a/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-number.js @@ -3,20 +3,13 @@ /*--- esid: sec-temporal.plainyearmonth.compare -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const calendar = 19970327; - -const arg = { year: 2019, monthCode: "M06", calendar }; -const result1 = Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)); -assert.sameValue(result1, 0, "19970327 is a valid ISO string for calendar (first argument)"); -const result2 = Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg); -assert.sameValue(result2, 0, "19970327 is a valid ISO string for calendar (second argument)"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,13 +17,13 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 2019, monthCode: "M06", calendar }; assert.throws( - RangeError, + TypeError, () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), - `Number ${calendar} does not convert to a valid ISO string for calendar (first argument)` + "A number is not a valid ISO string for calendar (first argument)" ); assert.throws( - RangeError, + TypeError, () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), - `Number ${calendar} does not convert to a valid ISO string for calendar (second argument)` + "A number is not a valid ISO string for calendar (second argument)" ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-wrong-type.js index 5d405acc502..73ecf05f88f 100644 --- a/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,10 +17,18 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), `${description} does not convert to a valid ISO string (first argument)`); - assert.throws(RangeError, () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), `${description} does not convert to a valid ISO string (second argument)`); + assert.throws( + typeof calendar === "string" ? RangeError : TypeError, + () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), + `${description} does not convert to a valid ISO string (first argument)` + ); + assert.throws( + typeof calendar === "string" ? RangeError : TypeError, + () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), + `${description} does not convert to a valid ISO string (second argument)` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/argument-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/compare/argument-wrong-type.js index c50651ec762..0a696a62000 100644 --- a/test/built-ins/Temporal/PlainYearMonth/compare/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/compare/argument-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -18,9 +18,17 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), `${description} does not convert to a valid ISO string (first argument)`); - assert.throws(RangeError, () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), `${description} does not convert to a valid ISO string (second argument)`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), + `${description} does not convert to a valid ISO string (first argument)` + ); + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), + `${description} does not convert to a valid ISO string (second argument)` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-number.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-number.js index 4c9e3196c66..1f4a6fd21ff 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/argument-number.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-number.js @@ -3,26 +3,21 @@ /*--- esid: sec-temporal.plainyearmonth.from -description: A number is converted to a string, then to Temporal.PlainYearMonth -includes: [temporalHelpers.js] +description: A number is invalid in place of an ISO string for Temporal.PlainYearMonth features: [Temporal] ---*/ -const arg = 201906; - -const result = Temporal.PlainYearMonth.from(arg); -TemporalHelpers.assertPlainYearMonth(result, 2019, 6, "M06", "201906 is a valid ISO string for PlainYearMonth"); - const numbers = [ 1, + 201906, -201906, 1234567, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => Temporal.PlainYearMonth.from(arg), - `Number ${arg} does not convert to a valid ISO string for PlainYearMonth` + "A number is not a valid ISO string for PlainYearMonth" ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-number.js index be415abf44e..8b5fec59118 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-number.js @@ -3,19 +3,13 @@ /*--- esid: sec-temporal.plainyearmonth.from -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const calendar = 19970327; - -const arg = { year: 2019, monthCode: "M06", calendar }; -const result = Temporal.PlainYearMonth.from(arg); -TemporalHelpers.assertPlainYearMonth(result, 2019, 6, "M06", "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -23,8 +17,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 2019, monthCode: "M06", calendar }; assert.throws( - RangeError, + TypeError, () => Temporal.PlainYearMonth.from(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-wrong-type.js index 551c97e3ac0..96f03d09865 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,9 +17,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => Temporal.PlainYearMonth.from(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => Temporal.PlainYearMonth.from(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-wrong-type.js index 5e4154a3e00..fbe0bf93998 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.PlainYearMonth.from(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.PlainYearMonth.from(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-not-object.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-not-object.js index fdc21ea1a57..68dde7484ea 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-not-object.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-not-object.js @@ -8,12 +8,12 @@ features: [Symbol, Temporal] ---*/ const instance = new Temporal.PlainYearMonth(2000, 5); -assert.throws(RangeError, () => instance.add(undefined), "undefined"); -assert.throws(RangeError, () => instance.add(null), "null"); -assert.throws(RangeError, () => instance.add(true), "boolean"); +assert.throws(TypeError, () => instance.add(undefined), "undefined"); +assert.throws(TypeError, () => instance.add(null), "null"); +assert.throws(TypeError, () => instance.add(true), "boolean"); assert.throws(RangeError, () => instance.add(""), "empty string"); assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); -assert.throws(RangeError, () => instance.add(7), "number"); -assert.throws(RangeError, () => instance.add(7n), "bigint"); +assert.throws(TypeError, () => instance.add(7), "number"); +assert.throws(TypeError, () => instance.add(7n), "bigint"); assert.throws(TypeError, () => instance.add([]), "array"); assert.throws(TypeError, () => instance.add(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-number.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-number.js index 11cbfd5e07b..d60992631d4 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-number.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.plainyearmonth.prototype.equals -description: A number is converted to a string, then to Temporal.PlainYearMonth +description: A number is invalid in place of an ISO string for Temporal.PlainYearMonth features: [Temporal] ---*/ const instance = new Temporal.PlainYearMonth(2019, 6); -const arg = 201906; - -const result = instance.equals(arg); -assert.sameValue(result, true, "201906 is a valid ISO string for PlainYearMonth"); - const numbers = [ 1, + 201906, -201906, 1234567, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.equals(arg), - `Number ${arg} does not convert to a valid ISO string for PlainYearMonth` + "A number is not a valid ISO string for PlainYearMonth" ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-number.js index 4e979abcd26..21be48be03f 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.plainyearmonth.prototype.equals -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.PlainYearMonth(2019, 6); -const calendar = 19970327; - -const arg = { year: 2019, monthCode: "M06", calendar }; -const result = instance.equals(arg); -assert.sameValue(result, true, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 2019, monthCode: "M06", calendar }; assert.throws( - RangeError, + TypeError, () => instance.equals(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-wrong-type.js index 4448cd36f83..e55cb3cee8d 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.PlainYearMonth(2000, 5); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.equals(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-wrong-type.js index f3c1e56acaa..c4e0dd31c7d 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainYearMonth(2000, 5); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.equals(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-number.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-number.js index f9116301e5a..b47721c158a 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-number.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-number.js @@ -3,28 +3,23 @@ /*--- esid: sec-temporal.plainyearmonth.prototype.since -description: A number is converted to a string, then to Temporal.PlainYearMonth -includes: [temporalHelpers.js] +description: A number is invalid in place of an ISO string for Temporal.PlainYearMonth features: [Temporal] ---*/ const instance = new Temporal.PlainYearMonth(2019, 6); -const arg = 201906; - -const result = instance.since(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "201906 is a valid ISO string for PlainYearMonth"); - const numbers = [ 1, + 201906, -201906, 1234567, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.since(arg), - `Number ${arg} does not convert to a valid ISO string for PlainYearMonth` + "A number is not a valid ISO string for PlainYearMonth" ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-number.js index 97c87fc7e23..791b0eda621 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-number.js @@ -3,30 +3,23 @@ /*--- esid: sec-temporal.plainyearmonth.prototype.since -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const instance = new Temporal.PlainYearMonth(2019, 6); - -const calendar = 19970327; - -const arg = { year: 2019, monthCode: "M06", calendar }; -const result = instance.since(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); +const instance = new Temporal.PlainDate(1976, 11, 18); const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; - for (const calendar of numbers) { const arg = { year: 2019, monthCode: "M06", calendar }; assert.throws( - RangeError, + TypeError, () => instance.since(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-wrong-type.js index 364753a8404..1368ad4ebd6 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.PlainYearMonth(2000, 5); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.since(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.since(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-wrong-type.js index 7078e9941c8..47a3be38949 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainYearMonth(2000, 5); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.since(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.since(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-not-object.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-not-object.js index 1bc421fb865..f5f552005ad 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-not-object.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-not-object.js @@ -8,12 +8,12 @@ features: [Symbol, Temporal] ---*/ const instance = new Temporal.PlainYearMonth(2000, 5); -assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); -assert.throws(RangeError, () => instance.subtract(null), "null"); -assert.throws(RangeError, () => instance.subtract(true), "boolean"); +assert.throws(TypeError, () => instance.subtract(undefined), "undefined"); +assert.throws(TypeError, () => instance.subtract(null), "null"); +assert.throws(TypeError, () => instance.subtract(true), "boolean"); assert.throws(RangeError, () => instance.subtract(""), "empty string"); assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); -assert.throws(RangeError, () => instance.subtract(7), "number"); -assert.throws(RangeError, () => instance.subtract(7n), "bigint"); +assert.throws(TypeError, () => instance.subtract(7), "number"); +assert.throws(TypeError, () => instance.subtract(7n), "bigint"); assert.throws(TypeError, () => instance.subtract([]), "array"); assert.throws(TypeError, () => instance.subtract(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-number.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-number.js index b056e5aebe8..5e1c73b1e41 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-number.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-number.js @@ -3,28 +3,23 @@ /*--- esid: sec-temporal.plainyearmonth.prototype.until -description: A number is converted to a string, then to Temporal.PlainYearMonth -includes: [temporalHelpers.js] +description: A number is invalid in place of an ISO string for Temporal.PlainYearMonth features: [Temporal] ---*/ const instance = new Temporal.PlainYearMonth(2019, 6); -const arg = 201906; - -const result = instance.until(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "201906 is a valid ISO string for PlainYearMonth"); - const numbers = [ 1, + 201906, -201906, 1234567, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.until(arg), - `Number ${arg} does not convert to a valid ISO string for PlainYearMonth` + "A number is not a valid ISO string for PlainYearMonth" ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-number.js index 2ee4920af05..2e99be53293 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-number.js @@ -3,30 +3,23 @@ /*--- esid: sec-temporal.plainyearmonth.prototype.until -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const instance = new Temporal.PlainYearMonth(2019, 6); - -const calendar = 19970327; - -const arg = { year: 2019, monthCode: "M06", calendar }; -const result = instance.until(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); +const instance = new Temporal.PlainDate(1976, 11, 18); const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; - for (const calendar of numbers) { const arg = { year: 2019, monthCode: "M06", calendar }; assert.throws( - RangeError, + TypeError, () => instance.until(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-wrong-type.js index 760a559d6b0..e26fb728206 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.PlainYearMonth(2000, 5); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.until(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.until(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-wrong-type.js index fc04e66b8a0..f93848d269d 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainYearMonth(2000, 5); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.until(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.until(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/TimeZone/argument-wrong-type.js b/test/built-ins/Temporal/TimeZone/argument-wrong-type.js new file mode 100644 index 00000000000..2baebf5e821 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/argument-wrong-type.js @@ -0,0 +1,30 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone +description: RangeError thrown when constructor invoked with the wrong type +features: [Temporal] +---*/ + +const tests = [ + [null, "null"], + [true, "boolean"], + ["", "empty string"], + [1, "number that doesn't convert to a valid ISO string"], + [19761118, "number that would convert to a valid ISO string in other contexts"], + [1n, "bigint"], + [Symbol(), "symbol"], + [{}, "object not implementing any protocol"], + [new Temporal.Calendar("iso8601"), "calendar instance"], + [new Temporal.TimeZone("UTC"), "time zone instance"], + [Temporal.ZonedDateTime.from("2020-01-01T00:00Z[UTC]"), "ZonedDateTime instance"], +]; + +for (const [arg, description] of tests) { + assert.throws( + typeof (arg) === "string" ? RangeError : TypeError, + () => new Temporal.TimeZone(arg), + `${description} is not accepted by this constructor` + ); +} diff --git a/test/built-ins/Temporal/TimeZone/from/argument-primitive.js b/test/built-ins/Temporal/TimeZone/from/argument-primitive.js index ebe3504d80a..a915eb635f4 100644 --- a/test/built-ins/Temporal/TimeZone/from/argument-primitive.js +++ b/test/built-ins/Temporal/TimeZone/from/argument-primitive.js @@ -37,7 +37,7 @@ const thisValues = [ for (const thisValue of thisValues) { for (const primitive of primitives) { - assert.throws(RangeError, () => Temporal.TimeZone.from.call(thisValue, primitive)); + assert.throws(typeof primitive === 'string' ? RangeError : TypeError, () => Temporal.TimeZone.from.call(thisValue, primitive)); } const symbol = Symbol(); diff --git a/test/built-ins/Temporal/TimeZone/from/timezone-wrong-type.js b/test/built-ins/Temporal/TimeZone/from/timezone-wrong-type.js index ac74b54f7fd..c2b735593cd 100644 --- a/test/built-ins/Temporal/TimeZone/from/timezone-wrong-type.js +++ b/test/built-ins/Temporal/TimeZone/from/timezone-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.TimeZone.from(timeZone), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => Temporal.TimeZone.from(timeZone), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/TimeZone/missing-arguments.js b/test/built-ins/Temporal/TimeZone/missing-arguments.js index c407daed1cb..65ecacdbf59 100644 --- a/test/built-ins/Temporal/TimeZone/missing-arguments.js +++ b/test/built-ins/Temporal/TimeZone/missing-arguments.js @@ -3,9 +3,9 @@ /*--- esid: sec-temporal.timezone -description: RangeError thrown when constructor invoked with no argument +description: TypeError thrown when constructor invoked with no argument features: [Temporal] ---*/ -assert.throws(RangeError, () => new Temporal.TimeZone()); -assert.throws(RangeError, () => new Temporal.TimeZone(undefined)); +assert.throws(TypeError, () => new Temporal.TimeZone()); +assert.throws(TypeError, () => new Temporal.TimeZone(undefined)); diff --git a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-not-datetime.js b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-not-datetime.js index caf2725370d..92c057a34ca 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-not-datetime.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-not-datetime.js @@ -8,11 +8,11 @@ features: [Temporal] ---*/ const timeZone = Temporal.TimeZone.from("UTC"); -assert.throws(RangeError, () => timeZone.getInstantFor(undefined), "undefined"); -assert.throws(RangeError, () => timeZone.getInstantFor(null), "null"); -assert.throws(RangeError, () => timeZone.getInstantFor(true), "boolean"); +assert.throws(TypeError, () => timeZone.getInstantFor(undefined), "undefined"); +assert.throws(TypeError, () => timeZone.getInstantFor(null), "null"); +assert.throws(TypeError, () => timeZone.getInstantFor(true), "boolean"); assert.throws(RangeError, () => timeZone.getInstantFor(""), "empty string"); assert.throws(TypeError, () => timeZone.getInstantFor(Symbol()), "Symbol"); -assert.throws(RangeError, () => timeZone.getInstantFor(5), "number"); -assert.throws(RangeError, () => timeZone.getInstantFor(5n), "bigint"); +assert.throws(TypeError, () => timeZone.getInstantFor(5), "number"); +assert.throws(TypeError, () => timeZone.getInstantFor(5n), "bigint"); assert.throws(TypeError, () => timeZone.getInstantFor({ year: 2020 }), "plain object"); diff --git a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-number.js b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-number.js index d2d05898828..b408a00f743 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-number.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.timezone.prototype.getinstantfor -description: A number is converted to a string, then to Temporal.PlainDateTime +description: A number cannot be used in place of a Temporal.PlainDateTime features: [Temporal] ---*/ const instance = new Temporal.TimeZone("UTC"); -let arg = 19761118; - -const result = instance.getInstantFor(arg); -assert.sameValue(result.epochNanoseconds, 217_123_200_000_000_000n, "19761118 is a valid ISO string for PlainDateTime"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.getInstantFor(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDateTime` + "A number is not a valid ISO string for PlainDateTime" ); } diff --git a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-number.js index 1de1dca472c..15ad1bdcadc 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.timezone.prototype.getinstantfor -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.TimeZone("UTC"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.getInstantFor(arg); -assert.sameValue(result.epochNanoseconds, 217_123_200_000_000_000n, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.getInstantFor(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-wrong-type.js index 6604b51fe76..e2f93998ad2 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.TimeZone("UTC"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.getInstantFor(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.getInstantFor(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-wrong-type.js b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-wrong-type.js index 187c362e0a8..4e2b85431c4 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-wrong-type.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.TimeZone("UTC"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.getInstantFor(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.getInstantFor(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/TimeZone/prototype/getNextTransition/argument-wrong-type.js b/test/built-ins/Temporal/TimeZone/prototype/getNextTransition/argument-wrong-type.js index 2ee1c8a62ed..65294ea9063 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getNextTransition/argument-wrong-type.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getNextTransition/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.TimeZone("UTC"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -23,8 +23,14 @@ const rangeErrorTests = [ [Temporal.Instant, "Temporal.Instant, object"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.getNextTransition(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === "string" || (typeof arg === "object" && arg !== null) || typeof arg === "function" + ? RangeError + : TypeError, + () => instance.getNextTransition(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/argument-wrong-type.js b/test/built-ins/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/argument-wrong-type.js index 18524e21a65..536d637accb 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/argument-wrong-type.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.TimeZone("UTC"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -23,8 +23,14 @@ const rangeErrorTests = [ [Temporal.Instant, "Temporal.Instant, object"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.getOffsetNanosecondsFor(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === "string" || (typeof arg === "object" && arg !== null) || typeof arg === "function" + ? RangeError + : TypeError, + () => instance.getOffsetNanosecondsFor(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-not-absolute-getOffsetNanosecondsFor-override.js b/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-not-absolute-getOffsetNanosecondsFor-override.js index 9922140e4d3..1cbebe0e6e3 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-not-absolute-getOffsetNanosecondsFor-override.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-not-absolute-getOffsetNanosecondsFor-override.js @@ -10,12 +10,12 @@ features: [Temporal] const timeZone = Temporal.TimeZone.from("UTC"); let called = false; timeZone.getOffsetNanosecondsFor = () => called = true; -assert.throws(RangeError, () => timeZone.getOffsetStringFor(undefined), "undefined"); -assert.throws(RangeError, () => timeZone.getOffsetStringFor(null), "null"); -assert.throws(RangeError, () => timeZone.getOffsetStringFor(true), "boolean"); +assert.throws(TypeError, () => timeZone.getOffsetStringFor(undefined), "undefined"); +assert.throws(TypeError, () => timeZone.getOffsetStringFor(null), "null"); +assert.throws(TypeError, () => timeZone.getOffsetStringFor(true), "boolean"); assert.throws(RangeError, () => timeZone.getOffsetStringFor(""), "empty string"); assert.throws(TypeError, () => timeZone.getOffsetStringFor(Symbol()), "Symbol"); -assert.throws(RangeError, () => timeZone.getOffsetStringFor(5), "number"); -assert.throws(RangeError, () => timeZone.getOffsetStringFor(5n), "bigint"); +assert.throws(TypeError, () => timeZone.getOffsetStringFor(5), "number"); +assert.throws(TypeError, () => timeZone.getOffsetStringFor(5n), "bigint"); assert.throws(RangeError, () => timeZone.getOffsetStringFor({}), "plain object"); assert.sameValue(called, false); diff --git a/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-wrong-type.js b/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-wrong-type.js index 9838043bfa7..9a070edc31c 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-wrong-type.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.TimeZone("UTC"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -23,8 +23,14 @@ const rangeErrorTests = [ [Temporal.Instant, "Temporal.Instant, object"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.getOffsetStringFor(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === "string" || (typeof arg === "object" && arg !== null) || typeof arg === "function" + ? RangeError + : TypeError, + () => instance.getOffsetStringFor(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/argument-not-absolute-getOffsetNanosecondsFor-override.js b/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/argument-not-absolute-getOffsetNanosecondsFor-override.js index ffc3816506e..c3b94ef1f41 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/argument-not-absolute-getOffsetNanosecondsFor-override.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/argument-not-absolute-getOffsetNanosecondsFor-override.js @@ -10,12 +10,12 @@ features: [Temporal] const timeZone = Temporal.TimeZone.from("UTC"); let called = false; timeZone.getOffsetNanosecondsFor = () => called = true; -assert.throws(RangeError, () => timeZone.getPlainDateTimeFor(undefined), "undefined"); -assert.throws(RangeError, () => timeZone.getPlainDateTimeFor(null), "null"); -assert.throws(RangeError, () => timeZone.getPlainDateTimeFor(true), "boolean"); +assert.throws(TypeError, () => timeZone.getPlainDateTimeFor(undefined), "undefined"); +assert.throws(TypeError, () => timeZone.getPlainDateTimeFor(null), "null"); +assert.throws(TypeError, () => timeZone.getPlainDateTimeFor(true), "boolean"); assert.throws(RangeError, () => timeZone.getPlainDateTimeFor(""), "empty string"); assert.throws(TypeError, () => timeZone.getPlainDateTimeFor(Symbol()), "Symbol"); -assert.throws(RangeError, () => timeZone.getPlainDateTimeFor(5), "number"); -assert.throws(RangeError, () => timeZone.getPlainDateTimeFor(5n), "bigint"); +assert.throws(TypeError, () => timeZone.getPlainDateTimeFor(5), "number"); +assert.throws(TypeError, () => timeZone.getPlainDateTimeFor(5n), "bigint"); assert.throws(RangeError, () => timeZone.getPlainDateTimeFor({}), "plain object"); assert.sameValue(called, false); diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/argument-wrong-type.js b/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/argument-wrong-type.js index 087f7a1f8a7..94a5fab8ae7 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/argument-wrong-type.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.TimeZone("UTC"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -23,8 +23,14 @@ const rangeErrorTests = [ [Temporal.Instant, "Temporal.Instant, object"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.getPlainDateTimeFor(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === "string" || (typeof arg === "object" && arg !== null) || typeof arg === "function" + ? RangeError + : TypeError, + () => instance.getPlainDateTimeFor(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-number.js b/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-number.js index f48725772e2..9deb3a0f323 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-number.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.timezone.prototype.getplaindatetimefor -description: A number is converted to a string, then to Temporal.Calendar +description: A number is not allowed to be a calendar features: [Temporal] ---*/ const instance = new Temporal.TimeZone("UTC"); -const arg = 19761118; - -const result = instance.getPlainDateTimeFor(new Temporal.Instant(0n), arg); -assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar"); - const numbers = [ 1, -19761118, + 19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.getPlainDateTimeFor(new Temporal.Instant(0n), arg), - `Number ${arg} does not convert to a valid ISO string for Calendar` + "A number is not a valid ISO string for Calendar" ); } diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-wrong-type.js b/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-wrong-type.js index 10b657796dd..f4084d60ad4 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-wrong-type.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.TimeZone("UTC"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -19,8 +19,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.getPlainDateTimeFor(new Temporal.Instant(0n), arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.getPlainDateTimeFor(new Temporal.Instant(0n), arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-not-datetime.js b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-not-datetime.js index f6107979367..9d243db4a1c 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-not-datetime.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-not-datetime.js @@ -8,11 +8,11 @@ features: [Temporal] ---*/ const timeZone = Temporal.TimeZone.from("UTC"); -assert.throws(RangeError, () => timeZone.getPossibleInstantsFor(undefined), "undefined"); -assert.throws(RangeError, () => timeZone.getPossibleInstantsFor(null), "null"); -assert.throws(RangeError, () => timeZone.getPossibleInstantsFor(true), "boolean"); +assert.throws(TypeError, () => timeZone.getPossibleInstantsFor(undefined), "undefined"); +assert.throws(TypeError, () => timeZone.getPossibleInstantsFor(null), "null"); +assert.throws(TypeError, () => timeZone.getPossibleInstantsFor(true), "boolean"); assert.throws(RangeError, () => timeZone.getPossibleInstantsFor(""), "empty string"); assert.throws(TypeError, () => timeZone.getPossibleInstantsFor(Symbol()), "Symbol"); -assert.throws(RangeError, () => timeZone.getPossibleInstantsFor(5), "number"); -assert.throws(RangeError, () => timeZone.getPossibleInstantsFor(5n), "bigint"); +assert.throws(TypeError, () => timeZone.getPossibleInstantsFor(5), "number"); +assert.throws(TypeError, () => timeZone.getPossibleInstantsFor(5n), "bigint"); assert.throws(TypeError, () => timeZone.getPossibleInstantsFor({}), "plain object"); diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-number.js b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-number.js index a5894c8bf0e..1fcf44f0a9d 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-number.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-number.js @@ -3,28 +3,23 @@ /*--- esid: sec-temporal.timezone.prototype.getpossibleinstantsfor -description: A number is converted to a string, then to Temporal.PlainDateTime -includes: [compareArray.js] +description: A number cannot be used in place of a Temporal.PlainDateTime features: [Temporal] ---*/ const instance = new Temporal.TimeZone("UTC"); -let arg = 19761118; - -const result = instance.getPossibleInstantsFor(arg); -assert.compareArray(result.map(i => i.epochNanoseconds), [217_123_200_000_000_000n], "19761118 is a valid ISO string for PlainDateTime"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.getPossibleInstantsFor(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDateTime` + "A number is not a valid ISO string for PlainDateTime" ); } diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-number.js index 9e2821f5cd1..3f404de7409 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-number.js @@ -3,21 +3,15 @@ /*--- esid: sec-temporal.timezone.prototype.getpossibleinstantsfor -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [compareArray.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.TimeZone("UTC"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.getPossibleInstantsFor(arg); -assert.compareArray(result.map(i => i.epochNanoseconds), [217_123_200_000_000_000n], "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -25,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.getPossibleInstantsFor(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-wrong-type.js index ac83d439b10..31643beedaf 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.TimeZone("UTC"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.getPossibleInstantsFor(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.getPossibleInstantsFor(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-wrong-type.js b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-wrong-type.js index 40cd622852c..9b12a1a80b4 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-wrong-type.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.TimeZone("UTC"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.getPossibleInstantsFor(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.getPossibleInstantsFor(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPreviousTransition/argument-wrong-type.js b/test/built-ins/Temporal/TimeZone/prototype/getPreviousTransition/argument-wrong-type.js index 5cda1891657..1bd6dd29933 100644 --- a/test/built-ins/Temporal/TimeZone/prototype/getPreviousTransition/argument-wrong-type.js +++ b/test/built-ins/Temporal/TimeZone/prototype/getPreviousTransition/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.TimeZone("UTC"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -23,8 +23,14 @@ const rangeErrorTests = [ [Temporal.Instant, "Temporal.Instant, object"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.getPreviousTransition(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === "string" || (typeof arg === "object" && arg !== null) || typeof arg === "function" + ? RangeError + : TypeError, + () => instance.getPreviousTransition(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/calendar-number.js index 1d2409c1109..0edb6e4650f 100644 --- a/test/built-ins/Temporal/ZonedDateTime/calendar-number.js +++ b/test/built-ins/Temporal/ZonedDateTime/calendar-number.js @@ -3,25 +3,21 @@ /*--- esid: sec-temporal.zoneddatetime -description: A number is converted to a string, then to Temporal.Calendar +description: A number is not allowed to be a calendar features: [Temporal] ---*/ -const arg = 19761118; - -const result = new Temporal.ZonedDateTime(0n, "UTC", arg); -assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar"); - const numbers = [ 1, -19761118, + 19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => new Temporal.ZonedDateTime(0n, "UTC", arg), - `Number ${arg} does not convert to a valid ISO string for Calendar` + "A number is not a valid ISO string for Calendar" ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/calendar-wrong-type.js index 537bcca972b..6aa4667067c 100644 --- a/test/built-ins/Temporal/ZonedDateTime/calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,8 +17,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => new Temporal.ZonedDateTime(0n, "UTC", arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => new Temporal.ZonedDateTime(0n, "UTC", arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-number.js index 50cc9b4cb68..e01d722949e 100644 --- a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-number.js @@ -3,23 +3,16 @@ /*--- esid: sec-temporal.zoneddatetime.compare -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const calendar = 19970327; - const timeZone = new Temporal.TimeZone("UTC"); const datetime = new Temporal.ZonedDateTime(0n, timeZone); -const arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone }; -const result1 = Temporal.ZonedDateTime.compare(arg, datetime); -assert.sameValue(result1, 0, "19970327 is a valid ISO string for calendar (first argument)"); -const result2 = Temporal.ZonedDateTime.compare(datetime, arg); -assert.sameValue(result2, 0, "19970327 is a valid ISO string for calendar (second argument)"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -27,13 +20,13 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone }; assert.throws( - RangeError, + TypeError, () => Temporal.ZonedDateTime.compare(arg, datetime), - `Number ${calendar} does not convert to a valid ISO string for calendar (first argument)` + "A number is not a valid ISO string for calendar (first argument)" ); assert.throws( - RangeError, + TypeError, () => Temporal.ZonedDateTime.compare(datetime, arg), - `Number ${calendar} does not convert to a valid ISO string for calendar (second argument)` + "A number is not a valid ISO string for calendar (second argument)" ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-wrong-type.js index b0a235e9396..3641ce8f63b 100644 --- a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const datetime = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("UTC")); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -19,10 +19,18 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(arg, datetime), `${description} does not convert to a valid ISO string (first argument)`); - assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(datetime, arg), `${description} does not convert to a valid ISO string (second argument)`); + assert.throws( + typeof calendar === "string" ? RangeError : TypeError, + () => Temporal.ZonedDateTime.compare(arg, datetime), + `${description} does not convert to a valid ISO string (first argument)` + ); + assert.throws( + typeof calendar === "string" ? RangeError : TypeError, + () => Temporal.ZonedDateTime.compare(datetime, arg), + `${description} does not convert to a valid ISO string (second argument)` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-invalid-offset-string.js index 6a10a37901e..63baaa1af72 100644 --- a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-invalid-offset-string.js +++ b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-invalid-offset-string.js @@ -14,10 +14,21 @@ const badOffsets = [ "00:00", // missing sign "+0", // too short "-000:00", // too long - 0, // converts to a string that is invalid + 0, // must be a string + null, // must be a string + true, // must be a string + 1000n, // must be a string ]; badOffsets.forEach((offset) => { const arg = { year: 2021, month: 10, day: 28, offset, timeZone }; - assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(arg, datetime), `"${offset} is not a valid offset string (second argument)`); - assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(datetime, arg), `"${offset} is not a valid offset string (second argument)`); + assert.throws( + typeof(offset) === 'string' ? RangeError : TypeError, + () => Temporal.ZonedDateTime.compare(arg, datetime), + `"${offset} is not a valid offset string (second argument)` + ); + assert.throws( + typeof(offset) === 'string' ? RangeError : TypeError, + () => Temporal.ZonedDateTime.compare(datetime, arg), + `"${offset} is not a valid offset string (second argument)` + ); }); diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-timezone-string-multiple-offsets.js b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-timezone-string-multiple-offsets.js index 32c03c5f7e3..2e47557fa1a 100644 --- a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-timezone-string-multiple-offsets.js +++ b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-timezone-string-multiple-offsets.js @@ -14,4 +14,4 @@ const timeZone = "2021-08-19T17:30:45.123456789+01:46[+01:45:30.987654321]"; const result1 = Temporal.ZonedDateTime.compare({ year: 2020, month: 5, day: 2, timeZone }, instance); assert.sameValue(result1, 0, "Time zone string determined from bracket name (first argument)"); const result2 = Temporal.ZonedDateTime.compare(instance, { year: 2020, month: 5, day: 2, timeZone }); -assert.sameValue(result2, 0, "Time zone string determined from bracket name (first argument)"); +assert.sameValue(result2, 0, "Time zone string determined from bracket name (second argument)"); diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-timezone-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-timezone-wrong-type.js index 12ae11172c7..7c6ec7d0efc 100644 --- a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-timezone-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const datetime = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("UTC")); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,17 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.ZonedDateTime.compare({ year: 2020, month: 5, day: 2, timeZone }, datetime), `${description} does not convert to a valid ISO string (first argument)`); - assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(datetime, { year: 2020, month: 5, day: 2, timeZone }), `${description} does not convert to a valid ISO string (second argument)`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => Temporal.ZonedDateTime.compare({ year: 2020, month: 5, day: 2, timeZone }, datetime), + `${description} does not convert to a valid ISO string (first argument)` + ); + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => Temporal.ZonedDateTime.compare(datetime, { year: 2020, month: 5, day: 2, timeZone }), + `${description} does not convert to a valid ISO string (second argument)` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/argument-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/compare/argument-wrong-type.js index b6ca567fefc..6e8600fdaf0 100644 --- a/test/built-ins/Temporal/ZonedDateTime/compare/argument-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/compare/argument-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const other = new Temporal.ZonedDateTime(0n, timeZone); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -22,9 +22,17 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(arg, other), `${description} does not convert to a valid ISO string (first argument)`); - assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(other, arg), `${description} does not convert to a valid ISO string (second argument)`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.ZonedDateTime.compare(arg, other), + `${description} does not convert to a valid ISO string (first argument)` + ); + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.ZonedDateTime.compare(other, arg), + `${description} does not convert to a valid ISO string (second argument)` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/calendar-datefromfields-called-with-null-prototype-fields.js b/test/built-ins/Temporal/ZonedDateTime/compare/calendar-datefromfields-called-with-null-prototype-fields.js index 0f36f38ccc5..d5c3ae63f0b 100644 --- a/test/built-ins/Temporal/ZonedDateTime/compare/calendar-datefromfields-called-with-null-prototype-fields.js +++ b/test/built-ins/Temporal/ZonedDateTime/compare/calendar-datefromfields-called-with-null-prototype-fields.js @@ -20,4 +20,4 @@ assert.sameValue(calendar.dateFromFieldsCallCount, 1, "dateFromFields should be calendar.dateFromFieldsCallCount = 0; Temporal.ZonedDateTime.compare(arg2, arg1); -assert.sameValue(calendar.dateFromFieldsCallCount, 1, "dateFromFields should be called on the property bag's calendar (first argument)"); +assert.sameValue(calendar.dateFromFieldsCallCount, 1, "dateFromFields should be called on the property bag's calendar (second argument)"); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-number.js index 750cbeda5d7..fc9dbcb170a 100644 --- a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-number.js @@ -3,19 +3,15 @@ /*--- esid: sec-temporal.zoneddatetime.from -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ -const calendar = 19970327; - const timeZone = new Temporal.TimeZone("UTC"); -const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar }; -const result = Temporal.ZonedDateTime.from(arg); -assert.sameValue(result.calendarId, "iso8601", "19970327 is a valid ISO string for calendar"); const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -23,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar }; assert.throws( - RangeError, + TypeError, () => Temporal.ZonedDateTime.from(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-wrong-type.js index c2b810525f2..e4d9cb78859 100644 --- a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -17,9 +17,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => Temporal.ZonedDateTime.from(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => Temporal.ZonedDateTime.from(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-invalid-offset-string.js index edbb81772b1..daf623d3b0d 100644 --- a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-invalid-offset-string.js +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-invalid-offset-string.js @@ -15,13 +15,16 @@ const badOffsets = [ "00:00", // missing sign "+0", // too short "-000:00", // too long - 0, // converts to a string that is invalid + 0, // must be a string + null, // must be a string + true, // must be a string + 1000n, // must be a string ]; offsetOptions.forEach((offsetOption) => { badOffsets.forEach((offset) => { const arg = { year: 2021, month: 10, day: 28, offset, timeZone }; assert.throws( - RangeError, + typeof(offset) === 'string' ? RangeError : TypeError, () => Temporal.ZonedDateTime.from(arg, { offset: offsetOption }), `"${offset} is not a valid offset string (with offset option ${offsetOption})` ); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-timezone-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-timezone-wrong-type.js index d4e814ebbe5..0e49c1ccaf6 100644 --- a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-timezone-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-timezone-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.ZonedDateTime.from({ year: 2000, month: 5, day: 2, timeZone }), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => Temporal.ZonedDateTime.from({ year: 2000, month: 5, day: 2, timeZone }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-wrong-type.js index d2a424fb4e7..d111889e5ca 100644 --- a/test/built-ins/Temporal/ZonedDateTime/from/argument-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -19,8 +19,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => Temporal.ZonedDateTime.from(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => Temporal.ZonedDateTime.from(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-not-object.js b/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-not-object.js index 51d6ade9a7a..3b53fda9bf8 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-not-object.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-not-object.js @@ -8,12 +8,12 @@ features: [Symbol, Temporal] ---*/ const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); -assert.throws(RangeError, () => instance.add(undefined), "undefined"); -assert.throws(RangeError, () => instance.add(null), "null"); -assert.throws(RangeError, () => instance.add(true), "boolean"); +assert.throws(TypeError, () => instance.add(undefined), "undefined"); +assert.throws(TypeError, () => instance.add(null), "null"); +assert.throws(TypeError, () => instance.add(true), "boolean"); assert.throws(RangeError, () => instance.add(""), "empty string"); assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); -assert.throws(RangeError, () => instance.add(7), "number"); -assert.throws(RangeError, () => instance.add(7n), "bigint"); +assert.throws(TypeError, () => instance.add(7), "number"); +assert.throws(TypeError, () => instance.add(7n), "bigint"); assert.throws(TypeError, () => instance.add([]), "array"); assert.throws(TypeError, () => instance.add(() => {}), "function"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-number.js index 7d1b55efd12..06248b267fb 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-number.js @@ -3,21 +3,16 @@ /*--- esid: sec-temporal.zoneddatetime.prototype.equals -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.ZonedDateTime(0n, timeZone); -const calendar = 19970327; - -const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar }; -const result = instance.equals(arg); -assert.sameValue(result, true, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -25,8 +20,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar }; assert.throws( - RangeError, + TypeError, () => instance.equals(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js index a78ed4b4edd..794e1d61259 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.ZonedDateTime(0n, timeZone); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.equals(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-invalid-offset-string.js index 35f4b6d469f..18538ce5ab6 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-invalid-offset-string.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-invalid-offset-string.js @@ -14,9 +14,16 @@ const badOffsets = [ "00:00", // missing sign "+0", // too short "-000:00", // too long - 0, // converts to a string that is invalid + 0, // must be a string + null, // must be a string + true, // must be a string + 1000n, // must be a string ]; badOffsets.forEach((offset) => { const arg = { year: 2021, month: 10, day: 28, offset, timeZone }; - assert.throws(RangeError, () => instance.equals(arg), `"${offset} is not a valid offset string`); + assert.throws( + typeof(offset) === 'string' ? RangeError : TypeError, + () => instance.equals(arg), + `"${offset} is not a valid offset string` + ); }); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-wrong-type.js index 2f5480eea3e..5f8aa22f5e7 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("UTC")); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.equals({ year: 2020, month: 5, day: 2, timeZone }), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => instance.equals({ year: 2020, month: 5, day: 2, timeZone }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-wrong-type.js index 32294fc757b..4cf570fd748 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.ZonedDateTime(0n, timeZone); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -22,8 +22,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.equals(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-number.js index 78d9c51616a..7b318fbf4d3 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-number.js @@ -3,22 +3,16 @@ /*--- esid: sec-temporal.zoneddatetime.prototype.since -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.ZonedDateTime(0n, timeZone); -const calendar = 19970327; - -const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar }; -const result = instance.since(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -26,8 +20,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar }; assert.throws( - RangeError, + TypeError, () => instance.since(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js index d9c064e7476..7b9aa6dccf6 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.ZonedDateTime(0n, timeZone); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.since(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.since(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-invalid-offset-string.js index 80a15d787c5..8aa2efceb5c 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-invalid-offset-string.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-invalid-offset-string.js @@ -14,9 +14,16 @@ const badOffsets = [ "00:00", // missing sign "+0", // too short "-000:00", // too long - 0, // converts to a string that is invalid + 0, // must be a string + null, // must be a string + true, // must be a string + 1000n, // must be a string ]; badOffsets.forEach((offset) => { const arg = { year: 2021, month: 10, day: 28, offset, timeZone }; - assert.throws(RangeError, () => instance.since(arg), `"${offset} is not a valid offset string`); + assert.throws( + typeof(offset) === 'string' ? RangeError : TypeError, + () => instance.since(arg), + `"${offset} is not a valid offset string` + ); }); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-timezone-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-timezone-wrong-type.js index 4535b54017e..5278a935d71 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-timezone-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("UTC")); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.since({ year: 2020, month: 5, day: 2, timeZone }), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => instance.since({ year: 2020, month: 5, day: 2, timeZone }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-wrong-type.js index d4824739f44..65793e8dec9 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.ZonedDateTime(0n, timeZone); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -22,8 +22,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.since(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.since(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-not-object.js b/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-not-object.js index 5da56f46309..a74e7fbadfc 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-not-object.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-not-object.js @@ -8,12 +8,12 @@ features: [Symbol, Temporal] ---*/ const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); -assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); -assert.throws(RangeError, () => instance.subtract(null), "null"); -assert.throws(RangeError, () => instance.subtract(true), "boolean"); +assert.throws(TypeError, () => instance.subtract(undefined), "undefined"); +assert.throws(TypeError, () => instance.subtract(null), "null"); +assert.throws(TypeError, () => instance.subtract(true), "boolean"); assert.throws(RangeError, () => instance.subtract(""), "empty string"); assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); -assert.throws(RangeError, () => instance.subtract(7), "number"); -assert.throws(RangeError, () => instance.subtract(7n), "bigint"); +assert.throws(TypeError, () => instance.subtract(7), "number"); +assert.throws(TypeError, () => instance.subtract(7n), "bigint"); assert.throws(TypeError, () => instance.subtract([]), "array"); assert.throws(TypeError, () => instance.subtract(() => {}), "function"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-number.js index 80f6fa3f5b8..c3e14bef3f3 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-number.js @@ -3,22 +3,16 @@ /*--- esid: sec-temporal.zoneddatetime.prototype.until -description: A number as calendar in a property bag is converted to a string, then to a calendar -includes: [temporalHelpers.js] +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.ZonedDateTime(0n, timeZone); -const calendar = 19970327; - -const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar }; -const result = instance.until(arg); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -26,8 +20,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar }; assert.throws( - RangeError, + TypeError, () => instance.until(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js index b2ab7ba2594..fea32897da0 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.ZonedDateTime(0n, timeZone); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.until(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.until(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-invalid-offset-string.js index adcbc5b9d92..65c1091f9b5 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-invalid-offset-string.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-invalid-offset-string.js @@ -14,9 +14,16 @@ const badOffsets = [ "00:00", // missing sign "+0", // too short "-000:00", // too long - 0, // converts to a string that is invalid + 0, // must be a string + null, // must be a string + true, // must be a string + 1000n, // must be a string ]; badOffsets.forEach((offset) => { const arg = { year: 2021, month: 10, day: 28, offset, timeZone }; - assert.throws(RangeError, () => instance.until(arg), `"${offset} is not a valid offset string`); + assert.throws( + typeof(offset) === 'string' ? RangeError : TypeError, + () => instance.until(arg), + `"${offset} is not a valid offset string` + ); }); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-timezone-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-timezone-wrong-type.js index 9f3dcd50419..479d405086b 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-timezone-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("UTC")); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.until({ year: 2020, month: 5, day: 2, timeZone }), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => instance.until({ year: 2020, month: 5, day: 2, timeZone }), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-wrong-type.js index 79609f3e2b8..528825459d3 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.ZonedDateTime(0n, timeZone); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -22,8 +22,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.until(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.until(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/with/offset-property-invalid-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/with/offset-property-invalid-string.js index 18e5cb4074b..432a00c5951 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/with/offset-property-invalid-string.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/with/offset-property-invalid-string.js @@ -16,12 +16,15 @@ const badOffsets = [ "00:00", // missing sign "+0", // too short "-000:00", // too long - 0, // converts to a string that is invalid + 0, // must be a string + null, // must be a string + true, // must be a string + 1000n, // must be a string ]; offsetOptions.forEach((offsetOption) => { badOffsets.forEach((offset) => { assert.throws( - RangeError, + typeof(offset) === 'string' ? RangeError : TypeError, () => instance.with({ offset }, { offset: offsetOption }), `"${offset} is not a valid offset string (with ${offsetOption} offset option)`, ); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js index b7a194d7870..07bf8b3603b 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js @@ -3,7 +3,7 @@ /*--- esid: sec-temporal.zoneddatetime.prototype.withcalendar -description: A number is converted to a string, then to Temporal.Calendar +description: A number is not allowed to be a calendar features: [Temporal] ---*/ @@ -31,21 +31,17 @@ const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", { yearOfWeek() {}, }); -const arg = 19761118; - -const result = instance.withCalendar(arg); -assert.sameValue(result.calendarId, "iso8601", "19761118 is a valid ISO string for Calendar"); - const numbers = [ 1, -19761118, + 19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.withCalendar(arg), - `Number ${arg} does not convert to a valid ISO string for Calendar` + "A number is not a valid ISO string for Calendar" ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-wrong-type.js index 55b122aed45..382c7bdf864 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-wrong-type.js @@ -33,7 +33,7 @@ const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", { yearOfWeek() {}, }); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -41,8 +41,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.withCalendar(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.withCalendar(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/missing-argument.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/missing-argument.js index 4ae04818fba..13b94a70b65 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/missing-argument.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/missing-argument.js @@ -3,10 +3,10 @@ /*--- esid: sec-temporal.zoneddatetime.prototype.withcalendar -description: RangeError thrown when calendar argument not given +description: TypeError thrown when calendar argument not given features: [Temporal] ---*/ const zonedDateTime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC"); -assert.throws(RangeError, () => zonedDateTime.withCalendar(), "missing argument"); -assert.throws(RangeError, () => zonedDateTime.withCalendar(undefined), "undefined argument"); +assert.throws(TypeError, () => zonedDateTime.withCalendar(), "missing argument"); +assert.throws(TypeError, () => zonedDateTime.withCalendar(undefined), "undefined argument"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-number.js index f251b281fda..ff2cb7d69b4 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-number.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.zoneddatetime.prototype.withplaindate -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); -const arg = 19761118; - -const result = instance.withPlainDate(arg); -assert.sameValue(result.epochNanoseconds, 217_129_600_000_000_000n, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.withPlainDate(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js index 96d1f007491..0c222b6ed66 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js @@ -3,21 +3,16 @@ /*--- esid: sec-temporal.zoneddatetime.prototype.withplaindate -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, timeZone); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.withPlainDate(arg); -assert.sameValue(result.epochNanoseconds, 217_129_600_000_000_000n, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -25,8 +20,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.withPlainDate(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-propertybag-calendar-wrong-type.js index f1c28a2d2aa..4324669c4a4 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, timeZone); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.withPlainDate(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.withPlainDate(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-wrong-type.js index 20a9cd9474e..f2a84262b8f 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.withPlainDate(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.withPlainDate(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-number.js index 13dc510e5b3..a5fb9859829 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-number.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-number.js @@ -3,17 +3,12 @@ /*--- esid: sec-temporal.zoneddatetime.prototype.withplaintime -description: A number is converted to a string, then to Temporal.PlainTime +description: A number is invalid in place of an ISO string for Temporal.PlainTime features: [Temporal] ---*/ const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); -const arg = 123456.987654321; - -const result = instance.withPlainTime(arg); -assert.sameValue(result.epochNanoseconds, 1000038896_987_654_321n, "123456.987654321 is a valid ISO string for PlainTime"); - const numbers = [ 1, -123456.987654321, @@ -23,8 +18,8 @@ const numbers = [ for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.withPlainTime(arg), - `Number ${arg} does not convert to a valid ISO string for PlainTime` + "A number is not a valid ISO string for PlainTime" ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-wrong-type.js index 85589a45b9b..fdf8cb3852a 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -19,8 +19,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.withPlainTime(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.withPlainTime(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withTimeZone/timezone-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withTimeZone/timezone-wrong-type.js index 96fee6b2cfe..2f185583f54 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withTimeZone/timezone-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withTimeZone/timezone-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.ZonedDateTime(0n, new Temporal.TimeZone("UTC")); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.withTimeZone(timeZone), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => instance.withTimeZone(timeZone), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/built-ins/Temporal/ZonedDateTime/timezone-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/timezone-wrong-type.js index c19d14e5e69..5399b24f0b5 100644 --- a/test/built-ins/Temporal/ZonedDateTime/timezone-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/timezone-wrong-type.js @@ -9,7 +9,7 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -18,8 +18,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [timeZone, description] of rangeErrorTests) { - assert.throws(RangeError, () => new Temporal.ZonedDateTime(0n, timeZone), `${description} does not convert to a valid ISO string`); +for (const [timeZone, description] of primitiveTests) { + assert.throws( + typeof timeZone === 'string' ? RangeError : TypeError, + () => new Temporal.ZonedDateTime(0n, timeZone), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-number.js b/test/intl402/Temporal/Calendar/prototype/era/argument-number.js index 1fde733db50..e215edd320c 100644 --- a/test/intl402/Temporal/Calendar/prototype/era/argument-number.js +++ b/test/intl402/Temporal/Calendar/prototype/era/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.era -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.era(arg); -assert.sameValue(result, undefined, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.era(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-number.js b/test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-number.js index 348130bb039..459fe5bf018 100644 --- a/test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-number.js +++ b/test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.era -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.era(arg); -assert.sameValue(result, undefined, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.era(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-wrong-type.js b/test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-wrong-type.js index 90c4346527e..74c82e89edb 100644 --- a/test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-wrong-type.js +++ b/test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.era(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.era(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-wrong-type.js b/test/intl402/Temporal/Calendar/prototype/era/argument-wrong-type.js index 209579e27cd..161a86e0c16 100644 --- a/test/intl402/Temporal/Calendar/prototype/era/argument-wrong-type.js +++ b/test/intl402/Temporal/Calendar/prototype/era/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.era(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.era(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-number.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-number.js index 9cecd5ed35a..ec8903e125c 100644 --- a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-number.js +++ b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-number.js @@ -3,27 +3,23 @@ /*--- esid: sec-temporal.calendar.prototype.erayear -description: A number is converted to a string, then to Temporal.PlainDate +description: A number cannot be used in place of a Temporal.PlainDate features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const arg = 19761118; - -const result = instance.eraYear(arg); -assert.sameValue(result, undefined, "19761118 is a valid ISO string for PlainDate"); - const numbers = [ 1, + 19761118, -19761118, 1234567890, ]; for (const arg of numbers) { assert.throws( - RangeError, + TypeError, () => instance.eraYear(arg), - `Number ${arg} does not convert to a valid ISO string for PlainDate` + 'Numbers cannot be used in place of an ISO string for PlainDate' ); } diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-number.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-number.js index 7ea80459f9a..190e3f6427a 100644 --- a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-number.js +++ b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-number.js @@ -3,20 +3,15 @@ /*--- esid: sec-temporal.calendar.prototype.erayear -description: A number as calendar in a property bag is converted to a string, then to a calendar +description: A number as calendar in a property bag is not accepted features: [Temporal] ---*/ const instance = new Temporal.Calendar("iso8601"); -const calendar = 19970327; - -const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; -const result = instance.eraYear(arg); -assert.sameValue(result, undefined, "19970327 is a valid ISO string for calendar"); - const numbers = [ 1, + 19970327, -19970327, 1234567890, ]; @@ -24,8 +19,8 @@ const numbers = [ for (const calendar of numbers) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - RangeError, + TypeError, () => instance.eraYear(arg), - `Number ${calendar} does not convert to a valid ISO string for calendar` + "Numbers cannot be used as a calendar" ); } diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-wrong-type.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-wrong-type.js index 4e9f42a80c5..3ca62d1d64a 100644 --- a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-wrong-type.js +++ b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-wrong-type.js @@ -12,7 +12,7 @@ features: [BigInt, Symbol, Temporal] const timeZone = new Temporal.TimeZone("UTC"); const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [null, "null"], [true, "boolean"], ["", "empty string"], @@ -20,9 +20,13 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [calendar, description] of rangeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(RangeError, () => instance.eraYear(arg), `${description} does not convert to a valid ISO string`); + assert.throws( + typeof calendar === 'string' ? RangeError : TypeError, + () => instance.eraYear(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-wrong-type.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-wrong-type.js index d30f3214af2..8cff13438a6 100644 --- a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-wrong-type.js +++ b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-wrong-type.js @@ -11,7 +11,7 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.Calendar("iso8601"); -const rangeErrorTests = [ +const primitiveTests = [ [undefined, "undefined"], [null, "null"], [true, "boolean"], @@ -20,8 +20,12 @@ const rangeErrorTests = [ [1n, "bigint"], ]; -for (const [arg, description] of rangeErrorTests) { - assert.throws(RangeError, () => instance.eraYear(arg), `${description} does not convert to a valid ISO string`); +for (const [arg, description] of primitiveTests) { + assert.throws( + typeof arg === 'string' ? RangeError : TypeError, + () => instance.eraYear(arg), + `${description} does not convert to a valid ISO string` + ); } const typeErrorTests = [ diff --git a/test/staging/Temporal/Duration/old/round.js b/test/staging/Temporal/Duration/old/round.js index 7a365981284..245d79a61e4 100644 --- a/test/staging/Temporal/Duration/old/round.js +++ b/test/staging/Temporal/Duration/old/round.js @@ -194,11 +194,11 @@ assert.sameValue(`${ hours25.round({ } }) }`, "P1DT1H"); -// accepts datetime string equivalents or fields for relativeTo +// accepts datetime strings or fields for relativeTo [ "2020-01-01", + "20200101", "2020-01-01T00:00:00.000000000", - 20200101n, { year: 2020, month: 1, @@ -211,6 +211,18 @@ assert.sameValue(`${ hours25.round({ }) }`, "P5Y5M5W5DT5H5M5S"); }); +// does not accept non-string primitives for relativeTo +[ + 20200101, + 20200101n, + null, + true, +].forEach(relativeTo => { + assert.throws( + TypeError, () => d.round({ smallestUnit: "seconds", relativeTo}) + ); +}); + // throws on wrong offset for ZonedDateTime relativeTo string assert.throws(RangeError, () => d.round({ smallestUnit: "seconds", diff --git a/test/staging/Temporal/Duration/old/total.js b/test/staging/Temporal/Duration/old/total.js index b551cd24c2e..67e852888df 100644 --- a/test/staging/Temporal/Duration/old/total.js +++ b/test/staging/Temporal/Duration/old/total.js @@ -35,11 +35,11 @@ var s = Temporal.Duration.from({ }).total({ unit: "seconds" }); assert.sameValue(s, 0.002031); -// accepts datetime string equivalents or fields for relativeTo +// accepts datetime strings or fields for relativeTo [ "2020-01-01", + "20200101", "2020-01-01T00:00:00.000000000", - 20200101n, { year: 2020, month: 1, @@ -58,6 +58,18 @@ assert.sameValue(s, 0.002031); assert.sameValue(total.toPrecision(15), totalMonths.toPrecision(15)); }); +// does not accept non-string primitives for relativeTo +[ + 20200101, + 20200101n, + null, + true, +].forEach(relativeTo => { + assert.throws( + TypeError, () => d.total({ unit: "months", relativeTo}) + ); +}); + // throws on wrong offset for ZonedDateTime relativeTo string assert.throws(RangeError, () => d.total({ unit: "months", diff --git a/test/staging/Temporal/Instant/old/toZonedDateTimeISO.js b/test/staging/Temporal/Instant/old/toZonedDateTimeISO.js index a5396938b2b..95986c44dd0 100644 --- a/test/staging/Temporal/Instant/old/toZonedDateTimeISO.js +++ b/test/staging/Temporal/Instant/old/toZonedDateTimeISO.js @@ -10,7 +10,7 @@ features: [Temporal] var inst = Temporal.Instant.from("1976-11-18T14:23:30.123456789Z"); // throws without parameter -assert.throws(RangeError, () => inst.toZonedDateTimeISO()); +assert.throws(TypeError, () => inst.toZonedDateTimeISO()); // time zone parameter UTC var tz = Temporal.TimeZone.from("UTC"); diff --git a/test/staging/Temporal/ZonedDateTime/old/property-bags.js b/test/staging/Temporal/ZonedDateTime/old/property-bags.js index 14f27c3b2a3..e49838a08ce 100644 --- a/test/staging/Temporal/ZonedDateTime/old/property-bags.js +++ b/test/staging/Temporal/ZonedDateTime/old/property-bags.js @@ -73,15 +73,29 @@ assert.sameValue(`${ Temporal.ZonedDateTime.from({ hours: 12 }) }`, "1976-11-18T00:00:00+01:00[+01:00]"); -// casts offset property -var zdt = Temporal.ZonedDateTime.from({ - year: 1976, - month: 11, - day: 18, - offset: -1030, - timeZone: Temporal.TimeZone.from("-10:30") +// does not accept non-string offset property +[ + null, + true, + 1000, + 1000n, + Symbol(), + {} +].forEach(offset => { + assert.throws( + typeof offset === "string" || (typeof offset === "object" && offset !== null) || typeof offset === "function" + ? RangeError + : TypeError, + () => Temporal.ZonedDateTime.from({ + year: 1976, + month: 11, + day: 18, + offset: offset, + timeZone: Temporal.TimeZone.from("+10:00") + }) + ) }); -assert.sameValue(`${ zdt }`, "1976-11-18T00:00:00-10:30[-10:30]"); + // overflow options var bad = {