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:
parent
b1c8029c2b
commit
5edd4bd512
2 changed files with 9 additions and 1 deletions
|
@ -273,6 +273,8 @@
|
|||
"the opposite sign") \
|
||||
M(TemporalNanosecondsConvertedToRemainderOfNanosecondsWithOppositeSign, "Time zone or calendar ended up with a remainder of " \
|
||||
"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(TemporalObjectMustNotHave, "Object must not have a defined {} property") \
|
||||
M(TemporalPropertyMustBeFinite, "Property must not be Infinity") \
|
||||
|
|
|
@ -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()) };
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue