mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:07:46 +00:00
LibJS: Add an explicit operation for merging calendar field names
This is an editorial change in the Temporal spec.
See: 2bd7977
This commit is contained in:
parent
ee80164ac1
commit
3025f77991
4 changed files with 33 additions and 20 deletions
|
@ -1004,4 +1004,32 @@ ThrowCompletionOr<Object*> default_merge_calendar_fields(GlobalObject& global_ob
|
|||
return merged;
|
||||
}
|
||||
|
||||
// 12.2.41 CalendarMergeFieldNames ( receiverFieldNames, inputFieldNames ), https://tc39.es/proposal-temporal/#sec-temporal-calendarmergefieldnames
|
||||
Vector<String> calendar_merge_field_names(Vector<String> const& receiver_field_names, Vector<String> const& input_field_names)
|
||||
{
|
||||
// 1. Let merged be a new empty List.
|
||||
Vector<String> merged;
|
||||
|
||||
// 2. For each element name of receiverFieldNames, do
|
||||
for (auto const& field_name : receiver_field_names) {
|
||||
// a. If merged does not contain name, then
|
||||
if (!merged.contains_slow(field_name)) {
|
||||
// i. Append name to merged.
|
||||
merged.append(field_name);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. For each element name of inputFieldNames, do
|
||||
for (auto const& field_name : input_field_names) {
|
||||
// a. If merged does not contain name, then
|
||||
if (!merged.contains_slow(field_name)) {
|
||||
// i. Append name to merged.
|
||||
merged.append(field_name);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Return merged.
|
||||
return merged;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -74,5 +74,6 @@ 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(GlobalObject&, Object const& fields, Object const& additional_fields);
|
||||
Vector<String> calendar_merge_field_names(Vector<String> const& receiver_field_names, Vector<String> const& input_field_names);
|
||||
|
||||
}
|
||||
|
|
|
@ -231,16 +231,8 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::to_plain_date)
|
|||
// 9. Let mergedFields be ? CalendarMergeFields(calendar, fields, inputFields).
|
||||
auto* merged_fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *input_fields));
|
||||
|
||||
// 10. Let mergedFieldNames be the List containing all the elements of receiverFieldNames followed by all the elements of inputFieldNames, with duplicate elements removed.
|
||||
Vector<String> merged_field_names;
|
||||
for (auto& field_name : receiver_field_names) {
|
||||
if (!merged_field_names.contains_slow(field_name))
|
||||
merged_field_names.append(move(field_name));
|
||||
}
|
||||
for (auto& field_name : input_field_names) {
|
||||
if (!merged_field_names.contains_slow(field_name))
|
||||
merged_field_names.append(move(field_name));
|
||||
}
|
||||
// 10. Let mergedFieldNames be CalendarMergeFieldNames(receiverFieldNames, inputFieldNames).
|
||||
auto merged_field_names = calendar_merge_field_names(receiver_field_names, input_field_names);
|
||||
|
||||
// 11. Set mergedFields to ? PrepareTemporalFields(mergedFields, mergedFieldNames, «»).
|
||||
merged_fields = TRY(prepare_temporal_fields(global_object, *merged_fields, merged_field_names, Vector<StringView> {}));
|
||||
|
|
|
@ -398,16 +398,8 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::to_plain_date)
|
|||
// 9. Let mergedFields be ? CalendarMergeFields(calendar, fields, inputFields).
|
||||
auto* merged_fields = TRY(calendar_merge_fields(global_object, calendar, *fields, *input_fields));
|
||||
|
||||
// 10. Let mergedFieldNames be the List containing all the elements of receiverFieldNames followed by all the elements of inputFieldNames, with duplicate elements removed.
|
||||
Vector<String> merged_field_names;
|
||||
for (auto& field_name : receiver_field_names) {
|
||||
if (!merged_field_names.contains_slow(field_name))
|
||||
merged_field_names.append(move(field_name));
|
||||
}
|
||||
for (auto& field_name : input_field_names) {
|
||||
if (!merged_field_names.contains_slow(field_name))
|
||||
merged_field_names.append(move(field_name));
|
||||
}
|
||||
// 10. Let mergedFieldNames be CalendarMergeFieldNames(receiverFieldNames, inputFieldNames).
|
||||
auto merged_field_names = calendar_merge_field_names(receiver_field_names, input_field_names);
|
||||
|
||||
// 11. Set mergedFields to ? PrepareTemporalFields(mergedFields, mergedFieldNames, «»).
|
||||
merged_fields = TRY(prepare_temporal_fields(global_object, *merged_fields, merged_field_names, Vector<StringView> {}));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue