소스 검색

LibJS: Switch branches in RegulateISODate

This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/2e4a06f
Linus Groh 3 년 전
부모
커밋
a7dfe9096c
1개의 변경된 파일27개의 추가작업 그리고 27개의 파일을 삭제
  1. 27 27
      Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp

+ 27 - 27
Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp

@@ -310,47 +310,47 @@ ThrowCompletionOr<ISODateRecord> regulate_iso_date(GlobalObject& global_object,
 
     VERIFY(year == trunc(year) && month == trunc(month) && day == trunc(day));
 
-    // 1. If overflow is "reject", then
-    if (overflow == "reject"sv) {
-        // IMPLEMENTATION DEFINED: This is an optimization that allows us to treat these doubles as normal integers from this point onwards.
-        // This does not change the exposed behavior as the call to IsValidISODate will immediately check that these values are valid ISO
-        // values (for years: -273975 - 273975, for months: 1 - 12, for days: 1 - 31) all of which are subsets of this check.
-        if (!AK::is_within_range<i32>(year) || !AK::is_within_range<u8>(month) || !AK::is_within_range<u8>(day))
-            return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainDate);
-
-        auto y = static_cast<i32>(year);
-        auto m = static_cast<u8>(month);
-        auto d = static_cast<u8>(day);
-        // a. If IsValidISODate(year, month, day) is false, throw a RangeError exception.
-        if (!is_valid_iso_date(y, m, d))
-            return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainDate);
-
-        // b. Return the Record { [[Year]]: year, [[Month]]: month, [[Day]]: day }.
-        return ISODateRecord { .year = y, .month = m, .day = d };
-    }
-    // 2. Else,
-    else {
-        // a. Assert: overflow is "constrain".
-        VERIFY(overflow == "constrain"sv);
-
+    // 1. If overflow is "constrain", then
+    if (overflow == "constrain"sv) {
         // IMPLEMENTATION DEFINED: This is an optimization that allows us to treat this double as normal integer from this point onwards. This
         // does not change the exposed behavior as the parent's call to CreateTemporalDate will immediately check that this value is a valid
         // ISO value for years: -273975 - 273975, which is a subset of this check.
         if (!AK::is_within_range<i32>(year))
             return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainDate);
 
-        // b. Set month to the result of clamping month between 1 and 12.
+        // a. Set month to the result of clamping month between 1 and 12.
         month = clamp(month, 1, 12);
 
-        // c. Let daysInMonth be ! ISODaysInMonth(year, month).
+        // b. Let daysInMonth be ! ISODaysInMonth(year, month).
         auto days_in_month = iso_days_in_month(static_cast<i32>(year), static_cast<u8>(month));
 
-        // d. Set day to the result of clamping day between 1 and daysInMonth.
+        // c. Set day to the result of clamping day between 1 and daysInMonth.
         day = clamp(day, 1, days_in_month);
 
-        // e. Return CreateISODateRecord(year, month, day).
+        // d. Return CreateISODateRecord(year, month, day).
         return create_iso_date_record(static_cast<i32>(year), static_cast<u8>(month), static_cast<u8>(day));
     }
+    // 2. Else,
+    else {
+        // a. Assert: overflow is "reject".
+        VERIFY(overflow == "reject"sv);
+
+        // IMPLEMENTATION DEFINED: This is an optimization that allows us to treat these doubles as normal integers from this point onwards.
+        // This does not change the exposed behavior as the call to IsValidISODate will immediately check that these values are valid ISO
+        // values (for years: -273975 - 273975, for months: 1 - 12, for days: 1 - 31) all of which are subsets of this check.
+        if (!AK::is_within_range<i32>(year) || !AK::is_within_range<u8>(month) || !AK::is_within_range<u8>(day))
+            return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainDate);
+
+        auto y = static_cast<i32>(year);
+        auto m = static_cast<u8>(month);
+        auto d = static_cast<u8>(day);
+        // b. If IsValidISODate(year, month, day) is false, throw a RangeError exception.
+        if (!is_valid_iso_date(y, m, d))
+            return vm.throw_completion<RangeError>(global_object, ErrorType::TemporalInvalidPlainDate);
+
+        // c. Return the Record { [[Year]]: year, [[Month]]: month, [[Day]]: day }.
+        return ISODateRecord { .year = y, .month = m, .day = d };
+    }
 }
 
 // 3.5.5 IsValidISODate ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-isvalidisodate