// Copyright 2013 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "src/keys.h" #include "src/api-arguments.h" #include "src/elements.h" #include "src/factory.h" #include "src/identity-map.h" #include "src/isolate-inl.h" #include "src/objects-inl.h" #include "src/property-descriptor.h" #include "src/prototype.h" namespace v8 { namespace internal { KeyAccumulator::~KeyAccumulator() { } namespace { static bool ContainsOnlyValidKeys(Handle array) { int len = array->length(); for (int i = 0; i < len; i++) { Object* e = array->get(i); if (!(e->IsName() || e->IsNumber())) return false; } return true; } } // namespace MaybeHandle KeyAccumulator::GetKeys( Handle object, KeyCollectionType type, PropertyFilter filter, GetKeysConversion keys_conversion, bool filter_proxy_keys, bool is_for_in) { USE(ContainsOnlyValidKeys); Isolate* isolate = object->GetIsolate(); KeyAccumulator accumulator(isolate, type, filter); accumulator.set_filter_proxy_keys(filter_proxy_keys); accumulator.set_is_for_in(is_for_in); MAYBE_RETURN(accumulator.CollectKeys(object, object), MaybeHandle()); Handle keys = accumulator.GetKeys(keys_conversion); DCHECK(ContainsOnlyValidKeys(keys)); return keys; } Handle KeyAccumulator::GetKeys(GetKeysConversion convert) { if (keys_.is_null()) { return isolate_->factory()->empty_fixed_array(); } if (type_ == OWN_ONLY && keys_->map() == isolate_->heap()->fixed_array_map()) { return Handle::cast(keys_); } return OrderedHashSet::ConvertToKeysArray(keys(), convert); } void KeyAccumulator::AddKey(Object* key, AddKeyConversion convert) { AddKey(handle(key, isolate_), convert); } void KeyAccumulator::AddKey(Handle key, AddKeyConversion convert) { if (key->IsSymbol()) { if (filter_ & SKIP_SYMBOLS) return; if (Handle::cast(key)->is_private()) return; } else if (filter_ & SKIP_STRINGS) { return; } if (keys_.is_null()) { keys_ = OrderedHashSet::Allocate(isolate_, 16); } uint32_t index; if (convert == CONVERT_TO_ARRAY_INDEX && key->IsString() && Handle::cast(key)->AsArrayIndex(&index)) { key = isolate_->factory()->NewNumberFromUint(index); } keys_ = OrderedHashSet::Add(keys(), key); } void KeyAccumulator::AddKeys(Handle array, AddKeyConversion convert) { int add_length = array->length(); for (int i = 0; i < add_length; i++) { Handle current(array->get(i), isolate_); AddKey(current, convert); } } void KeyAccumulator::AddKeys(Handle array_like, AddKeyConversion convert) { DCHECK(array_like->IsJSArray() || array_like->HasSloppyArgumentsElements()); ElementsAccessor* accessor = array_like->GetElementsAccessor(); accessor->AddElementsToKeyAccumulator(array_like, this, convert); } MaybeHandle FilterProxyKeys(Isolate* isolate, Handle owner, Handle keys, PropertyFilter filter) { if (filter == ALL_PROPERTIES) { // Nothing to do. return keys; } int store_position = 0; for (int i = 0; i < keys->length(); ++i) { Handle key(Name::cast(keys->get(i)), isolate); if (key->FilterKey(filter)) continue; // Skip this key. if (filter & ONLY_ENUMERABLE) { PropertyDescriptor desc; Maybe found = JSProxy::GetOwnPropertyDescriptor(isolate, owner, key, &desc); MAYBE_RETURN(found, MaybeHandle()); if (!found.FromJust() || !desc.enumerable()) continue; // Skip this key. } // Keep this key. if (store_position != i) { keys->set(store_position, *key); } store_position++; } if (store_position == 0) return isolate->factory()->empty_fixed_array(); keys->Shrink(store_position); return keys; } // Returns "nothing" in case of exception, "true" on success. Maybe KeyAccumulator::AddKeysFromJSProxy(Handle proxy, Handle keys) { if (filter_proxy_keys_) { DCHECK(!is_for_in_); ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate_, keys, FilterProxyKeys(isolate_, proxy, keys, filter_), Nothing()); } if (type_ == OWN_ONLY && !is_for_in_) { // If we collect only the keys from a JSProxy do not sort or deduplicate it. keys_ = keys; return Just(true); } AddKeys(keys, is_for_in_ ? CONVERT_TO_ARRAY_INDEX : DO_NOT_CONVERT); return Just(true); } Maybe KeyAccumulator::CollectKeys(Handle receiver, Handle object) { // Proxies have no hidden prototype and we should not trigger the // [[GetPrototypeOf]] trap on the last iteration when using // AdvanceFollowingProxies. if (type_ == OWN_ONLY && object->IsJSProxy()) { MAYBE_RETURN(CollectOwnJSProxyKeys(receiver, Handle::cast(object)), Nothing()); return Just(true); } PrototypeIterator::WhereToEnd end = type_ == OWN_ONLY ? PrototypeIterator::END_AT_NON_HIDDEN : PrototypeIterator::END_AT_NULL; for (PrototypeIterator iter(isolate_, object, PrototypeIterator::START_AT_RECEIVER, end); !iter.IsAtEnd();) { Handle current = PrototypeIterator::GetCurrent(iter); Maybe result = Just(false); // Dummy initialization. if (current->IsJSProxy()) { result = CollectOwnJSProxyKeys(receiver, Handle::cast(current)); } else { DCHECK(current->IsJSObject()); result = CollectOwnKeys(receiver, Handle::cast(current)); } MAYBE_RETURN(result, Nothing()); if (!result.FromJust()) break; // |false| means "stop iterating". // Iterate through proxies but ignore access checks for the ALL_CAN_READ // case on API objects for OWN_ONLY keys handled in CollectOwnKeys. if (!iter.AdvanceFollowingProxiesIgnoringAccessChecks()) { return Nothing(); } } return Just(true); } namespace { void TrySettingEmptyEnumCache(JSReceiver* object) { Map* map = object->map(); DCHECK_EQ(kInvalidEnumCacheSentinel, map->EnumLength()); if (!map->OnlyHasSimpleProperties()) return; if (map->IsJSProxyMap()) return; if (map->NumberOfOwnDescriptors() > 0) { int number_of_enumerable_own_properties = map->NumberOfDescribedProperties(OWN_DESCRIPTORS, ENUMERABLE_STRINGS); if (number_of_enumerable_own_properties > 0) return; } DCHECK(object->IsJSObject()); map->SetEnumLength(0); } bool CheckAndInitalizeSimpleEnumCache(JSReceiver* object) { if (object->map()->EnumLength() == kInvalidEnumCacheSentinel) { TrySettingEmptyEnumCache(object); } if (object->map()->EnumLength() != 0) return false; DCHECK(object->IsJSObject()); return !JSObject::cast(object)->HasEnumerableElements(); } } // namespace void FastKeyAccumulator::Prepare() { DisallowHeapAllocation no_gc; // Directly go for the fast path for OWN_ONLY keys. if (type_ == OWN_ONLY) return; // Fully walk the prototype chain and find the last prototype with keys. is_receiver_simple_enum_ = false; has_empty_prototype_ = true; JSReceiver* first_non_empty_prototype; for (PrototypeIterator iter(isolate_, *receiver_); !iter.IsAtEnd(); iter.Advance()) { JSReceiver* current = iter.GetCurrent(); if (CheckAndInitalizeSimpleEnumCache(current)) continue; has_empty_prototype_ = false; first_non_empty_prototype = current; // TODO(cbruni): use the first non-empty prototype. USE(first_non_empty_prototype); return; } DCHECK(has_empty_prototype_); is_receiver_simple_enum_ = receiver_->map()->EnumLength() != kInvalidEnumCacheSentinel && !JSObject::cast(*receiver_)->HasEnumerableElements(); } namespace { static Handle ReduceFixedArrayTo(Isolate* isolate, Handle array, int length) { DCHECK_LE(length, array->length()); if (array->length() == length) return array; return isolate->factory()->CopyFixedArrayUpTo(array, length); } Handle GetFastEnumPropertyKeys(Isolate* isolate, Handle object) { Handle map(object->map()); bool cache_enum_length = map->OnlyHasSimpleProperties(); Handle descs = Handle(map->instance_descriptors(), isolate); int own_property_count = map->EnumLength(); // If the enum length of the given map is set to kInvalidEnumCache, this // means that the map itself has never used the present enum cache. The // first step to using the cache is to set the enum length of the map by // counting the number of own descriptors that are ENUMERABLE_STRINGS. if (own_property_count == kInvalidEnumCacheSentinel) { own_property_count = map->NumberOfDescribedProperties(OWN_DESCRIPTORS, ENUMERABLE_STRINGS); } else { DCHECK( own_property_count == map->NumberOfDescribedProperties(OWN_DESCRIPTORS, ENUMERABLE_STRINGS)); } if (descs->HasEnumCache()) { Handle keys(descs->GetEnumCache(), isolate); // In case the number of properties required in the enum are actually // present, we can reuse the enum cache. Otherwise, this means that the // enum cache was generated for a previous (smaller) version of the // Descriptor Array. In that case we regenerate the enum cache. if (own_property_count <= keys->length()) { isolate->counters()->enum_cache_hits()->Increment(); if (cache_enum_length) map->SetEnumLength(own_property_count); return ReduceFixedArrayTo(isolate, keys, own_property_count); } } if (descs->IsEmpty()) { isolate->counters()->enum_cache_hits()->Increment(); if (cache_enum_length) map->SetEnumLength(0); return isolate->factory()->empty_fixed_array(); } isolate->counters()->enum_cache_misses()->Increment(); Handle storage = isolate->factory()->NewFixedArray(own_property_count); Handle indices = isolate->factory()->NewFixedArray(own_property_count); int size = map->NumberOfOwnDescriptors(); int index = 0; for (int i = 0; i < size; i++) { PropertyDetails details = descs->GetDetails(i); if (details.IsDontEnum()) continue; Object* key = descs->GetKey(i); if (key->IsSymbol()) continue; storage->set(index, key); if (!indices.is_null()) { if (details.type() != DATA) { indices = Handle(); } else { FieldIndex field_index = FieldIndex::ForDescriptor(*map, i); int load_by_field_index = field_index.GetLoadByFieldIndex(); indices->set(index, Smi::FromInt(load_by_field_index)); } } index++; } DCHECK(index == storage->length()); DescriptorArray::SetEnumCache(descs, isolate, storage, indices); if (cache_enum_length) { map->SetEnumLength(own_property_count); } return storage; } template Handle GetOwnKeysWithElements(Isolate* isolate, Handle object, GetKeysConversion convert) { Handle keys; ElementsAccessor* accessor = object->GetElementsAccessor(); if (fast_properties) { keys = GetFastEnumPropertyKeys(isolate, object); } else { // TODO(cbruni): preallocate big enough array to also hold elements. keys = KeyAccumulator::GetEnumPropertyKeys(isolate, object); } Handle result = accessor->PrependElementIndices(object, keys, convert, ONLY_ENUMERABLE); if (FLAG_trace_for_in_enumerate) { PrintF("| strings=%d symbols=0 elements=%u || prototypes>=1 ||\n", keys->length(), result->length() - keys->length()); } return result; } MaybeHandle GetOwnKeysWithUninitializedEnumCache( Isolate* isolate, Handle object) { // Uninitalized enum cache Map* map = object->map(); if (object->elements() != isolate->heap()->empty_fixed_array() || object->elements() != isolate->heap()->empty_slow_element_dictionary()) { // Assume that there are elements. return MaybeHandle(); } int number_of_own_descriptors = map->NumberOfOwnDescriptors(); if (number_of_own_descriptors == 0) { map->SetEnumLength(0); return isolate->factory()->empty_fixed_array(); } // We have no elements but possibly enumerable property keys, hence we can // directly initialize the enum cache. return GetFastEnumPropertyKeys(isolate, object); } bool OnlyHasSimpleProperties(Map* map) { return map->instance_type() > LAST_CUSTOM_ELEMENTS_RECEIVER; } } // namespace MaybeHandle FastKeyAccumulator::GetKeys(GetKeysConversion convert) { Handle keys; if (GetKeysFast(convert).ToHandle(&keys)) { return keys; } return GetKeysSlow(convert); } MaybeHandle FastKeyAccumulator::GetKeysFast( GetKeysConversion convert) { bool own_only = has_empty_prototype_ || type_ == OWN_ONLY; Map* map = receiver_->map(); if (!own_only || !OnlyHasSimpleProperties(map)) { return MaybeHandle(); } // From this point on we are certiain to only collect own keys. DCHECK(receiver_->IsJSObject()); Handle object = Handle::cast(receiver_); // Do not try to use the enum-cache for dict-mode objects. if (map->is_dictionary_map()) { return GetOwnKeysWithElements(isolate_, object, convert); } int enum_length = receiver_->map()->EnumLength(); if (enum_length == kInvalidEnumCacheSentinel) { Handle keys; // Try initializing the enum cache and return own properties. if (GetOwnKeysWithUninitializedEnumCache(isolate_, object) .ToHandle(&keys)) { if (FLAG_trace_for_in_enumerate) { PrintF("| strings=%d symbols=0 elements=0 || prototypes>=1 ||\n", keys->length()); } is_receiver_simple_enum_ = object->map()->EnumLength() != kInvalidEnumCacheSentinel; return keys; } } // The properties-only case failed because there were probably elements on the // receiver. return GetOwnKeysWithElements(isolate_, object, convert); } MaybeHandle FastKeyAccumulator::GetKeysSlow( GetKeysConversion convert) { return KeyAccumulator::GetKeys(receiver_, type_, filter_, KEEP_NUMBERS, filter_proxy_keys_, is_for_in_); } namespace { enum IndexedOrNamed { kIndexed, kNamed }; // Returns |true| on success, |nothing| on exception. template Maybe GetKeysFromInterceptor(Handle receiver, Handle object, KeyAccumulator* accumulator) { Isolate* isolate = accumulator->isolate(); if (type == kIndexed) { if (!object->HasIndexedInterceptor()) return Just(true); } else { if (!object->HasNamedInterceptor()) return Just(true); } Handle interceptor(type == kIndexed ? object->GetIndexedInterceptor() : object->GetNamedInterceptor(), isolate); if ((accumulator->filter() & ONLY_ALL_CAN_READ) && !interceptor->all_can_read()) { return Just(true); } PropertyCallbackArguments args(isolate, interceptor->data(), *receiver, *object, Object::DONT_THROW); Handle result; if (!interceptor->enumerator()->IsUndefined()) { Callback enum_fun = v8::ToCData(interceptor->enumerator()); const char* log_tag = type == kIndexed ? "interceptor-indexed-enum" : "interceptor-named-enum"; LOG(isolate, ApiObjectAccess(log_tag, *object)); result = args.Call(enum_fun); } RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing()); if (result.is_null()) return Just(true); accumulator->AddKeys( result, type == kIndexed ? CONVERT_TO_ARRAY_INDEX : DO_NOT_CONVERT); return Just(true); } } // namespace Maybe KeyAccumulator::CollectOwnElementIndices( Handle receiver, Handle object) { if (filter_ & SKIP_STRINGS || skip_indices_) return Just(true); ElementsAccessor* accessor = object->GetElementsAccessor(); accessor->CollectElementIndices(object, this); return GetKeysFromInterceptor(receiver, object, this); } namespace { template int CollectOwnPropertyNamesInternal(Handle object, KeyAccumulator* keys, Handle descs, int start_index, int limit) { int first_skipped = -1; for (int i = start_index; i < limit; i++) { PropertyDetails details = descs->GetDetails(i); if ((details.attributes() & keys->filter()) != 0) continue; if (keys->filter() & ONLY_ALL_CAN_READ) { if (details.kind() != kAccessor) continue; Object* accessors = descs->GetValue(i); if (!accessors->IsAccessorInfo()) continue; if (!AccessorInfo::cast(accessors)->all_can_read()) continue; } Name* key = descs->GetKey(i); if (skip_symbols == key->IsSymbol()) { if (first_skipped == -1) first_skipped = i; continue; } if (key->FilterKey(keys->filter())) continue; keys->AddKey(key, DO_NOT_CONVERT); } return first_skipped; } } // namespace Maybe KeyAccumulator::CollectOwnPropertyNames(Handle receiver, Handle object) { if (filter_ == ENUMERABLE_STRINGS) { Handle enum_keys = KeyAccumulator::GetEnumPropertyKeys(isolate_, object); AddKeys(enum_keys, DO_NOT_CONVERT); } else { if (object->HasFastProperties()) { int limit = object->map()->NumberOfOwnDescriptors(); Handle descs(object->map()->instance_descriptors(), isolate_); // First collect the strings, int first_symbol = CollectOwnPropertyNamesInternal(object, this, descs, 0, limit); // then the symbols. if (first_symbol != -1) { CollectOwnPropertyNamesInternal(object, this, descs, first_symbol, limit); } } else if (object->IsJSGlobalObject()) { GlobalDictionary::CollectKeysTo( handle(object->global_dictionary(), isolate_), this, filter_); } else { NameDictionary::CollectKeysTo( handle(object->property_dictionary(), isolate_), this, filter_); } } // Add the property keys from the interceptor. return GetKeysFromInterceptor(receiver, object, this); } // Returns |true| on success, |false| if prototype walking should be stopped, // |nothing| if an exception was thrown. Maybe KeyAccumulator::CollectOwnKeys(Handle receiver, Handle object) { // Check access rights if required. if (object->IsAccessCheckNeeded() && !isolate_->MayAccess(handle(isolate_->context()), object)) { // The cross-origin spec says that [[Enumerate]] shall return an empty // iterator when it doesn't have access... if (type_ == INCLUDE_PROTOS) { return Just(false); } // ...whereas [[OwnPropertyKeys]] shall return whitelisted properties. DCHECK_EQ(OWN_ONLY, type_); filter_ = static_cast(filter_ | ONLY_ALL_CAN_READ); } MAYBE_RETURN(CollectOwnElementIndices(receiver, object), Nothing()); MAYBE_RETURN(CollectOwnPropertyNames(receiver, object), Nothing()); return Just(true); } // static Handle KeyAccumulator::GetEnumPropertyKeys( Isolate* isolate, Handle object) { if (object->HasFastProperties()) { return GetFastEnumPropertyKeys(isolate, object); } else if (object->IsJSGlobalObject()) { Handle dictionary(object->global_dictionary(), isolate); int length = dictionary->NumberOfEnumElements(); if (length == 0) { return isolate->factory()->empty_fixed_array(); } Handle storage = isolate->factory()->NewFixedArray(length); dictionary->CopyEnumKeysTo(*storage); return storage; } else { Handle dictionary(object->property_dictionary(), isolate); int length = dictionary->NumberOfEnumElements(); if (length == 0) { return isolate->factory()->empty_fixed_array(); } Handle storage = isolate->factory()->NewFixedArray(length); dictionary->CopyEnumKeysTo(*storage); return storage; } } // ES6 9.5.12 // Returns |true| on success, |nothing| in case of exception. Maybe KeyAccumulator::CollectOwnJSProxyKeys(Handle receiver, Handle proxy) { STACK_CHECK(isolate_, Nothing()); // 1. Let handler be the value of the [[ProxyHandler]] internal slot of O. Handle handler(proxy->handler(), isolate_); // 2. If handler is null, throw a TypeError exception. // 3. Assert: Type(handler) is Object. if (proxy->IsRevoked()) { isolate_->Throw(*isolate_->factory()->NewTypeError( MessageTemplate::kProxyRevoked, isolate_->factory()->ownKeys_string())); return Nothing(); } // 4. Let target be the value of the [[ProxyTarget]] internal slot of O. Handle target(proxy->target(), isolate_); // 5. Let trap be ? GetMethod(handler, "ownKeys"). Handle trap; ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate_, trap, Object::GetMethod(Handle::cast(handler), isolate_->factory()->ownKeys_string()), Nothing()); // 6. If trap is undefined, then if (trap->IsUndefined()) { // 6a. Return target.[[OwnPropertyKeys]](). return CollectOwnJSProxyTargetKeys(proxy, target); } // 7. Let trapResultArray be Call(trap, handler, «target»). Handle trap_result_array; Handle args[] = {target}; ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate_, trap_result_array, Execution::Call(isolate_, trap, handler, arraysize(args), args), Nothing()); // 8. Let trapResult be ? CreateListFromArrayLike(trapResultArray, // «String, Symbol»). Handle trap_result; ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate_, trap_result, Object::CreateListFromArrayLike(isolate_, trap_result_array, ElementTypes::kStringAndSymbol), Nothing()); // 9. Let extensibleTarget be ? IsExtensible(target). Maybe maybe_extensible = JSReceiver::IsExtensible(target); MAYBE_RETURN(maybe_extensible, Nothing()); bool extensible_target = maybe_extensible.FromJust(); // 10. Let targetKeys be ? target.[[OwnPropertyKeys]](). Handle target_keys; ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate_, target_keys, JSReceiver::OwnPropertyKeys(target), Nothing()); // 11. (Assert) // 12. Let targetConfigurableKeys be an empty List. // To save memory, we're re-using target_keys and will modify it in-place. Handle target_configurable_keys = target_keys; // 13. Let targetNonconfigurableKeys be an empty List. Handle target_nonconfigurable_keys = isolate_->factory()->NewFixedArray(target_keys->length()); int nonconfigurable_keys_length = 0; // 14. Repeat, for each element key of targetKeys: for (int i = 0; i < target_keys->length(); ++i) { // 14a. Let desc be ? target.[[GetOwnProperty]](key). PropertyDescriptor desc; Maybe found = JSReceiver::GetOwnPropertyDescriptor( isolate_, target, handle(target_keys->get(i), isolate_), &desc); MAYBE_RETURN(found, Nothing()); // 14b. If desc is not undefined and desc.[[Configurable]] is false, then if (found.FromJust() && !desc.configurable()) { // 14b i. Append key as an element of targetNonconfigurableKeys. target_nonconfigurable_keys->set(nonconfigurable_keys_length, target_keys->get(i)); nonconfigurable_keys_length++; // The key was moved, null it out in the original list. target_keys->set(i, Smi::FromInt(0)); } else { // 14c. Else, // 14c i. Append key as an element of targetConfigurableKeys. // (No-op, just keep it in |target_keys|.) } } // 15. If extensibleTarget is true and targetNonconfigurableKeys is empty, // then: if (extensible_target && nonconfigurable_keys_length == 0) { // 15a. Return trapResult. return AddKeysFromJSProxy(proxy, trap_result); } // 16. Let uncheckedResultKeys be a new List which is a copy of trapResult. Zone set_zone(isolate_->allocator()); const int kPresent = 1; const int kGone = 0; IdentityMap unchecked_result_keys(isolate_->heap(), &set_zone); int unchecked_result_keys_size = 0; for (int i = 0; i < trap_result->length(); ++i) { DCHECK(trap_result->get(i)->IsUniqueName()); Object* key = trap_result->get(i); int* entry = unchecked_result_keys.Get(key); if (*entry != kPresent) { *entry = kPresent; unchecked_result_keys_size++; } } // 17. Repeat, for each key that is an element of targetNonconfigurableKeys: for (int i = 0; i < nonconfigurable_keys_length; ++i) { Object* key = target_nonconfigurable_keys->get(i); // 17a. If key is not an element of uncheckedResultKeys, throw a // TypeError exception. int* found = unchecked_result_keys.Find(key); if (found == nullptr || *found == kGone) { isolate_->Throw(*isolate_->factory()->NewTypeError( MessageTemplate::kProxyOwnKeysMissing, handle(key, isolate_))); return Nothing(); } // 17b. Remove key from uncheckedResultKeys. *found = kGone; unchecked_result_keys_size--; } // 18. If extensibleTarget is true, return trapResult. if (extensible_target) { return AddKeysFromJSProxy(proxy, trap_result); } // 19. Repeat, for each key that is an element of targetConfigurableKeys: for (int i = 0; i < target_configurable_keys->length(); ++i) { Object* key = target_configurable_keys->get(i); if (key->IsSmi()) continue; // Zapped entry, was nonconfigurable. // 19a. If key is not an element of uncheckedResultKeys, throw a // TypeError exception. int* found = unchecked_result_keys.Find(key); if (found == nullptr || *found == kGone) { isolate_->Throw(*isolate_->factory()->NewTypeError( MessageTemplate::kProxyOwnKeysMissing, handle(key, isolate_))); return Nothing(); } // 19b. Remove key from uncheckedResultKeys. *found = kGone; unchecked_result_keys_size--; } // 20. If uncheckedResultKeys is not empty, throw a TypeError exception. if (unchecked_result_keys_size != 0) { DCHECK_GT(unchecked_result_keys_size, 0); isolate_->Throw(*isolate_->factory()->NewTypeError( MessageTemplate::kProxyOwnKeysNonExtensible)); return Nothing(); } // 21. Return trapResult. return AddKeysFromJSProxy(proxy, trap_result); } Maybe KeyAccumulator::CollectOwnJSProxyTargetKeys( Handle proxy, Handle target) { // TODO(cbruni): avoid creating another KeyAccumulator Handle keys; ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate_, keys, JSReceiver::OwnPropertyKeys(target), Nothing()); bool prev_filter_proxy_keys_ = filter_proxy_keys_; filter_proxy_keys_ = false; Maybe result = AddKeysFromJSProxy(proxy, keys); filter_proxy_keys_ = prev_filter_proxy_keys_; return result; } } // namespace internal } // namespace v8