diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index c6d98e36c2..2d5bafd9ce 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -487,6 +487,23 @@ ThrowCompletionOr Object::copy_data_properties(VM& vm, Value source, HashT return {}; } +// 14.7 SnapshotOwnProperties ( source, proto [ , excludedKeys [ , excludedValues ] ] ), https://tc39.es/proposal-temporal/#sec-snapshotownproperties +ThrowCompletionOr> Object::snapshot_own_properties(VM& vm, GCPtr prototype, HashTable const& excluded_keys, HashTable const& excluded_values) +{ + auto& realm = *vm.current_realm(); + + // 1. Let copy be OrdinaryObjectCreate(proto). + auto copy = Object::create(realm, prototype); + + // 2. If excludedKeys is not present, set excludedKeys to « ». + // 3. If excludedValues is not present, set excludedValues to « ». + // 4. Perform ? CopyDataProperties(copy, source, excludedKeys, excludedValues). + TRY(copy->copy_data_properties(vm, Value { this }, excluded_keys, excluded_values)); + + // 5. Return copy. + return copy; +} + // 7.3.27 PrivateElementFind ( O, P ), https://tc39.es/ecma262/#sec-privateelementfind PrivateElement* Object::private_element_find(PrivateName const& name) { diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index 492a556301..8fa9aa1529 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -119,6 +119,7 @@ public: ThrowCompletionOr test_integrity_level(IntegrityLevel) const; ThrowCompletionOr> enumerable_own_property_names(PropertyKind kind) const; ThrowCompletionOr copy_data_properties(VM&, Value source, HashTable const& excluded_keys, HashTable const& excluded_values = {}); + ThrowCompletionOr> snapshot_own_properties(VM&, GCPtr prototype, HashTable const& excluded_keys = {}, HashTable const& excluded_values = {}); PrivateElement* private_element_find(PrivateName const& name); ThrowCompletionOr private_field_add(PrivateName const& name, Value value);