diff --git a/test/built-ins/Temporal/PlainTime/get-prototype-from-constructor-throws.js b/test/built-ins/Temporal/PlainTime/get-prototype-from-constructor-throws.js new file mode 100644 index 0000000000..d4579b7dcc --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/get-prototype-from-constructor-throws.js @@ -0,0 +1,39 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime +description: > + OrdinaryCreateFromConstructor returns with an abrupt completion. +info: | + CreateTemporalTime ( time [ , newTarget ] ) + + ... + 2. Let object be ? OrdinaryCreateFromConstructor(newTarget, + "%Temporal.PlainTime.prototype%", « [[InitializedTemporalTime]], [[Time]] »). + ... + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + ... + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 2. Let proto be ? Get(constructor, "prototype"). + ... + +features: [Temporal] +---*/ + +var newTarget = Object.defineProperty(function(){}.bind(), "prototype", { + get() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.construct(Temporal.PlainTime, [], newTarget) +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/with/throws-if-time-is-invalid-when-overflow-is-reject.js b/test/built-ins/Temporal/PlainTime/prototype/with/throws-if-time-is-invalid-when-overflow-is-reject.js new file mode 100644 index 0000000000..477dfb598c --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/with/throws-if-time-is-invalid-when-overflow-is-reject.js @@ -0,0 +1,51 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.with +description: > + Throws if overflow is "reject" and any value is outside the valid bounds. +info: | + Temporal.PlainTime.prototype.with ( temporalTimeLike [ , options ] ) + + ... + 19. Let result be ? RegulateTime(hour, minute, second, millisecond, microsecond, nanosecond, overflow). + ... + + RegulateTime ( hour, minute, second, millisecond, microsecond, nanosecond, overflow ) + + ... + 2. Else, + a. Assert: overflow is reject. + b. If IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception. + ... + +features: [Temporal] +---*/ + +var instance = new Temporal.PlainTime(); + +var temporalTimeLikes = [ + {hour: -1}, + {hour: 24}, + {minute: -1}, + {minute: 60}, + {second: -1}, + {second: 60}, + {millisecond: -1}, + {millisecond: 1000}, + {microsecond: -1}, + {microsecond: 1000}, + {nanosecond: -1}, + {nanosecond: 1000}, +]; + +var options = {overflow: "reject"}; + +for (var temporalTimeLike of temporalTimeLikes) { + assert.throws( + RangeError, + () => instance.with(temporalTimeLike, options), + `temporalTimeLike = ${JSON.stringify(temporalTimeLike)}` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/throws-if-time-is-invalid.js b/test/built-ins/Temporal/PlainTime/throws-if-time-is-invalid.js new file mode 100644 index 0000000000..43e569dfc0 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/throws-if-time-is-invalid.js @@ -0,0 +1,39 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime +description: > + Throws if any value is outside the valid bounds. +info: | + Temporal.PlainTime ( [ hour [ , minute [ , second [ , millisecond [ , microsecond [ , nanosecond ] ] ] ] ] ] ) + + ... + 8. If IsValidTime(hour, minute, second, millisecond, microsecond, nanosecond) is false, throw a RangeError exception. + ... + +features: [Temporal] +---*/ + +var invalidArgs = [ + [-1], + [24], + [0, -1], + [0, 60], + [0, 0, -1], + [0, 0, 60], + [0, 0, 0, -1], + [0, 0, 0, 1000], + [0, 0, 0, 0, -1], + [0, 0, 0, 0, 1000], + [0, 0, 0, 0, 0, -1], + [0, 0, 0, 0, 0, 1000], +]; + +for (var args of invalidArgs) { + assert.throws( + RangeError, + () => new Temporal.PlainTime(...args), + `args = ${JSON.stringify(args)}` + ); +}