LibJS: Capture CalendarFields by reference in Calendar*FromFields AOs
These fields are modified by an invocation to CalendarResolveFields. All callers currently don't care about these modifications, so they move the CalendarFields struct into the AO. But it turns out that at least one AO will care (InterpretTemporalDateTimeFields), thus we will need to take by reference here.
This commit is contained in:
parent
021a5f4ded
commit
521638642f
Notes:
github-actions[bot]
2024-11-23 13:47:20 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/521638642fa Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2513 Reviewed-by: https://github.com/shannonbooth ✅
6 changed files with 15 additions and 15 deletions
|
@ -495,7 +495,7 @@ ThrowCompletionOr<String> get_temporal_calendar_identifier_with_iso_default(VM&
|
|||
}
|
||||
|
||||
// 12.2.10 CalendarDateFromFields ( calendar, fields, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-calendardatefromfields
|
||||
ThrowCompletionOr<ISODate> calendar_date_from_fields(VM& vm, StringView calendar, CalendarFields fields, Overflow overflow)
|
||||
ThrowCompletionOr<ISODate> calendar_date_from_fields(VM& vm, StringView calendar, CalendarFields& fields, Overflow overflow)
|
||||
{
|
||||
// 1. Perform ? CalendarResolveFields(calendar, fields, DATE).
|
||||
TRY(calendar_resolve_fields(vm, calendar, fields, DateType::Date));
|
||||
|
@ -512,7 +512,7 @@ ThrowCompletionOr<ISODate> calendar_date_from_fields(VM& vm, StringView calendar
|
|||
}
|
||||
|
||||
// 12.2.11 CalendarYearMonthFromFields ( calendar, fields, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-calendaryearmonthfromfields
|
||||
ThrowCompletionOr<ISODate> calendar_year_month_from_fields(VM& vm, StringView calendar, CalendarFields fields, Overflow overflow)
|
||||
ThrowCompletionOr<ISODate> calendar_year_month_from_fields(VM& vm, StringView calendar, CalendarFields& fields, Overflow overflow)
|
||||
{
|
||||
// 1. Perform ? CalendarResolveFields(calendar, fields, YEAR-MONTH).
|
||||
TRY(calendar_resolve_fields(vm, calendar, fields, DateType::YearMonth));
|
||||
|
@ -536,7 +536,7 @@ ThrowCompletionOr<ISODate> calendar_year_month_from_fields(VM& vm, StringView ca
|
|||
}
|
||||
|
||||
// 12.2.12 CalendarMonthDayFromFields ( calendar, fields, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmonthdayfromfields
|
||||
ThrowCompletionOr<ISODate> calendar_month_day_from_fields(VM& vm, StringView calendar, CalendarFields fields, Overflow overflow)
|
||||
ThrowCompletionOr<ISODate> calendar_month_day_from_fields(VM& vm, StringView calendar, CalendarFields& fields, Overflow overflow)
|
||||
{
|
||||
// 1. Perform ? CalendarResolveFields(calendar, fields, MONTH-DAY).
|
||||
TRY(calendar_resolve_fields(vm, calendar, fields, DateType::MonthDay));
|
||||
|
|
|
@ -99,9 +99,9 @@ using CalendarFieldListOrPartial = Variant<Partial, CalendarFieldList>;
|
|||
ThrowCompletionOr<String> canonicalize_calendar(VM&, StringView id);
|
||||
Vector<String> const& available_calendars();
|
||||
ThrowCompletionOr<CalendarFields> prepare_calendar_fields(VM&, StringView calendar, Object const& fields, CalendarFieldList calendar_field_names, CalendarFieldList non_calendar_field_names, CalendarFieldListOrPartial required_field_names);
|
||||
ThrowCompletionOr<ISODate> calendar_date_from_fields(VM&, StringView calendar, CalendarFields, Overflow);
|
||||
ThrowCompletionOr<ISODate> calendar_year_month_from_fields(VM&, StringView calendar, CalendarFields, Overflow);
|
||||
ThrowCompletionOr<ISODate> calendar_month_day_from_fields(VM&, StringView calendar, CalendarFields, Overflow);
|
||||
ThrowCompletionOr<ISODate> calendar_date_from_fields(VM&, StringView calendar, CalendarFields&, Overflow);
|
||||
ThrowCompletionOr<ISODate> calendar_year_month_from_fields(VM&, StringView calendar, CalendarFields&, Overflow);
|
||||
ThrowCompletionOr<ISODate> calendar_month_day_from_fields(VM&, StringView calendar, CalendarFields&, Overflow);
|
||||
String format_calendar_annotation(StringView id, ShowCalendar);
|
||||
bool calendar_equals(StringView one, StringView two);
|
||||
u8 iso_days_in_month(double year, double month);
|
||||
|
|
|
@ -106,7 +106,7 @@ ThrowCompletionOr<GC::Ref<PlainDate>> to_temporal_date(VM& vm, Value item, Value
|
|||
auto overflow = TRY(get_temporal_overflow_option(vm, resolved_options));
|
||||
|
||||
// h. Let isoDate be ? CalendarDateFromFields(calendar, fields, overflow).
|
||||
auto iso_date = TRY(calendar_date_from_fields(vm, calendar, move(fields), overflow));
|
||||
auto iso_date = TRY(calendar_date_from_fields(vm, calendar, fields, overflow));
|
||||
|
||||
// i. Return ! CreateTemporalDate(isoDate, calendar).
|
||||
return MUST(create_temporal_date(vm, iso_date, move(calendar)));
|
||||
|
|
|
@ -207,7 +207,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_plain_year_month)
|
|||
auto fields = iso_date_to_fields(calendar, temporal_date->iso_date(), DateType::Date);
|
||||
|
||||
// 5. Let isoDate be ? CalendarYearMonthFromFields(calendar, fields, CONSTRAIN).
|
||||
auto iso_date = TRY(calendar_year_month_from_fields(vm, calendar, move(fields), Overflow::Constrain));
|
||||
auto iso_date = TRY(calendar_year_month_from_fields(vm, calendar, fields, Overflow::Constrain));
|
||||
|
||||
// 6. Return ! CreateTemporalYearMonth(isoDate, calendar).
|
||||
return MUST(create_temporal_year_month(vm, iso_date, calendar));
|
||||
|
@ -227,7 +227,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_plain_month_day)
|
|||
auto fields = iso_date_to_fields(calendar, temporal_date->iso_date(), DateType::Date);
|
||||
|
||||
// 5. Let isoDate be ? CalendarMonthDayFromFields(calendar, fields, CONSTRAIN).
|
||||
auto iso_date = TRY(calendar_month_day_from_fields(vm, calendar, move(fields), Overflow::Constrain));
|
||||
auto iso_date = TRY(calendar_month_day_from_fields(vm, calendar, fields, Overflow::Constrain));
|
||||
|
||||
// 6. Return ! CreateTemporalMonthDay(isoDate, calendar).
|
||||
return MUST(create_temporal_month_day(vm, iso_date, calendar));
|
||||
|
|
|
@ -62,7 +62,7 @@ ThrowCompletionOr<GC::Ref<PlainMonthDay>> to_temporal_month_day(VM& vm, Value it
|
|||
auto overflow = TRY(get_temporal_overflow_option(vm, resolved_options));
|
||||
|
||||
// f. Let isoDate be ? CalendarMonthDayFromFields(calendar, fields, overflow).
|
||||
auto iso_date = TRY(calendar_month_day_from_fields(vm, calendar, move(fields), overflow));
|
||||
auto iso_date = TRY(calendar_month_day_from_fields(vm, calendar, fields, overflow));
|
||||
|
||||
// g. Return ! CreateTemporalMonthDay(isoDate, calendar).
|
||||
return MUST(create_temporal_month_day(vm, iso_date, move(calendar)));
|
||||
|
|
|
@ -64,7 +64,7 @@ ThrowCompletionOr<GC::Ref<PlainYearMonth>> to_temporal_year_month(VM& vm, Value
|
|||
auto overflow = TRY(get_temporal_overflow_option(vm, resolved_options));
|
||||
|
||||
// f. Let isoDate be ? CalendarYearMonthFromFields(calendar, fields, overflow).
|
||||
auto iso_date = TRY(calendar_year_month_from_fields(vm, calendar, move(fields), overflow));
|
||||
auto iso_date = TRY(calendar_year_month_from_fields(vm, calendar, fields, overflow));
|
||||
|
||||
// g. Return ! CreateTemporalYearMonth(isoDate, calendar).
|
||||
return MUST(create_temporal_year_month(vm, iso_date, move(calendar)));
|
||||
|
@ -224,7 +224,7 @@ ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_plain_year_month(VM& vm
|
|||
this_fields.day = 1;
|
||||
|
||||
// 9. Let thisDate be ? CalendarDateFromFields(calendar, thisFields, CONSTRAIN).
|
||||
auto this_date = TRY(calendar_date_from_fields(vm, calendar, move(this_fields), Overflow::Constrain));
|
||||
auto this_date = TRY(calendar_date_from_fields(vm, calendar, this_fields, Overflow::Constrain));
|
||||
|
||||
// 10. Let otherFields be ISODateToFields(calendar, other.[[ISODate]], YEAR-MONTH).
|
||||
auto other_fields = iso_date_to_fields(calendar, other->iso_date(), DateType::YearMonth);
|
||||
|
@ -233,7 +233,7 @@ ThrowCompletionOr<GC::Ref<Duration>> difference_temporal_plain_year_month(VM& vm
|
|||
other_fields.day = 1;
|
||||
|
||||
// 12. Let otherDate be ? CalendarDateFromFields(calendar, otherFields, CONSTRAIN).
|
||||
auto other_date = TRY(calendar_date_from_fields(vm, calendar, move(other_fields), Overflow::Constrain));
|
||||
auto other_date = TRY(calendar_date_from_fields(vm, calendar, other_fields, Overflow::Constrain));
|
||||
|
||||
// 13. Let dateDifference be CalendarDateUntil(calendar, thisDate, otherDate, settings.[[LargestUnit]]).
|
||||
auto date_difference = calendar_date_until(vm, calendar, this_date, other_date, settings.largest_unit);
|
||||
|
@ -299,7 +299,7 @@ ThrowCompletionOr<GC::Ref<PlainYearMonth>> add_duration_to_year_month(VM& vm, Ar
|
|||
fields.day = 1;
|
||||
|
||||
// 9. Let intermediateDate be ? CalendarDateFromFields(calendar, fields, CONSTRAIN).
|
||||
auto intermediate_date = TRY(calendar_date_from_fields(vm, calendar, move(fields), Overflow::Constrain));
|
||||
auto intermediate_date = TRY(calendar_date_from_fields(vm, calendar, fields, Overflow::Constrain));
|
||||
|
||||
ISODate date;
|
||||
|
||||
|
@ -333,7 +333,7 @@ ThrowCompletionOr<GC::Ref<PlainYearMonth>> add_duration_to_year_month(VM& vm, Ar
|
|||
auto added_date_fields = iso_date_to_fields(calendar, added_date, DateType::YearMonth);
|
||||
|
||||
// 15. Let isoDate be ? CalendarYearMonthFromFields(calendar, addedDateFields, overflow).
|
||||
auto iso_date = TRY(calendar_year_month_from_fields(vm, calendar, move(added_date_fields), overflow));
|
||||
auto iso_date = TRY(calendar_year_month_from_fields(vm, calendar, added_date_fields, overflow));
|
||||
|
||||
// 16. Return ! CreateTemporalYearMonth(isoDate, calendar).
|
||||
return MUST(create_temporal_year_month(vm, iso_date, calendar));
|
||||
|
|
Loading…
Add table
Reference in a new issue