1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 16:57:46 +00:00

LibJS: Fold PreparePartialTemporalFields into PrepareTemporalFields

This is an editorial change in the Temporal spec.

See: 6ed1835
This commit is contained in:
Linus Groh 2022-06-14 20:22:52 +01:00
parent 631f270ac1
commit 3e6561c75f
13 changed files with 69 additions and 99 deletions

View file

@ -628,7 +628,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(GlobalObject& global_object
auto field_names = TRY(calendar_fields(global_object, *calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
// e. Let fields be ? PrepareTemporalFields(value, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, value_object, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, value_object, field_names, Vector<StringView> {}));
// f. Let dateOptions be OrdinaryObjectCreate(null).
auto* date_options = Object::create(global_object, nullptr);
@ -1764,7 +1764,7 @@ ThrowCompletionOr<double> to_positive_integer(GlobalObject& global_object, Value
}
// 13.43 PrepareTemporalFields ( fields, fieldNames, requiredFields ), https://tc39.es/proposal-temporal/#sec-temporal-preparetemporalfields
ThrowCompletionOr<Object*> prepare_temporal_fields(GlobalObject& global_object, Object const& fields, Vector<String> const& field_names, Vector<StringView> const& required_fields)
ThrowCompletionOr<Object*> prepare_temporal_fields(GlobalObject& global_object, Object const& fields, Vector<String> const& field_names, Variant<PrepareTemporalFieldsPartial, Vector<StringView>> const& required_fields)
{
auto& vm = global_object.vm();
@ -1772,54 +1772,6 @@ ThrowCompletionOr<Object*> prepare_temporal_fields(GlobalObject& global_object,
auto* result = Object::create(global_object, global_object.object_prototype());
VERIFY(result);
// 2. For each value property of fieldNames, do
for (auto& property : field_names) {
// a. Let value be ? Get(fields, property).
auto value = TRY(fields.get(property));
// b. If value is undefined, then
if (value.is_undefined()) {
// i. If requiredFields contains property, then
if (required_fields.contains_slow(property)) {
// 1. Throw a TypeError exception.
return vm.throw_completion<TypeError>(global_object, ErrorType::MissingRequiredProperty, property);
}
// ii. If property is in the Property column of Table 13, then
// NOTE: The other properties in the table are automatically handled as their default value is undefined
if (property.is_one_of("hour"sv, "minute"sv, "second"sv, "millisecond"sv, "microsecond"sv, "nanosecond"sv)) {
// 1. Set value to the corresponding Default value of the same row.
value = Value(0);
}
}
// c. Else,
else {
// i. If property is in the Property column of Table 13 and there is a Conversion value in the same row, then
// 1. Let Conversion represent the abstract operation named by the Conversion value of the same row.
// 2. Set value to ? Conversion(value).
if (property.is_one_of("year"sv, "hour"sv, "minute"sv, "second"sv, "millisecond"sv, "microsecond"sv, "nanosecond"sv, "eraYear"sv))
value = Value(TRY(to_integer_throw_on_infinity(global_object, value, ErrorType::TemporalPropertyMustBeFinite)));
else if (property.is_one_of("month"sv, "day"sv))
value = Value(TRY(to_positive_integer(global_object, value)));
else if (property.is_one_of("monthCode"sv, "offset"sv, "era"sv))
value = TRY(value.to_primitive_string(global_object));
}
// d. Perform ! CreateDataPropertyOrThrow(result, property, value).
MUST(result->create_data_property_or_throw(property, value));
}
// 3. Return result.
return result;
}
// 13.44 PreparePartialTemporalFields ( fields, fieldNames ), https://tc39.es/proposal-temporal/#sec-temporal-preparepartialtemporalfields
ThrowCompletionOr<Object*> prepare_partial_temporal_fields(GlobalObject& global_object, Object const& fields, Vector<String> const& field_names)
{
auto& vm = global_object.vm();
// 1. Let result be OrdinaryObjectCreate(%Object.prototype%).
auto* result = Object::create(global_object, global_object.object_prototype());
// 2. Let any be false.
auto any = false;
@ -1833,7 +1785,7 @@ ThrowCompletionOr<Object*> prepare_partial_temporal_fields(GlobalObject& global_
// i. Set any to true.
any = true;
// ii. If property is in the Property column of Table 13, then
// ii. If property is in the Property column of Table 15 and there is a Conversion value in the same row, then
// 1. Let Conversion represent the abstract operation named by the Conversion value of the same row.
// 2. Set value to ? Conversion(value).
if (property.is_one_of("year"sv, "hour"sv, "minute"sv, "second"sv, "millisecond"sv, "microsecond"sv, "nanosecond"sv, "eraYear"sv))
@ -1843,13 +1795,30 @@ ThrowCompletionOr<Object*> prepare_partial_temporal_fields(GlobalObject& global_
else if (property.is_one_of("monthCode"sv, "offset"sv, "era"sv))
value = TRY(value.to_primitive_string(global_object));
// iii. Perform ! CreateDataPropertyOrThrow(result, property, value).
MUST(result->create_data_property_or_throw(property, value));
}
// c. Else if requiredFields is a List, then
else if (required_fields.has<Vector<StringView>>()) {
// i. If requiredFields contains property, then
if (required_fields.get<Vector<StringView>>().contains_slow(property)) {
// 1. Throw a TypeError exception.
return vm.throw_completion<TypeError>(global_object, ErrorType::MissingRequiredProperty, property);
}
// ii. If property is in the Property column of Table 13, then
// NOTE: The other properties in the table are automatically handled as their default value is undefined
if (property.is_one_of("hour"sv, "minute"sv, "second"sv, "millisecond"sv, "microsecond"sv, "nanosecond"sv)) {
// 1. Set value to the corresponding Default value of the same row.
value = Value(0);
}
// iii. Perform ! CreateDataPropertyOrThrow(result, property, value).
MUST(result->create_data_property_or_throw(property, value));
}
}
// 4. If any is false, then
if (!any) {
// 4. If requiredFields is partial and any is false, then
if (required_fields.has<PrepareTemporalFieldsPartial>() && !any) {
// a. Throw a TypeError exception.
return vm.throw_completion<TypeError>(global_object, ErrorType::TemporalObjectMustHaveOneOf, String::join(", "sv, field_names));
}
@ -1857,4 +1826,5 @@ ThrowCompletionOr<Object*> prepare_partial_temporal_fields(GlobalObject& global_
// 5. Return result.
return result;
}
}

View file

@ -122,6 +122,7 @@ struct SecondsStringPrecision {
};
struct TemporalUnitRequired { };
struct PrepareTemporalFieldsPartial { };
ThrowCompletionOr<MarkedVector<Value>> iterable_to_list_of_type(GlobalObject&, Value items, Vector<OptionType> const& element_types);
ThrowCompletionOr<Object*> get_options_object(GlobalObject&, Value options);
@ -166,8 +167,7 @@ ThrowCompletionOr<TemporalTime> parse_temporal_time_string(GlobalObject&, String
ThrowCompletionOr<TemporalTimeZone> parse_temporal_time_zone_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<TemporalYearMonth> parse_temporal_year_month_string(GlobalObject&, String const& iso_string);
ThrowCompletionOr<double> to_positive_integer(GlobalObject&, Value argument);
ThrowCompletionOr<Object*> prepare_temporal_fields(GlobalObject&, Object const& fields, Vector<String> const& field_names, Vector<StringView> const& required_fields);
ThrowCompletionOr<Object*> prepare_partial_temporal_fields(GlobalObject&, Object const& fields, Vector<String> const& field_names);
ThrowCompletionOr<Object*> prepare_temporal_fields(GlobalObject&, Object const& fields, Vector<String> const& field_names, Variant<PrepareTemporalFieldsPartial, Vector<StringView>> const& required_fields);
// 13.41 ToIntegerThrowOnInfinity ( argument ), https://tc39.es/proposal-temporal/#sec-temporal-tointegerthrowoninfinity
template<typename... Args>

View file

@ -734,7 +734,7 @@ ThrowCompletionOr<ISODateRecord> iso_date_from_fields(GlobalObject& global_objec
auto overflow = TRY(to_temporal_overflow(global_object, &options));
// 3. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », «»).
auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "day", "month", "monthCode", "year" }, {}));
auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "day", "month", "monthCode", "year" }, Vector<StringView> {}));
// 4. Let year be ! Get(fields, "year").
auto year = MUST(prepared_fields->get(vm.names.year));
@ -774,7 +774,7 @@ ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(GlobalObject& global_
auto overflow = TRY(to_temporal_overflow(global_object, &options));
// 3. Set fields to ? PrepareTemporalFields(fields, « "month", "monthCode", "year" », « "year" »).
auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "month"sv, "monthCode"sv, "year"sv }, { "year"sv }));
auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "month"sv, "monthCode"sv, "year"sv }, Vector<StringView> { "year"sv }));
// 4. Let year be ! Get(fields, "year").
auto year = MUST(prepared_fields->get(vm.names.year));
@ -803,7 +803,7 @@ ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(GlobalObject& global_ob
auto overflow = TRY(to_temporal_overflow(global_object, &options));
// 3. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », «»).
auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "day"sv, "month"sv, "monthCode"sv, "year"sv }, {}));
auto* prepared_fields = TRY(prepare_temporal_fields(global_object, fields, { "day"sv, "month"sv, "monthCode"sv, "year"sv }, Vector<StringView> {}));
// 4. Let month be ! Get(fields, "month").
auto month_value = MUST(prepared_fields->get(vm.names.month));

