diff options
author | Moustafa Raafat <MoustafaRaafat2@gmail.com> | 2022-10-16 13:36:59 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-19 22:39:33 +0200 |
commit | 69d5368b2a540f15361bc0ac3775f970bf867586 (patch) | |
tree | 316b2b319b398ba38abcf091cf078c11e487f3e0 /Userland/Libraries/LibJS/Runtime/Temporal | |
parent | 48cc557dfa9c72a4ee4588ba698c6b7dd9ddfa57 (diff) | |
download | serenity-69d5368b2a540f15361bc0ac3775f970bf867586.zip |
LibJS: Remove trivial operation IsValidISOMonth
This is an editorial change in the Temporal spec.
See: https://github.com/tc39/proposal-temporal/commit/a08330a
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Temporal')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp | 30 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.h | 1 |
2 files changed, 8 insertions, 23 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp index c744de030e..fd885815cc 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.cpp @@ -116,8 +116,8 @@ ThrowCompletionOr<ISOYearMonth> regulate_iso_year_month(VM& vm, double year, dou if (!AK::is_within_range<i32>(year) || !AK::is_within_range<u8>(month)) return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidPlainYearMonth); - // b. If ! IsValidISOMonth(month) is false, throw a RangeError exception. - if (!is_valid_iso_month(month)) + // b. If month < 1 or month > 12, throw a RangeError exception. + if (month < 1 || month > 12) return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidPlainYearMonth); // c. Return the Record { [[Year]]: year, [[Month]]: month }. @@ -125,21 +125,7 @@ ThrowCompletionOr<ISOYearMonth> regulate_iso_year_month(VM& vm, double year, dou } } -// 9.5.3 IsValidISOMonth ( month ), https://tc39.es/proposal-temporal/#sec-temporal-isvalidisomonth -bool is_valid_iso_month(u8 month) -{ - // 1. Assert: month is an integer. - // 2. If month < 1 or month > 12, then - if (month < 1 || month > 12) { - // a.Return false. - return false; - } - - // 3. Return true. - return true; -} - -// 9.5.4 ISOYearMonthWithinLimits ( year, month ), https://tc39.es/proposal-temporal/#sec-temporal-isoyearmonthwithinlimits +// 9.5.3 ISOYearMonthWithinLimits ( year, month ), https://tc39.es/proposal-temporal/#sec-temporal-isoyearmonthwithinlimits bool iso_year_month_within_limits(i32 year, u8 month) { // 1. Assert: year and month are integers. @@ -166,7 +152,7 @@ bool iso_year_month_within_limits(i32 year, u8 month) return true; } -// 9.5.5 BalanceISOYearMonth ( year, month ), https://tc39.es/proposal-temporal/#sec-temporal-balanceisoyearmonth +// 9.5.4 BalanceISOYearMonth ( year, month ), https://tc39.es/proposal-temporal/#sec-temporal-balanceisoyearmonth ISOYearMonth balance_iso_year_month(double year, double month) { // 1. Assert: year and month are integers. @@ -182,7 +168,7 @@ ISOYearMonth balance_iso_year_month(double year, double month) return ISOYearMonth { .year = static_cast<i32>(year), .month = static_cast<u8>(month), .reference_iso_day = 0 }; } -// 9.5.6 CreateTemporalYearMonth ( isoYear, isoMonth, calendar, referenceISODay [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalyearmonth +// 9.5.5 CreateTemporalYearMonth ( isoYear, isoMonth, calendar, referenceISODay [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalyearmonth ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(VM& vm, i32 iso_year, u8 iso_month, Object& calendar, u8 reference_iso_day, FunctionObject const* new_target) { auto& realm = *vm.current_realm(); @@ -213,7 +199,7 @@ ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(VM& vm, i32 iso_ye return object; } -// 9.5.7 TemporalYearMonthToString ( yearMonth, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporalyearmonthtostring +// 9.5.6 TemporalYearMonthToString ( yearMonth, showCalendar ), https://tc39.es/proposal-temporal/#sec-temporal-temporalyearmonthtostring ThrowCompletionOr<String> temporal_year_month_to_string(VM& vm, PlainYearMonth& year_month, StringView show_calendar) { // 1. Assert: Type(yearMonth) is Object. @@ -242,7 +228,7 @@ ThrowCompletionOr<String> temporal_year_month_to_string(VM& vm, PlainYearMonth& return String::formatted("{}{}", result, calendar_string); } -// 9.5.8 DifferenceTemporalPlainYearMonth ( operation, yearMonth, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalplainyearmonth +// 9.5.7 DifferenceTemporalPlainYearMonth ( operation, yearMonth, other, options ), https://tc39.es/proposal-temporal/#sec-temporal-differencetemporalplainyearmonth ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(VM& vm, DifferenceOperation operation, PlainYearMonth& year_month, Value other_value, Value options_value) { // 1. If operation is since, let sign be -1. Otherwise, let sign be 1. @@ -300,7 +286,7 @@ ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(VM& vm, Differ return MUST(create_temporal_duration(vm, sign * result.years, sign * result.months, 0, 0, 0, 0, 0, 0, 0, 0)); } -// 9.5.9 AddDurationToOrSubtractDurationFromPlainYearMonth ( operation, yearMonth, temporalDurationLike, options ), https://tc39.es/proposal-temporal/#sec-temporal-addtemporalplainyearmonth +// 9.5.8 AddDurationToOrSubtractDurationFromPlainYearMonth ( operation, yearMonth, temporalDurationLike, options ), https://tc39.es/proposal-temporal/#sec-temporal-addtemporalplainyearmonth ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_plain_year_month(VM& vm, ArithmeticOperation operation, PlainYearMonth& year_month, Value temporal_duration_like, Value options_value) { auto& realm = *vm.current_realm(); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.h b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.h index b6b7ae4a08..f1744e209e 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/PlainYearMonth.h @@ -43,7 +43,6 @@ struct ISOYearMonth { ThrowCompletionOr<PlainYearMonth*> to_temporal_year_month(VM&, Value item, Object const* options = nullptr); ThrowCompletionOr<ISOYearMonth> regulate_iso_year_month(VM&, double year, double month, StringView overflow); -bool is_valid_iso_month(u8 month); bool iso_year_month_within_limits(i32 year, u8 month); ISOYearMonth balance_iso_year_month(double year, double month); ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(VM&, i32 iso_year, u8 iso_month, Object& calendar, u8 reference_iso_day, FunctionObject const* new_target = nullptr); |