Explorar el Código

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.
Linus Groh hace 3 años
padre
commit
f11277b50d
Se han modificado 1 ficheros con 1 adiciones y 1 borrados
  1. 1 1
      Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp

+ 1 - 1
Userland/Libraries/LibJS/Runtime/Temporal/Duration.cpp

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