View file

@ -124,7 +124,7 @@ ThrowCompletionOr<PlainDate*> to_temporal_date(GlobalObject& global_object, Valu
auto field_names = TRY(calendar_fields(global_object, *calendar, { "day"sv, "month"sv, "monthCode"sv, "year"sv }));
// f. Let fields be ? PrepareTemporalFields(item, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, Vector<StringView> {}));
// g. Return ? CalendarDateFromFields(calendar, fields, options).
return calendar_date_from_fields(global_object, *calendar, *fields, options);

View file

@ -290,7 +290,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_plain_year_month)
auto field_names = TRY(calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv }));
// 5. Let fields be ? PrepareTemporalFields(temporalDate, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date, field_names, Vector<StringView> {}));
// 6. Return ? CalendarYearMonthFromFields(calendar, fields).
return TRY(calendar_year_month_from_fields(global_object, calendar, *fields));
@ -310,7 +310,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::to_plain_month_day)
auto field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "monthCode"sv }));
// 5. Let fields be ? PrepareTemporalFields(temporalDate, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date, field_names, Vector<StringView> {}));
// 6. Return ? CalendarMonthDayFromFields(calendar, fields).
return TRY(calendar_month_day_from_fields(global_object, calendar, *fields));
@ -403,20 +403,20 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::with)
// 6. Let fieldNames be ? CalendarFields(calendar, « "day", "month", "monthCode", "year" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "month"sv, "monthCode"sv, "year"sv }));
// 7. Let partialDate be ? PreparePartialTemporalFields(temporalDateLike, fieldNames).
auto* partial_date = TRY(prepare_partial_temporal_fields(global_object, temporal_date_like.as_object(), field_names));
// 7. Let partialDate be ? PrepareTemporalFields(temporalDateLike, fieldNames, partial).
auto* partial_date = TRY(prepare_temporal_fields(global_object, temporal_date_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
// 8. Set options to ? GetOptionsObject(options).
auto const* options = TRY(get_options_object(global_object, vm.argument(1)));
// 9. Let fields be ? PrepareTemporalFields(temporalDate, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date, field_names, Vector<StringView> {}));
// 10. Set fields to ? CalendarMergeFields(calendar, fields, partialDate).
fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *partial_date));
// 11. Set fields to ? PrepareTemporalFields(fields, fieldNames, «»).
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, {}));
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, Vector<StringView> {}));
// 12. Return ? CalendarDateFromFields(calendar, fields, options).
return TRY(calendar_date_from_fields(global_object, calendar, *fields, options));

