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

LibJS: Fix missing handling of "week" largest_unit in balance_duration()

It would crash because of VERIFY(largest_unit == "nanosecond"sv) in the
final else branch when passing "week", because it's not handled in any
of the previous branches.
This commit is contained in:
Linus Groh 2021-11-13 14:21:08 +00:00
parent 8c73d85a65
commit f11277b50d

View file

@ -381,7 +381,7 @@ ThrowCompletionOr<BalancedDuration> balance_duration(GlobalObject& global_object
result_nanoseconds = fabs(result_nanoseconds);
// 10. If largestUnit is "year", "month", "week", "day", or "hour", then
if (largest_unit.is_one_of("year"sv, "month"sv, "day"sv, "hour"sv)) {
if (largest_unit.is_one_of("year"sv, "month"sv, "week"sv, "day"sv, "hour"sv)) {
// a. Set microseconds to floor(nanoseconds / 1000).
auto nanoseconds_division_result = total_nanoseconds.divided_by(Crypto::UnsignedBigInteger(1000));
// b. Set nanoseconds to nanoseconds modulo 1000.