1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:47:44 +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

@ -273,6 +273,8 @@
"the opposite sign") \ "the opposite sign") \
M(TemporalNanosecondsConvertedToRemainderOfNanosecondsWithOppositeSign, "Time zone or calendar ended up with a remainder of " \ M(TemporalNanosecondsConvertedToRemainderOfNanosecondsWithOppositeSign, "Time zone or calendar ended up with a remainder of " \
"nanoseconds with the opposite sign") \ "nanoseconds with the opposite sign") \
M(TemporalNanosecondsConvertedToRemainderOfNanosecondsLongerThanDayLength, "Time zone or calendar ended up with a remainder of " \
"nanoseconds longer than the day length") \
M(TemporalObjectMustHaveOneOf, "Object must have at least one of the following properties: {}") \ M(TemporalObjectMustHaveOneOf, "Object must have at least one of the following properties: {}") \
M(TemporalObjectMustNotHave, "Object must not have a defined {} property") \ M(TemporalObjectMustNotHave, "Object must not have a defined {} property") \
M(TemporalPropertyMustBeFinite, "Property must not be Infinity") \ M(TemporalPropertyMustBeFinite, "Property must not be Infinity") \

View file

@ -554,7 +554,13 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(VM& vm, Crypto::S
if (nanoseconds.is_positive() && sign == -1) if (nanoseconds.is_positive() && sign == -1)
return vm.throw_completion<RangeError>(ErrorType::TemporalNanosecondsConvertedToRemainderOfNanosecondsWithOppositeSign); 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()) }; return NanosecondsToDaysResult { .days = days, .nanoseconds = move(nanoseconds), .day_length = fabs(day_length_ns.to_double()) };
} }