View file

@ -170,7 +170,7 @@ ThrowCompletionOr<PlainDateTime*> to_temporal_date_time(GlobalObject& global_obj
auto field_names = TRY(calendar_fields(global_object, *calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
// f. Let fields be ? PrepareTemporalFields(item, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, Vector<StringView> {}));
// g. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, options).
result = TRY(interpret_temporal_date_time_fields(global_object, *calendar, *fields, *options));

View file

@ -377,20 +377,20 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::with)
// 6. Let fieldNames be ? CalendarFields(calendar, « "day", "hour", "microsecond", "millisecond", "minute", "month", "monthCode", "nanosecond", "second", "year" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
// 7. Let partialDateTime be ? PreparePartialTemporalFields(temporalDateTimeLike, fieldNames).
auto* partial_date_time = TRY(prepare_partial_temporal_fields(global_object, temporal_date_time_like.as_object(), field_names));
// 7. Let partialDateTime be ? PrepareTemporalFields(temporalDateTimeLike, fieldNames, partial).
auto* partial_date_time = TRY(prepare_temporal_fields(global_object, temporal_date_time_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
// 8. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
// 9. Let fields be ? PrepareTemporalFields(dateTime, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *date_time, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, *date_time, field_names, Vector<StringView> {}));
// 10. Set fields to ? CalendarMergeFields(calendar, fields, partialDateTime).
fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *partial_date_time));
// 11. Set fields to ? PrepareTemporalFields(fields, fieldNames, «»).
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, {}));
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, Vector<StringView> {}));
// 12. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, options).
auto result = TRY(interpret_temporal_date_time_fields(global_object, calendar, *fields, *options));
@ -686,7 +686,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_plain_year_month)
auto field_names = TRY(calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv }));
// 5. Let fields be ? PrepareTemporalFields(dateTime, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *date_time, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, *date_time, field_names, Vector<StringView> {}));
// 6. Return ? CalendarYearMonthFromFields(calendar, fields).
return TRY(calendar_year_month_from_fields(global_object, calendar, *fields));
@ -706,7 +706,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::to_plain_month_day)
auto field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "monthCode"sv }));
// 5. Let fields be ? PrepareTemporalFields(dateTime, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *date_time, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, *date_time, field_names, Vector<StringView> {}));
// 6. Return ? CalendarMonthDayFromFields(calendar, fields).
return TRY(calendar_month_day_from_fields(global_object, calendar, *fields));

