diff --git a/test/built-ins/Temporal/Instant/fromEpochMilliseconds/argument.js b/test/built-ins/Temporal/Instant/fromEpochMilliseconds/argument.js new file mode 100644 index 0000000000..7fafd338d1 --- /dev/null +++ b/test/built-ins/Temporal/Instant/fromEpochMilliseconds/argument.js @@ -0,0 +1,17 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.fromepochmilliseconds +description: > + TypeError thrown if input is of wrong primitive type. +info: | + Temporal.Instant.fromEpochMilliseconds ( epochMilliseconds ) + + 1. Set epochMilliseconds to ? ToNumber(epochMilliseconds). + ... +features: [Temporal] +---*/ + +assert.throws(TypeError, () => Temporal.Instant.fromEpochMilliseconds(42n), "number"); +assert.throws(TypeError, () => Temporal.Instant.fromEpochMilliseconds(Symbol()), "symbol"); diff --git a/test/built-ins/Temporal/Instant/fromEpochMilliseconds/non-integer.js b/test/built-ins/Temporal/Instant/fromEpochMilliseconds/non-integer.js new file mode 100644 index 0000000000..b1e4af85fe --- /dev/null +++ b/test/built-ins/Temporal/Instant/fromEpochMilliseconds/non-integer.js @@ -0,0 +1,28 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.fromepochmilliseconds +description: > + RangeError thrown if input doesn't convert. +info: | + Temporal.Instant.fromEpochMilliseconds ( epochMilliseconds ) + + ... + 2. Set epochMilliseconds to ? NumberToBigInt(epochMilliseconds). + ... + + NumberToBigInt ( number ) + + 1. If number is not an integral Number, throw a RangeError exception. + ... +features: [Temporal] +---*/ + +assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(), "undefined"); +assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(undefined), "undefined"); +assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(Infinity), "Infinity"); +assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(-Infinity), "-Infinity"); +assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(NaN), "NaN"); +assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(1.3), "1.3"); +assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(-0.5), "-0.5"); diff --git a/test/built-ins/Temporal/Instant/fromEpochNanoseconds/argument.js b/test/built-ins/Temporal/Instant/fromEpochNanoseconds/argument.js new file mode 100644 index 0000000000..65684abd03 --- /dev/null +++ b/test/built-ins/Temporal/Instant/fromEpochNanoseconds/argument.js @@ -0,0 +1,20 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.fromepochnanoseconds +description: > + TypeError thrown if input is of wrong primitive type. +info: | + Temporal.Instant.fromEpochNanoseconds ( epochNanoseconds ) + + 1. Set epochNanoseconds to ? ToBigInt(epochNanoseconds). + ... +features: [Temporal] +---*/ + +assert.throws(TypeError, () => Temporal.Instant.fromEpochNanoseconds(), "undefined"); +assert.throws(TypeError, () => Temporal.Instant.fromEpochNanoseconds(undefined), "undefined"); +assert.throws(TypeError, () => Temporal.Instant.fromEpochNanoseconds(null), "null"); +assert.throws(TypeError, () => Temporal.Instant.fromEpochNanoseconds(42), "number"); +assert.throws(TypeError, () => Temporal.Instant.fromEpochNanoseconds(Symbol()), "symbol"); diff --git a/test/built-ins/Temporal/Instant/fromEpochNanoseconds/limits.js b/test/built-ins/Temporal/Instant/fromEpochNanoseconds/limits.js new file mode 100644 index 0000000000..f5a5d0c113 --- /dev/null +++ b/test/built-ins/Temporal/Instant/fromEpochNanoseconds/limits.js @@ -0,0 +1,20 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.fromepochnanoseconds +description: > + Throws a RangeError if the input is not a valid epoch nanoseconds value. +info: | + Temporal.Instant.fromEpochNanoseconds ( epochNanoseconds ) + + ... + 2. If IsValidEpochNanoseconds(epochNanoseconds) is false, throw a RangeError exception. + ... +features: [Temporal] +---*/ + +var limit = 8640000000000000000000n; + +assert.throws(RangeError, () => Temporal.Instant.fromEpochNanoseconds(-limit - 1n)); +assert.throws(RangeError, () => Temporal.Instant.fromEpochNanoseconds(limit + 1n)); diff --git a/test/built-ins/Temporal/Instant/get-prototype-from-constructor-throws.js b/test/built-ins/Temporal/Instant/get-prototype-from-constructor-throws.js new file mode 100644 index 0000000000..3a6c128fce --- /dev/null +++ b/test/built-ins/Temporal/Instant/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.instant +description: > + OrdinaryCreateFromConstructor returns with an abrupt completion. +info: | + CreateTemporalInstant ( epochNanoseconds [ , newTarget ] ) + + ... + 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, + "%Temporal.Instant.prototype%", « [[InitializedTemporalInstant]], [[EpochNanoseconds]] »). + ... + + 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.Instant, [0n], newTarget) +}); diff --git a/test/built-ins/Temporal/Instant/large-bigint.js b/test/built-ins/Temporal/Instant/large-bigint.js new file mode 100644 index 0000000000..aabf2bf279 --- /dev/null +++ b/test/built-ins/Temporal/Instant/large-bigint.js @@ -0,0 +1,21 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant +description: > + Throws a RangeError if the input is far away from the epoch nanoseconds limits. +features: [Temporal] +---*/ + +assert.throws( + RangeError, + () => new Temporal.Instant(2n ** 128n), + "2n ** 128n" +); + +assert.throws( + RangeError, + () => new Temporal.Instant(-(2n ** 128n)), + "-(2n ** 128n)" +); diff --git a/test/built-ins/Temporal/Instant/prototype/toString/get-timezone-throws.js b/test/built-ins/Temporal/Instant/prototype/toString/get-timezone-throws.js new file mode 100644 index 0000000000..5063829323 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toString/get-timezone-throws.js @@ -0,0 +1,25 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.tostring +description: > + Accessor property for "timeZone" throws an error. +info: | + Temporal.Instant.prototype.toString ( [ options ] ) + + ... + 9. Let timeZone be ? Get(resolvedOptions, "timeZone"). + ... +features: [Temporal] +---*/ + +var instance = new Temporal.Instant(0n); + +var options = { + get timeZone() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => instance.toString(options));