1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:27:35 +00:00

LibJS: Require NanosecondsToDays remainder less than dayLength

This is an normative change in the Temporal spec.
See: ac69b63
This commit is contained in:
Moustafa Raafat 2022-10-21 23:03:44 +01:00 committed by Linus Groh
parent b1c8029c2b
commit 5edd4bd512
2 changed files with 9 additions and 1 deletions

View file

@ -554,7 +554,13 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(VM& vm, Crypto::S
if (nanoseconds.is_positive() && sign == -1)
return vm.throw_completion<RangeError>(ErrorType::TemporalNanosecondsConvertedToRemainderOfNanosecondsWithOppositeSign);
// 23. Return the Record { [[Days]]: days, [[Nanoseconds]]: nanoseconds, [[DayLength]]: abs(dayLengthNs) }.
// 23. If abs(nanoseconds) ≥ abs(dayLengthNs), throw a RangeError exception.
auto nanoseconds_absolute = nanoseconds.is_negative() ? nanoseconds.negated_value() : nanoseconds;
auto compare_result = nanoseconds_absolute.compare_to_double(fabs(day_length_ns.to_double()));
if (compare_result == Crypto::SignedBigInteger::CompareResult::DoubleLessThanBigInt || compare_result == Crypto::SignedBigInteger::CompareResult::DoubleEqualsBigInt)
return vm.throw_completion<RangeError>(ErrorType::TemporalNanosecondsConvertedToRemainderOfNanosecondsLongerThanDayLength);
// 24. Return the Record { [[Days]]: days, [[Nanoseconds]]: nanoseconds, [[DayLength]]: abs(dayLengthNs) }.
return NanosecondsToDaysResult { .days = days, .nanoseconds = move(nanoseconds), .day_length = fabs(day_length_ns.to_double()) };
}