View file

@ -96,7 +96,7 @@ ThrowCompletionOr<PlainMonthDay*> to_temporal_month_day(GlobalObject& global_obj
auto field_names = TRY(calendar_fields(global_object, *calendar, { "day"sv, "month"sv, "monthCode"sv, "year"sv }));
// e. Let fields be ? PrepareTemporalFields(item, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, Vector<StringView> {}));
// f. Let month be ? Get(fields, "month").
auto month = TRY(fields->get(vm.names.month));

View file

@ -106,20 +106,20 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::with)
// 6. Let fieldNames be ? CalendarFields(calendar, « "day", "month", "monthCode", "year" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "month"sv, "monthCode"sv, "year"sv }));
// 7. Let partialMonthDay be ? PreparePartialTemporalFields(temporalMonthDayLike, fieldNames).
auto* partial_month_day = TRY(prepare_partial_temporal_fields(global_object, temporal_month_day_like.as_object(), field_names));
// 7. Let partialMonthDay be ? PrepareTemporalFields(temporalMonthDayLike, fieldNames, partial).
auto* partial_month_day = TRY(prepare_temporal_fields(global_object, temporal_month_day_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
// 8. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
// 9. Let fields be ? PrepareTemporalFields(monthDay, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *month_day, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, *month_day, field_names, Vector<StringView> {}));
// 10. Set fields to ? CalendarMergeFields(calendar, fields, partialMonthDay).
fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *partial_month_day));
// 11. Set fields to ? PrepareTemporalFields(fields, fieldNames, «»).
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, {}));
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, Vector<StringView> {}));
// 12. Return ? CalendarMonthDayFromFields(calendar, fields, options).
return TRY(calendar_month_day_from_fields(global_object, calendar, *fields, options));
@ -220,13 +220,13 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_plain_date)
auto receiver_field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "monthCode"sv }));
// 6. Let fields be ? PrepareTemporalFields(monthDay, receiverFieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *month_day, receiver_field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, *month_day, receiver_field_names, Vector<StringView> {}));
// 7. Let inputFieldNames be ? CalendarFields(calendar, « "year" »).
auto input_field_names = TRY(calendar_fields(global_object, calendar, { "year"sv }));
// 8. Let inputFields be ? PrepareTemporalFields(item, inputFieldNames, «»).
auto* input_fields = TRY(prepare_temporal_fields(global_object, item.as_object(), input_field_names, {}));
auto* input_fields = TRY(prepare_temporal_fields(global_object, item.as_object(), input_field_names, Vector<StringView> {}));
// 9. Let mergedFields be ? CalendarMergeFields(calendar, fields, inputFields).
auto* merged_fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *input_fields));
@ -243,7 +243,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_plain_date)
}
// 11. Set mergedFields to ? PrepareTemporalFields(mergedFields, mergedFieldNames, «»).
merged_fields = TRY(prepare_temporal_fields(global_object, *merged_fields, merged_field_names, {}));
merged_fields = TRY(prepare_temporal_fields(global_object, *merged_fields, merged_field_names, Vector<StringView> {}));
// 12. Let options be OrdinaryObjectCreate(null).
auto* options = Object::create(global_object, nullptr);

View file

