summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-06-14 23:50:24 +0100
committerLinus Groh <mail@linusgroh.de>2022-06-15 17:49:20 +0100
commita7dfe9096c09f22b73374eafc463f1f371f78f7f (patch)
tree9fd53b4c678196eaf99b07fc8c7058d6b9bba9b3
parent07041498f833b4093e62e46a2bb6cbe47ecf8e4e (diff)
downloadserenity-a7dfe9096c09f22b73374eafc463f1f371f78f7f.zip
LibJS: Switch branches in RegulateISODate
This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/2e4a06f
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp54
1 files changed, 27 insertions, 27 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp
index 4ce2f1cf85..5ef61b0bb0 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainDate.cpp
+++ b/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