diff --git a/test/built-ins/Temporal/Duration/prototype/add/result-out-of-range-1.js b/test/built-ins/Temporal/Duration/prototype/add/result-out-of-range-1.js index 3b2d1691e7..012ea5011b 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/result-out-of-range-1.js +++ b/test/built-ins/Temporal/Duration/prototype/add/result-out-of-range-1.js @@ -8,9 +8,26 @@ description: > features: [Temporal] ---*/ -// Largest temporal unit is "second". -const duration = Temporal.Duration.from({seconds: Number.MAX_SAFE_INTEGER}); +const maxSec = Number.MAX_SAFE_INTEGER; +const maxMs = 9_007_199_254_740_991_487; +const maxUs = 9_007_199_254_740_991_475_711; +const maxNs = 9_007_199_254_740_991_463_129_087; + +const durations = [ + Temporal.Duration.from({seconds: maxSec}), + Temporal.Duration.from({milliseconds: maxMs}), + Temporal.Duration.from({microseconds: maxUs}), + Temporal.Duration.from({nanoseconds: maxNs}), + Temporal.Duration.from({seconds: -maxSec}), + Temporal.Duration.from({milliseconds: -maxMs}), + Temporal.Duration.from({microseconds: -maxUs}), + Temporal.Duration.from({nanoseconds: -maxNs}), +] + +for (let duration of durations) { + assert.throws(RangeError, () => { + duration.add(duration); + }); +} + -assert.throws(RangeError, () => { - duration.add(duration); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/round/out-of-range-when-converting-from-normalized-duration.js b/test/built-ins/Temporal/Duration/prototype/round/out-of-range-when-converting-from-normalized-duration.js index bcac75e573..6b70423ebc 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/out-of-range-when-converting-from-normalized-duration.js +++ b/test/built-ins/Temporal/Duration/prototype/round/out-of-range-when-converting-from-normalized-duration.js @@ -9,8 +9,44 @@ description: > features: [Temporal] ---*/ -const d = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ Number.MAX_SAFE_INTEGER, 0, 0, /* ns = */ 999_999_999); -assert.throws(RangeError, () => d.round({ +/* +const maxMs = 9_007_199_254_740_991_487; +const maxUs = 9_007_199_254_740_991_475_711; +const maxNs = 9_007_199_254_740_991_463_129_087; +*/ + +const ms = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ Number.MAX_SAFE_INTEGER, /* ms = */ 488, 0, 0); +assert.throws(RangeError, () => ms.round({ largestUnit: "nanoseconds", roundingIncrement: 1, -}), "nanoseconds component after balancing as a float64-representable integer is out of range"); +}), "nanoseconds component after balancing as a float64-representable integer is out of range (maximum milliseconds)"); + +const us = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ Number.MAX_SAFE_INTEGER, 0, /* us = */ 475_712, 0); +assert.throws(RangeError, () => ms.round({ + largestUnit: "nanoseconds", + roundingIncrement: 1, +}), "nanoseconds component after balancing as a float64-representable integer is out of range (maximum microseconds)"); + +const ns = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ Number.MAX_SAFE_INTEGER, 0, 0, /* ns = */ 463_129_088); +assert.throws(RangeError, () => ns.round({ + largestUnit: "nanoseconds", + roundingIncrement: 1, +}), "nanoseconds component after balancing as a float64-representable integer is out of range (maximum nanoseconds)"); + +const msMin = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ -Number.MAX_SAFE_INTEGER, /* ms = */ -487, 0, 0); +assert.throws(RangeError, () => msMin.round({ + largestUnit: "nanoseconds", + roundingIncrement: 1, +}), "nanoseconds component after balancing as a float64-representable integer is out of range (minimum milliseconds)"); + +const usMin = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ -Number.MAX_SAFE_INTEGER, 0, /* us = */ -475_711, 0); +assert.throws(RangeError, () => usMin.round({ + largestUnit: "nanoseconds", + roundingIncrement: 1, +}), "nanoseconds component after balancing as a float64-representable integer is out of range (minimum microseconds)"); + +const nsMin = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ -Number.MAX_SAFE_INTEGER, 0, 0, /* ns = */ -463_129_088); +assert.throws(RangeError, () => nsMin.round({ + largestUnit: "nanoseconds", + roundingIncrement: 1, +}), "nanoseconds component after balancing as a float64-representable integer is out of range (minimum nanoseconds)"); diff --git a/test/built-ins/Temporal/Duration/prototype/round/total-duration-nanoseconds-too-large-with-zoned-datetime.js b/test/built-ins/Temporal/Duration/prototype/round/total-duration-nanoseconds-too-large-with-zoned-datetime.js index 88af2e9e34..f5f2084ad1 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/total-duration-nanoseconds-too-large-with-zoned-datetime.js +++ b/test/built-ins/Temporal/Duration/prototype/round/total-duration-nanoseconds-too-large-with-zoned-datetime.js @@ -8,9 +8,20 @@ description: > features: [Temporal] ---*/ -var duration = Temporal.Duration.from({ - seconds: Number.MAX_SAFE_INTEGER, -}); +const maxMs = 9_007_199_254_740_991_487; +const maxUs = 9_007_199_254_740_991_475_711; +const maxNs = 9_007_199_254_740_991_463_129_087; + +const durations = [ + Temporal.Duration.from({ seconds: Number.MAX_SAFE_INTEGER }), + Temporal.Duration.from({ milliseconds: maxMs }), + Temporal.Duration.from({ microseconds: maxUs }), + Temporal.Duration.from({ nanoseconds: maxNs }), + Temporal.Duration.from({ seconds: -Number.MAX_SAFE_INTEGER }), + Temporal.Duration.from({ milliseconds: -maxMs }), + Temporal.Duration.from({ microseconds: -maxUs }), + Temporal.Duration.from({ nanoseconds: -maxNs }), +]; var zonedDateTime = new Temporal.ZonedDateTime(0n, "UTC"); @@ -20,4 +31,6 @@ var options = { relativeTo: zonedDateTime, }; -assert.throws(RangeError, () => duration.round(options)); +for (let duration of durations) { + assert.throws(RangeError, () => duration.round(options)); +} diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/result-out-of-range-1.js b/test/built-ins/Temporal/Duration/prototype/subtract/result-out-of-range-1.js index 9418305760..28f1ee1842 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/result-out-of-range-1.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/result-out-of-range-1.js @@ -8,10 +8,24 @@ description: > features: [Temporal] ---*/ -// Largest temporal unit is "second". -const duration1 = Temporal.Duration.from({seconds: Number.MAX_SAFE_INTEGER}); -const duration2 = Temporal.Duration.from({seconds: -Number.MAX_SAFE_INTEGER}); +const maxSec = Number.MAX_SAFE_INTEGER; +const maxMs = 9_007_199_254_740_991_487; +const maxUs = 9_007_199_254_740_991_475_711; +const maxNs = 9_007_199_254_740_991_463_129_087; -assert.throws(RangeError, () => { - duration1.subtract(duration2); -}); +const durations = [ + Temporal.Duration.from({seconds: maxSec}), + Temporal.Duration.from({milliseconds: maxMs}), + Temporal.Duration.from({microseconds: maxUs}), + Temporal.Duration.from({nanoseconds: maxNs}), + Temporal.Duration.from({seconds: -maxSec}), + Temporal.Duration.from({milliseconds: -maxMs}), + Temporal.Duration.from({microseconds: -maxUs}), + Temporal.Duration.from({nanoseconds: -maxNs}), +]; + +for (let duration of durations) { + assert.throws(RangeError, () => { + duration.subtract(duration.negated()); + }, `subtracting the negation of a large duration from the duration is out of bounds: ${duration}`); +}