@ -57,7 +57,7 @@ ThrowCompletionOr<PlainYearMonth*> to_temporal_year_month(GlobalObject& global_o
auto field_names = TRY(calendar_fields(global_object, *calendar, { "month"sv, "monthCode"sv, "year"sv }));
// d. Let fields be ? PrepareTemporalFields(item, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, Vector<StringView> {}));
// e. Return ? CalendarYearMonthFromFields(calendar, fields, options).
return calendar_year_month_from_fields(global_object, *calendar, *fields, options);
@ -316,7 +316,7 @@ ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(GlobalObject&
auto field_names = TRY(calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv }));
// 16. Let otherFields be ? PrepareTemporalFields(other, fieldNames, «»).
auto* other_fields = TRY(prepare_temporal_fields(global_object, *other, field_names, {}));
auto* other_fields = TRY(prepare_temporal_fields(global_object, *other, field_names, Vector<StringView> {}));
// 17. Perform ! CreateDataPropertyOrThrow(otherFields, "day", 1𝔽).
MUST(other_fields->create_data_property_or_throw(vm.names.day, Value(1)));
@ -325,7 +325,7 @@ ThrowCompletionOr<Duration*> difference_temporal_plain_year_month(GlobalObject&
auto* other_date = TRY(calendar_date_from_fields(global_object, calendar, *other_fields));
// 19. Let thisFields be ? PrepareTemporalFields(yearMonth, fieldNames, «»).
auto* this_fields = TRY(prepare_temporal_fields(global_object, year_month, field_names, {}));
auto* this_fields = TRY(prepare_temporal_fields(global_object, year_month, field_names, Vector<StringView> {}));
// 20. Perform ! CreateDataPropertyOrThrow(thisFields, "day", 1𝔽).
MUST(this_fields->create_data_property_or_throw(vm.names.day, Value(1)));
@ -384,7 +384,7 @@ ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_pla
auto field_names = TRY(calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv }));
// 7. Let fields be ? PrepareTemporalFields(yearMonth, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, year_month, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, year_month, field_names, Vector<StringView> {}));
// 8. Set sign to ! DurationSign(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], balanceResult.[[Days]], 0, 0, 0, 0, 0, 0).
auto sign = duration_sign(duration.years, duration.months, duration.weeks, balance_result.days, 0, 0, 0, 0, 0, 0);
@ -433,7 +433,7 @@ ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_pla
auto* added_date = TRY(calendar_date_add(global_object, calendar, date, *duration_to_add, options));
// 18. Let addedDateFields be ? PrepareTemporalFields(addedDate, fieldNames, «»).
auto* added_date_fields = TRY(prepare_temporal_fields(global_object, *added_date, field_names, {}));
auto* added_date_fields = TRY(prepare_temporal_fields(global_object, *added_date, field_names, Vector<StringView> {}));
// 19. Return ? CalendarYearMonthFromFields(calendar, addedDateFields, optionsCopy).
return calendar_year_month_from_fields(global_object, calendar, *added_date_fields, options_copy);

View file

@ -217,20 +217,20 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::with)
// 6. Let fieldNames be ? CalendarFields(calendar, « "month", "monthCode", "year" »).
auto field_names = TRY(calendar_fields(global_object, calendar, { "month"sv, "monthCode"sv, "year"sv }));
// 7. Let partialYearMonth be ? PreparePartialTemporalFields(temporalYearMonthLike, fieldNames).
auto* partial_year_month = TRY(prepare_partial_temporal_fields(global_object, temporal_year_month_like.as_object(), field_names));
// 7. Let partialYearMonth be ? PrepareTemporalFields(temporalYearMonthLike, fieldNames, partial).
auto* partial_year_month = TRY(prepare_temporal_fields(global_object, temporal_year_month_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
// 8. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
// 9. Let fields be ? PrepareTemporalFields(yearMonth, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *year_month, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, *year_month, field_names, Vector<StringView> {}));
// 10. Set fields to ? CalendarMergeFields(calendar, fields, partialYearMonth).
fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *partial_year_month));
// 11. Set fields to ? PrepareTemporalFields(fields, fieldNames, «»).
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, {}));
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, Vector<StringView> {}));
// 12. Return ? CalendarYearMonthFromFields(calendar, fields, options).
return TRY(calendar_year_month_from_fields(global_object, calendar, *fields, options));
@ -387,13 +387,13 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date)
auto receiver_field_names = TRY(calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv }));
// 6. Let fields be ? PrepareTemporalFields(yearMonth, receiverFieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *year_month, receiver_field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, *year_month, receiver_field_names, Vector<StringView> {}));
// 7. Let inputFieldNames be ? CalendarFields(calendar, « "day" »).
auto input_field_names = TRY(calendar_fields(global_object, calendar, { "day"sv }));
// 8. Let inputFields be ? PrepareTemporalFields(item, inputFieldNames, «»).
auto* input_fields = TRY(prepare_temporal_fields(global_object, item.as_object(), input_field_names, {}));
auto* input_fields = TRY(prepare_temporal_fields(global_object, item.as_object(), input_field_names, Vector<StringView> {}));
// 9. Let mergedFields be ? CalendarMergeFields(calendar, fields, inputFields).
auto* merged_fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *input_fields));
@ -410,7 +410,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date)
}
// 11. Set mergedFields to ? PrepareTemporalFields(mergedFields, mergedFieldNames, «»).
merged_fields = TRY(prepare_temporal_fields(global_object, *merged_fields, merged_field_names, {}));
merged_fields = TRY(prepare_temporal_fields(global_object, *merged_fields, merged_field_names, Vector<StringView> {}));
// 12. Let options be OrdinaryObjectCreate(null).
auto* options = Object::create(global_object, nullptr);

