mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-13 03:29:49 +00:00
LibJS: Add workaround for invalid ISODateTimes in DifferenceISODateTime
The assertions can be hit when Temporal.Duration.prototype.round / total are provided a PlainDate at the very limits of valid date-times. Tests were recently added to test262 which trip these assertions, thus we are now crashing in those tests. Let's throw a RangeError instead, as this is the behavior expected by the tests.
This commit is contained in:
parent
784e872851
commit
6dfa6993e5
Notes:
github-actions[bot]
2024-12-05 21:06:25 +00:00
Author: https://github.com/trflynn89
Commit: 6dfa6993e5
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2790
Reviewed-by: https://github.com/gmta ✅
4 changed files with 24 additions and 7 deletions
|
@ -286,13 +286,14 @@ ISODateTime round_iso_date_time(ISODateTime const& iso_date_time, u64 increment,
|
|||
}
|
||||
|
||||
// 5.5.12 DifferenceISODateTime ( isoDateTime1, isoDateTime2, calendar, largestUnit ), https://tc39.es/proposal-temporal/#sec-temporal-differenceisodatetime
|
||||
InternalDuration difference_iso_date_time(VM& vm, ISODateTime const& iso_date_time1, ISODateTime const& iso_date_time2, StringView calendar, Unit largest_unit)
|
||||
ThrowCompletionOr<InternalDuration> difference_iso_date_time(VM& vm, ISODateTime const& iso_date_time1, ISODateTime const& iso_date_time2, StringView calendar, Unit largest_unit)
|
||||
{
|
||||
// 1. Assert: ISODateTimeWithinLimits(isoDateTime1) is true.
|
||||
VERIFY(iso_date_time_within_limits(iso_date_time1));
|
||||
|
||||
// 2. Assert: ISODateTimeWithinLimits(isoDateTime2) is true.
|
||||
VERIFY(iso_date_time_within_limits(iso_date_time2));
|
||||
// FIXME: Spec issue: Rather than asserting, throw a RangeError. See:
|
||||
// https://github.com/tc39/proposal-temporal/issues/3015
|
||||
if (!iso_date_time_within_limits(iso_date_time1) || !iso_date_time_within_limits(iso_date_time2))
|
||||
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidISODateTime);
|
||||
|
||||
// 3. Let timeDuration be DifferenceTime(isoDateTime1.[[Time]], isoDateTime2.[[Time]]).
|
||||
auto time_duration = difference_time(iso_date_time1.time, iso_date_time2.time);
|
||||
|
@ -344,7 +345,7 @@ ThrowCompletionOr<InternalDuration> difference_plain_date_time_with_rounding(VM&
|
|||
}
|
||||
|
||||
// 2. Let diff be DifferenceISODateTime(isoDateTime1, isoDateTime2, calendar, largestUnit).
|
||||
auto diff = difference_iso_date_time(vm, iso_date_time1, iso_date_time2, calendar, largest_unit);
|
||||
auto diff = TRY(difference_iso_date_time(vm, iso_date_time1, iso_date_time2, calendar, largest_unit));
|
||||
|
||||
// 3. If smallestUnit is NANOSECOND and roundingIncrement = 1, return diff.
|
||||
if (smallest_unit == Unit::Nanosecond && rounding_increment == 1)
|
||||
|
@ -367,7 +368,7 @@ ThrowCompletionOr<Crypto::BigFraction> difference_plain_date_time_with_total(VM&
|
|||
}
|
||||
|
||||
// 2. Let diff be DifferenceISODateTime(isoDateTime1, isoDateTime2, calendar, unit).
|
||||
auto diff = difference_iso_date_time(vm, iso_date_time1, iso_date_time2, calendar, unit);
|
||||
auto diff = TRY(difference_iso_date_time(vm, iso_date_time1, iso_date_time2, calendar, unit));
|
||||
|
||||
// 3. If unit is NANOSECOND, return diff.[[Time]].
|
||||
if (unit == Unit::Nanosecond)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue