1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 21:08:12 +00:00

LibJS: Use consistent alias names for object-copy steps

This is an editorial change in the Temporal spec.

See: 6669bad
This commit is contained in:
Linus Groh 2022-06-15 00:19:04 +01:00
parent e68173b656
commit c0986be2c1
2 changed files with 25 additions and 25 deletions

View file

@ -941,51 +941,51 @@ ThrowCompletionOr<Object*> default_merge_calendar_fields(GlobalObject& global_ob
// 1. Let merged be OrdinaryObjectCreate(%Object.prototype%).
auto* merged = Object::create(global_object, global_object.object_prototype());
// 2. Let originalKeys be ? EnumerableOwnPropertyNames(fields, key).
auto original_keys = TRY(fields.enumerable_own_property_names(Object::PropertyKind::Key));
// 2. Let fieldsKeys be ? EnumerableOwnPropertyNames(fields, key).
auto fields_keys = TRY(fields.enumerable_own_property_names(Object::PropertyKind::Key));
// 3. For each element nextKey of originalKeys, do
for (auto& next_key : original_keys) {
// a. If nextKey is not "month" or "monthCode", then
if (next_key.as_string().string() != vm.names.month.as_string() && next_key.as_string().string() != vm.names.monthCode.as_string()) {
auto property_key = MUST(PropertyKey::from_value(global_object, next_key));
// 3. For each element key of fieldsKeys, do
for (auto& key : fields_keys) {
// a. If key is not "month" or "monthCode", then
if (key.as_string().string() != vm.names.month.as_string() && key.as_string().string() != vm.names.monthCode.as_string()) {
auto property_key = MUST(PropertyKey::from_value(global_object, key));
// i. Let propValue be ? Get(fields, nextKey).
// i. Let propValue be ? Get(fields, key).
auto prop_value = TRY(fields.get(property_key));
// ii. If propValue is not undefined, then
if (!prop_value.is_undefined()) {
// 1. Perform ! CreateDataPropertyOrThrow(merged, nextKey, propValue).
// 1. Perform ! CreateDataPropertyOrThrow(merged, key, propValue).
MUST(merged->create_data_property_or_throw(property_key, prop_value));
}
}
}
// 4. Let newKeys be ? EnumerableOwnPropertyNames(additionalFields, key).
auto new_keys = TRY(additional_fields.enumerable_own_property_names(Object::PropertyKind::Key));
// 4. Let additionalFieldsKeys be ? EnumerableOwnPropertyNames(additionalFields, key).
auto additional_fields_keys = TRY(additional_fields.enumerable_own_property_names(Object::PropertyKind::Key));
// IMPLEMENTATION DEFINED: This is an optimization, so we don't have to iterate new_keys three times (worst case), but only once.
bool new_keys_contains_month_or_month_code_property = false;
bool additional_fields_keys_contains_month_or_month_code_property = false;
// 5. For each element nextKey of newKeys, do
for (auto& next_key : new_keys) {
auto property_key = MUST(PropertyKey::from_value(global_object, next_key));
// 5. For each element key of additionalFieldsKeys, do
for (auto& key : additional_fields_keys) {
auto property_key = MUST(PropertyKey::from_value(global_object, key));
// a. Let propValue be ? Get(additionalFields, nextKey).
// a. Let propValue be ? Get(additionalFields, key).
auto prop_value = TRY(additional_fields.get(property_key));
// b. If propValue is not undefined, then
if (!prop_value.is_undefined()) {
// i. Perform ! CreateDataPropertyOrThrow(merged, nextKey, propValue).
// i. Perform ! CreateDataPropertyOrThrow(merged, key, propValue).
MUST(merged->create_data_property_or_throw(property_key, prop_value));
}
// See comment above.
new_keys_contains_month_or_month_code_property |= next_key.as_string().string() == vm.names.month.as_string() || next_key.as_string().string() == vm.names.monthCode.as_string();
additional_fields_keys_contains_month_or_month_code_property |= key.as_string().string() == vm.names.month.as_string() || key.as_string().string() == vm.names.monthCode.as_string();
}
// 6. If newKeys does not contain either "month" or "monthCode", then
if (!new_keys_contains_month_or_month_code_property) {
// 6. If additionalFieldsKeys does not contain either "month" or "monthCode", then
if (!additional_fields_keys_contains_month_or_month_code_property) {
// a. Let month be ? Get(fields, "month").
auto month = TRY(fields.get(vm.names.month));

View file

@ -409,12 +409,12 @@ ThrowCompletionOr<PlainYearMonth*> add_duration_to_or_subtract_duration_from_pla
// 15. Let entries be ? EnumerableOwnPropertyNames(options, key+value).
auto entries = TRY(options->enumerable_own_property_names(Object::PropertyKind::KeyAndValue));
// 16. For each element nextEntry of entries, do
for (auto& next_entry : entries) {
auto key = MUST(next_entry.as_array().get_without_side_effects(0).to_property_key(global_object));
auto value = next_entry.as_array().get_without_side_effects(1);
// 16. For each element entry of entries, do
for (auto& entry : entries) {
auto key = MUST(entry.as_array().get_without_side_effects(0).to_property_key(global_object));
auto value = entry.as_array().get_without_side_effects(1);
// a. Perform ! CreateDataPropertyOrThrow(optionsCopy, nextEntry[0], nextEntry[1]).
// a. Perform ! CreateDataPropertyOrThrow(optionsCopy, entry[0], entry[1]).
MUST(options_copy->create_data_property_or_throw(key, value));
}