View file

@ -153,7 +153,7 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(GlobalObject& glob
field_names.append("offset");
// f. Let fields be ? PrepareTemporalFields(item, fieldNames, « "timeZone" »).
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, { "timeZone"sv }));
auto* fields = TRY(prepare_temporal_fields(global_object, item_object, field_names, Vector<StringView> { "timeZone"sv }));
// g. Let timeZone be ! Get(fields, "timeZone").
auto time_zone_value = MUST(fields->get(vm.names.timeZone));

View file

@ -744,8 +744,8 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with)
// 7. Append "offset" to fieldNames.
field_names.append("offset"sv);
// 8. Let partialZonedDateTime be ? PreparePartialTemporalFields(temporalZonedDateTimeLike, fieldNames).
auto* partial_zoned_date_time = TRY(prepare_partial_temporal_fields(global_object, temporal_zoned_date_time_like.as_object(), field_names));
// 8. Let partialZonedDateTime be ? PrepareTemporalFields(temporalZonedDateTimeLike, fieldNames, partial).
auto* partial_zoned_date_time = TRY(prepare_temporal_fields(global_object, temporal_zoned_date_time_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
// 9. Set options to ? GetOptionsObject(options).
auto* options = TRY(get_options_object(global_object, vm.argument(1)));
@ -763,13 +763,13 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with)
field_names.append("timeZone"sv);
// 14. Let fields be ? PrepareTemporalFields(zonedDateTime, fieldNames, « "timeZone", "offset" »).
auto* fields = TRY(prepare_temporal_fields(global_object, *zoned_date_time, field_names, { "timeZone"sv, "offset"sv }));
auto* fields = TRY(prepare_temporal_fields(global_object, *zoned_date_time, field_names, Vector<StringView> { "timeZone"sv, "offset"sv }));
// 15. Set fields to ? CalendarMergeFields(calendar, fields, partialZonedDateTime).
fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *partial_zoned_date_time));
// 16. Set fields to ? PrepareTemporalFields(fields, fieldNames, « "timeZone", "offset" »).
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, { "timeZone"sv, "offset"sv }));
fields = TRY(prepare_temporal_fields(global_object, *fields, field_names, Vector<StringView> { "timeZone"sv, "offset"sv }));
// 17. Let offsetString be ! Get(fields, "offset").
auto offset_string = MUST(fields->get(vm.names.offset));
@ -1245,7 +1245,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_year_month)
auto field_names = TRY(calendar_fields(global_object, calendar, { "monthCode"sv, "year"sv }));
// 8. Let fields be ? PrepareTemporalFields(temporalDateTime, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date_time, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date_time, field_names, Vector<StringView> {}));
// 9. Return ? CalendarYearMonthFromFields(calendar, fields).
return TRY(calendar_year_month_from_fields(global_object, calendar, *fields));
@ -1274,7 +1274,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::to_plain_month_day)
auto field_names = TRY(calendar_fields(global_object, calendar, { "day"sv, "monthCode"sv }));
// 8. Let fields be ? PrepareTemporalFields(temporalDateTime, fieldNames, «»).
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date_time, field_names, {}));
auto* fields = TRY(prepare_temporal_fields(global_object, *temporal_date_time, field_names, Vector<StringView> {}));
// 9. Return ? CalendarMonthDayFromFields(calendar, fields).
return TRY(calendar_month_day_from_fields(global_object, calendar, *fields));