diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp index b531f444c8..7024a72388 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp @@ -783,8 +783,11 @@ ThrowCompletionOr balance_duration_relative(GlobalObject& gl return create_date_duration_record(years, months, weeks, days); } - // 2. Assert: relativeTo is not undefined, because callers of this operation ensure relativeTo is required in conditions where this algorithm does not return in step 1.a. - VERIFY(!relative_to_value.is_undefined()); + // 2. If relativeTo is undefined, then + if (relative_to_value.is_undefined()) { + // a. Throw a RangeError exception. + return vm.throw_completion(global_object, ErrorType::TemporalMissingStartingPoint, "calendar units"); + } // 3. Let sign be ! DurationSign(years, months, weeks, days, 0, 0, 0, 0, 0, 0). auto sign = duration_sign(years, months, weeks, days, 0, 0, 0, 0, 0, 0); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Duration/Duration.prototype.round.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Duration/Duration.prototype.round.js index c9df9501e8..28672bfa14 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/Duration/Duration.prototype.round.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/Duration/Duration.prototype.round.js @@ -161,4 +161,16 @@ describe("errors", () => { "A starting point is required for balancing calendar units" ); }); + + // Spec Issue: https://github.com/tc39/proposal-temporal/issues/2124 + // Spec Fix: https://github.com/tc39/proposal-temporal/commit/66f7464aaec64d3cd21fb2ec37f6502743b9a730 + test("balancing calendar units with largestUnit set to 'year' and relativeTo unset throws instead of crashing", () => { + const duration = new Temporal.Duration(1); + expect(() => { + duration.round({ largestUnit: "year" }); + }).toThrowWithMessage( + RangeError, + "A starting point is required for balancing calendar units" + ); + }); });