mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:47:34 +00:00
LibJS: Require that NanosecondsToDays doesn't flip sign
This is an normative change in the Temporal spec.
See: e13c52d
This commit is contained in:
parent
cfd684dc2f
commit
b1c8029c2b
2 changed files with 21 additions and 1 deletions
|
@ -269,6 +269,10 @@
|
|||
M(TemporalMissingOptionsObject, "Required options object is missing or undefined") \
|
||||
M(TemporalMissingStartingPoint, "A starting point is required for balancing {}") \
|
||||
M(TemporalMissingUnits, "One or both of smallestUnit or largestUnit is required") \
|
||||
M(TemporalNanosecondsConvertedToDaysWithOppositeSign, "Time zone or calendar converted nanoseconds into a number of days with " \
|
||||
"the opposite sign") \
|
||||
M(TemporalNanosecondsConvertedToRemainderOfNanosecondsWithOppositeSign, "Time zone or calendar ended up with a remainder of " \
|
||||
"nanoseconds with the opposite sign") \
|
||||
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") \
|
||||
|
|
|
@ -538,7 +538,23 @@ ThrowCompletionOr<NanosecondsToDaysResult> nanoseconds_to_days(VM& vm, Crypto::S
|
|||
}
|
||||
}
|
||||
|
||||
// 19. Return the Record { [[Days]]: days, [[Nanoseconds]]: nanoseconds, [[DayLength]]: abs(dayLengthNs) }.
|
||||
// 19. If days < 0 and sign = 1, throw a RangeError exception.
|
||||
if (days < 0 && sign == 1)
|
||||
return vm.throw_completion<RangeError>(ErrorType::TemporalNanosecondsConvertedToDaysWithOppositeSign);
|
||||
|
||||
// 20. If days > 0 and sign = -1, throw a RangeError exception.
|
||||
if (days > 0 && sign == -1)
|
||||
return vm.throw_completion<RangeError>(ErrorType::TemporalNanosecondsConvertedToDaysWithOppositeSign);
|
||||
|
||||
// 21. If nanoseconds < 0 and sign = 1, throw a RangeError exception.
|
||||
if (nanoseconds.is_negative() && sign == 1)
|
||||
return vm.throw_completion<RangeError>(ErrorType::TemporalNanosecondsConvertedToRemainderOfNanosecondsWithOppositeSign);
|
||||
|
||||
// 22. If nanoseconds > 0 and sign = -1, throw a RangeError exception.
|
||||
if (nanoseconds.is_positive() && sign == -1)
|
||||
return vm.throw_completion<RangeError>(ErrorType::TemporalNanosecondsConvertedToRemainderOfNanosecondsWithOppositeSign);
|
||||
|
||||
// 23. 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