/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
deps/v8/src/runtime/runtime-forin.cc
145 строк
6 KB
Michaël Zasso
deps: update V8 to 14.6.202.33
24 апр 2026, 19:01
Не верифицирован
24 апр 2026, 19:01
f1e0b83
Код
Авторство
О чём код?
// Copyright 2015 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/execution/isolate-inl.h" #include "src/heap/factory.h" #include "src/objects/keys.h" #include "src/objects/module.h" #include "src/objects/objects-inl.h" #include "src/roots/roots-inl.h" namespace v8 { namespace internal { namespace { // Returns either a FixedArray or, if the given {receiver} has an enum cache // that contains all enumerable properties of the {receiver} and its prototypes // have none, the map of the {receiver}. This is used to speed up the check for // deletions during a for-in. MaybeDirectHandle<HeapObject> Enumerate(Isolate* isolate, DirectHandle<JSReceiver> receiver) { JSObject::MakePrototypesFast(receiver, kStartAtReceiver, isolate); FastKeyAccumulator accumulator(isolate, receiver, KeyCollectionMode::kIncludePrototypes, ENUMERABLE_STRINGS, true); // Test if we have an enum cache for {receiver}. if (!accumulator.is_receiver_simple_enum()) { DirectHandle<FixedArray> keys; ASSIGN_RETURN_ON_EXCEPTION( isolate, keys, accumulator.GetKeys(accumulator.may_have_elements() ? GetKeysConversion::kConvertToString : GetKeysConversion::kNoNumbers)); // Test again, since cache may have been built by GetKeys() calls above. if (!accumulator.is_receiver_simple_enum()) return keys; } DCHECK(!IsJSModuleNamespace(*receiver)); return direct_handle(receiver->map(), isolate); } // This is a slight modification of JSReceiver::HasProperty, dealing with // the oddities of JSProxy and JSModuleNamespace in for-in filter. MaybeDirectHandle<Object> HasEnumerableProperty( Isolate* isolate, DirectHandle<JSReceiver> receiver, DirectHandle<Object> key) { bool success = false; Maybe<PropertyAttributes> result = Just(ABSENT); PropertyKey lookup_key(isolate, key, &success); if (!success) return isolate->factory()->undefined_value(); LookupIterator it(isolate, receiver, lookup_key); for (;; it.Next()) { switch (it.state()) { case LookupIterator::TRANSITION: UNREACHABLE(); case LookupIterator::JSPROXY: { // For proxies we have to invoke the [[GetOwnProperty]] trap. result = JSProxy::GetPropertyAttributes(&it); if (result.IsNothing()) return MaybeDirectHandle<Object>(); if (result.FromJust() == ABSENT) { // Continue lookup on the proxy's prototype. DirectHandle<JSProxy> proxy = it.GetHolder<JSProxy>(); DirectHandle<Object> prototype; ASSIGN_RETURN_ON_EXCEPTION(isolate, prototype, JSProxy::GetPrototype(proxy)); if (IsNull(*prototype, isolate)) { return isolate->factory()->undefined_value(); } // We already have a stack-check in JSProxy::GetPrototype. return HasEnumerableProperty(isolate, Cast<JSReceiver>(prototype), key); } else if (result.FromJust() & DONT_ENUM) { return isolate->factory()->undefined_value(); } else { return it.GetName(); } } case LookupIterator::MODULE_NAMESPACE: { #ifdef DEBUG DirectHandle<JSModuleNamespace> ns = it.GetHolder<JSModuleNamespace>(); if (IsJSDeferredModuleNamespace(*ns)) { DCHECK_EQ(ns->module()->status(), Module::kEvaluated); } #endif continue; } case LookupIterator::STRING_LOOKUP_START_OBJECT: UNREACHABLE(); case LookupIterator::WASM_OBJECT: continue; // Continue to the prototype, if present. case LookupIterator::INTERCEPTOR: { result = JSObject::GetPropertyAttributesWithInterceptor(&it); if (result.IsNothing()) return MaybeDirectHandle<Object>(); if (result.FromJust() != ABSENT) return it.GetName(); continue; } case LookupIterator::ACCESS_CHECK: { if (it.HasAccess()) continue; result = JSObject::GetPropertyAttributesWithFailedAccessCheck(&it); if (result.IsNothing()) return MaybeDirectHandle<Object>(); if (result.FromJust() != ABSENT) return it.GetName(); return isolate->factory()->undefined_value(); } case LookupIterator::TYPED_ARRAY_INDEX_NOT_FOUND: // TypedArray out-of-bounds access. return isolate->factory()->undefined_value(); case LookupIterator::ACCESSOR: { if (IsJSModuleNamespace(*it.GetHolder<Object>())) { result = JSModuleNamespace::GetPropertyAttributes(&it); if (result.IsNothing()) return MaybeDirectHandle<Object>(); DCHECK_EQ(0, result.FromJust() & DONT_ENUM); } return it.GetName(); } case LookupIterator::DATA: return it.GetName(); case LookupIterator::NOT_FOUND: return isolate->factory()->undefined_value(); } UNREACHABLE(); } } } // namespace RUNTIME_FUNCTION(Runtime_ForInEnumerate) { HandleScope scope(isolate); DCHECK_EQ(1, args.length()); DirectHandle<JSReceiver> receiver = args.at<JSReceiver>(0); RETURN_RESULT_OR_FAILURE(isolate, Enumerate(isolate, receiver)); } RUNTIME_FUNCTION(Runtime_ForInHasProperty) { HandleScope scope(isolate); DCHECK_EQ(2, args.length()); DirectHandle<JSReceiver> receiver = args.at<JSReceiver>(0); DirectHandle<Object> key = args.at(1); DirectHandle<Object> result; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, result, HasEnumerableProperty(isolate, receiver, key)); return ReadOnlyRoots(isolate).boolean_value(!IsUndefined(*result, isolate)); } } // namespace internal } // namespace v8