diff options
3 files changed, 14 insertions, 30 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp index f69417f060..15dc374185 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp @@ -741,8 +741,8 @@ u8 to_iso_week_of_year(i32 year, u8 month, u8 day) return week; } -// 12.2.32 BuildISOMonthCode ( month ), https://tc39.es/proposal-temporal/#sec-buildisomonthcode -String build_iso_month_code(u8 month) +// 12.2.32 ISOMonthCode ( month ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthcode +String iso_month_code(u8 month) { // 1. Let numberPart be ToZeroPaddedDecimalString(month, 2). // 2. Return the string-concatenation of "M" and numberPart. @@ -797,8 +797,8 @@ ThrowCompletionOr<double> resolve_iso_month(VM& vm, Object const& fields) // 11. Let monthCodeNumber be ! ToIntegerOrInfinity(monthCodeDigits). auto month_code_number = MUST(Value(js_string(vm, move(month_code_digits))).to_integer_or_infinity(vm)); - // 12. Assert: SameValue(monthCode, BuildISOMonthCode(monthCodeNumber)) is true. - VERIFY(month_code_string == build_iso_month_code(month_code_number)); + // 12. Assert: SameValue(monthCode, ISOMonthCode(monthCodeNumber)) is true. + VERIFY(month_code_string == iso_month_code(month_code_number)); // 13. If month is not undefined and SameValue(month, monthCodeNumber) is false, throw a RangeError exception. if (!month.is_undefined() && month.as_double() != month_code_number) @@ -959,25 +959,7 @@ u8 iso_month(Object& temporal_object) VERIFY_NOT_REACHED(); } -// 12.2.39 ISOMonthCode ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthcode -String iso_month_code(Object& temporal_object) -{ - // 1. Assert: temporalObject has an [[ISOMonth]] internal slot. - // NOTE: Asserted by the VERIFY_NOT_REACHED at the end - - // 2. Return ! BuildISOMonthCode(temporalObject.[[ISOMonth]]). - if (is<PlainDate>(temporal_object)) - return build_iso_month_code(static_cast<PlainDate&>(temporal_object).iso_month()); - if (is<PlainDateTime>(temporal_object)) - return build_iso_month_code(static_cast<PlainDateTime&>(temporal_object).iso_month()); - if (is<PlainYearMonth>(temporal_object)) - return build_iso_month_code(static_cast<PlainYearMonth&>(temporal_object).iso_month()); - if (is<PlainMonthDay>(temporal_object)) - return build_iso_month_code(static_cast<PlainMonthDay&>(temporal_object).iso_month()); - VERIFY_NOT_REACHED(); -} - -// 12.2.40 ISODay ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthcode +// 12.2.39 ISODay ( temporalObject ), https://tc39.es/proposal-temporal/#sec-temporal-isomonthcode u8 iso_day(Object& temporal_object) { // 1. Assert: temporalObject has an [[ISODay]] internal slot. @@ -995,7 +977,7 @@ u8 iso_day(Object& temporal_object) VERIFY_NOT_REACHED(); } -// 12.2.41 DefaultMergeCalendarFields ( fields, additionalFields ), https://tc39.es/proposal-temporal/#sec-temporal-defaultmergecalendarfields +// 12.2.40 DefaultMergeCalendarFields ( fields, additionalFields ), https://tc39.es/proposal-temporal/#sec-temporal-defaultmergecalendarfields ThrowCompletionOr<Object*> default_merge_calendar_fields(VM& vm, Object const& fields, Object const& additional_fields) { auto& realm = *vm.current_realm(); @@ -1071,7 +1053,7 @@ ThrowCompletionOr<Object*> default_merge_calendar_fields(VM& vm, Object const& f return merged; } -// 12.2.42 ToISODayOfYear ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisodayofyear +// 12.2.41 ToISODayOfYear ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisodayofyear u16 to_iso_day_of_year(i32 year, u8 month, u8 day) { // 1. Assert: IsValidISODate(year, month, day) is true. @@ -1087,7 +1069,7 @@ u16 to_iso_day_of_year(i32 year, u8 month, u8 day) return day_within_year(make_date(epoch_days, 0)) + 1; } -// 12.2.43 ToISODayOfWeek ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisodayofweek +// 12.2.42 ToISODayOfWeek ( year, month, day ), https://tc39.es/proposal-temporal/#sec-temporal-toisodayofweek u8 to_iso_day_of_week(i32 year, u8 month, u8 day) { // 1. Assert: IsValidISODate(year, month, day) is true. diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h index 69f158e8e4..d006a8b20c 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h @@ -66,14 +66,13 @@ ThrowCompletionOr<bool> calendar_equals(VM&, Object& one, Object& two); ThrowCompletionOr<Object*> consolidate_calendars(VM&, Object& one, Object& two); u8 iso_days_in_month(i32 year, u8 month); u8 to_iso_week_of_year(i32 year, u8 month, u8 day); -String build_iso_month_code(u8 month); +String iso_month_code(u8 month); ThrowCompletionOr<double> resolve_iso_month(VM&, Object const& fields); ThrowCompletionOr<ISODateRecord> iso_date_from_fields(VM&, Object const& fields, Object const& options); ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(VM&, Object const& fields, Object const& options); ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(VM&, Object const& fields, Object const& options); i32 iso_year(Object& temporal_object); u8 iso_month(Object& temporal_object); -String iso_month_code(Object& temporal_object); u8 iso_day(Object& temporal_object); ThrowCompletionOr<Object*> default_merge_calendar_fields(VM&, Object const& fields, Object const& additional_fields); u16 to_iso_day_of_year(i32 year, u8 month, u8 day); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp index 422bb7e3b6..b90a1d3dce 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp @@ -287,8 +287,11 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::month_code) temporal_date_like = TRY(to_temporal_date(vm, temporal_date_like)); } - // 5. Return ! ISOMonthCode(temporalDateLike). - return js_string(vm, iso_month_code(temporal_date_like.as_object())); + // 5. Assert: temporalDateLike has an [[ISOMonth]] internal slot. + // NOTE: The assertion happens in iso_month() call. + + // 6. Return ISOMonthCode(temporalDateLike.[[ISOMonth]]). + return js_string(vm, iso_month_code(iso_month(temporal_date_like.as_object()))); } // 12.4.12 Temporal.Calendar.prototype.day ( temporalDateLike ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.day |