mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:37:35 +00:00
LibJS: Implement excluded values in CopyDataProperties
This is a change to this AO as part of the Temporal proposal.
This commit is contained in:
parent
a504d76b14
commit
107fa1fdb8
2 changed files with 13 additions and 6 deletions
|
@ -438,7 +438,8 @@ ThrowCompletionOr<MarkedVector<Value>> Object::enumerable_own_property_names(Pro
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.3.26 CopyDataProperties ( target, source, excludedItems ), https://tc39.es/ecma262/#sec-copydataproperties
|
// 7.3.26 CopyDataProperties ( target, source, excludedItems ), https://tc39.es/ecma262/#sec-copydataproperties
|
||||||
ThrowCompletionOr<void> Object::copy_data_properties(VM& vm, Value source, HashTable<PropertyKey> const& seen_names)
|
// 14.6 CopyDataProperties ( target, source, excludedItems, excludedKeys [ , excludedValues ] ), https://tc39.es/proposal-temporal/#sec-copydataproperties
|
||||||
|
ThrowCompletionOr<void> Object::copy_data_properties(VM& vm, Value source, HashTable<PropertyKey> const& excluded_keys, HashTable<JS::Value> const& excluded_values)
|
||||||
{
|
{
|
||||||
// 1. If source is either undefined or null, return unused.
|
// 1. If source is either undefined or null, return unused.
|
||||||
if (source.is_nullish())
|
if (source.is_nullish())
|
||||||
|
@ -455,10 +456,10 @@ ThrowCompletionOr<void> Object::copy_data_properties(VM& vm, Value source, HashT
|
||||||
auto next_key = MUST(PropertyKey::from_value(vm, next_key_value));
|
auto next_key = MUST(PropertyKey::from_value(vm, next_key_value));
|
||||||
|
|
||||||
// a. Let excluded be false.
|
// a. Let excluded be false.
|
||||||
// b. For each element e of excludedItems, do
|
// b. For each element e of excludedKeys, do
|
||||||
// i. If SameValue(e, nextKey) is true, then
|
// i. If SameValue(e, nextKey) is true, then
|
||||||
// 1. Set excluded to true.
|
// 1. Set excluded to true.
|
||||||
if (seen_names.contains(next_key))
|
if (excluded_keys.contains(next_key))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// c. If excluded is false, then
|
// c. If excluded is false, then
|
||||||
|
@ -471,8 +472,14 @@ ThrowCompletionOr<void> Object::copy_data_properties(VM& vm, Value source, HashT
|
||||||
// 1. Let propValue be ? Get(from, nextKey).
|
// 1. Let propValue be ? Get(from, nextKey).
|
||||||
auto prop_value = TRY(from->get(next_key));
|
auto prop_value = TRY(from->get(next_key));
|
||||||
|
|
||||||
// 2. Perform ! CreateDataPropertyOrThrow(target, nextKey, propValue).
|
// 2. If excludedValues is present, then
|
||||||
MUST(create_data_property_or_throw(next_key, prop_value));
|
// a. For each element e of excludedValues, do
|
||||||
|
// i. If SameValue(e, propValue) is true, then
|
||||||
|
// i. Set excluded to true.
|
||||||
|
// 3. If excluded is false, Perform ! CreateDataPropertyOrThrow(target, nextKey, propValue).
|
||||||
|
// NOTE: HashTable traits for JS::Value uses SameValue.
|
||||||
|
if (!excluded_values.contains(prop_value))
|
||||||
|
MUST(create_data_property_or_throw(next_key, prop_value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ public:
|
||||||
ThrowCompletionOr<bool> set_integrity_level(IntegrityLevel);
|
ThrowCompletionOr<bool> set_integrity_level(IntegrityLevel);
|
||||||
ThrowCompletionOr<bool> test_integrity_level(IntegrityLevel) const;
|
ThrowCompletionOr<bool> test_integrity_level(IntegrityLevel) const;
|
||||||
ThrowCompletionOr<MarkedVector<Value>> enumerable_own_property_names(PropertyKind kind) const;
|
ThrowCompletionOr<MarkedVector<Value>> enumerable_own_property_names(PropertyKind kind) const;
|
||||||
ThrowCompletionOr<void> copy_data_properties(VM&, Value source, HashTable<PropertyKey> const& seen_names);
|
ThrowCompletionOr<void> copy_data_properties(VM&, Value source, HashTable<PropertyKey> const& excluded_keys, HashTable<JS::Value> const& excluded_values = {});
|
||||||
|
|
||||||
PrivateElement* private_element_find(PrivateName const& name);
|
PrivateElement* private_element_find(PrivateName const& name);
|
||||||
ThrowCompletionOr<void> private_field_add(PrivateName const& name, Value value);
|
ThrowCompletionOr<void> private_field_add(PrivateName const& name, Value value);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue