#include "src/objects/keys.h"
#include <optional>
#include "src/api/api-arguments-inl.h"
#include "src/api/api.h"
#include "src/common/assert-scope.h"
#include "src/common/globals.h"
#include "src/execution/isolate-inl.h"
#include "src/handles/handles-inl.h"
#include "src/heap/factory.h"
#include "src/objects/api-callbacks.h"
#include "src/objects/elements-inl.h"
#include "src/objects/field-index-inl.h"
#include "src/objects/hash-table-inl.h"
#include "src/objects/module-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/ordered-hash-table-inl.h"
#include "src/objects/property-descriptor.h"
#include "src/objects/prototype-info.h"
#include "src/objects/prototype.h"
#include "src/objects/slots-atomic-inl.h"
#include "src/utils/identity-map.h"
#include "src/zone/zone-hashmap.h"
namespace v8::internal {
#define RETURN_NOTHING_IF_NOT_SUCCESSFUL …
#define RETURN_FAILURE_IF_NOT_SUCCESSFUL …
namespace {
static bool ContainsOnlyValidKeys(DirectHandle<FixedArray> array) { … }
static int AddKey(Tagged<Object> key, DirectHandle<FixedArray> combined_keys,
DirectHandle<DescriptorArray> descs, int nof_descriptors,
int target) { … }
static Handle<FixedArray> CombineKeys(Isolate* isolate,
Handle<FixedArray> own_keys,
Handle<FixedArray> prototype_chain_keys,
DirectHandle<JSReceiver> receiver,
bool may_have_elements) { … }
}
MaybeHandle<FixedArray> KeyAccumulator::GetKeys(
Isolate* isolate, Handle<JSReceiver> object, KeyCollectionMode mode,
PropertyFilter filter, GetKeysConversion keys_conversion, bool is_for_in,
bool skip_indices) { … }
Handle<FixedArray> KeyAccumulator::GetKeys(GetKeysConversion convert) { … }
Handle<OrderedHashSet> KeyAccumulator::keys() { … }
ExceptionStatus KeyAccumulator::AddKey(Tagged<Object> key,
AddKeyConversion convert) { … }
ExceptionStatus KeyAccumulator::AddKey(Handle<Object> key,
AddKeyConversion convert) { … }
ExceptionStatus KeyAccumulator::AddKeys(DirectHandle<FixedArray> array,
AddKeyConversion convert) { … }
ExceptionStatus KeyAccumulator::AddKeys(Handle<JSObject> array_like,
AddKeyConversion convert) { … }
MaybeHandle<FixedArray> FilterProxyKeys(KeyAccumulator* accumulator,
DirectHandle<JSProxy> owner,
Handle<FixedArray> keys,
PropertyFilter filter,
bool skip_indices) { … }
Maybe<bool> KeyAccumulator::AddKeysFromJSProxy(DirectHandle<JSProxy> proxy,
Handle<FixedArray> keys) { … }
Maybe<bool> KeyAccumulator::CollectKeys(DirectHandle<JSReceiver> receiver,
Handle<JSReceiver> object) { … }
bool KeyAccumulator::HasShadowingKeys() { … }
bool KeyAccumulator::IsShadowed(Handle<Object> key) { … }
void KeyAccumulator::AddShadowingKey(Tagged<Object> key,
AllowGarbageCollection* allow_gc) { … }
void KeyAccumulator::AddShadowingKey(Handle<Object> key) { … }
namespace {
void TrySettingEmptyEnumCache(Tagged<JSReceiver> object) { … }
bool CheckAndInitializeEmptyEnumCache(Tagged<JSReceiver> object) { … }
}
void FastKeyAccumulator::Prepare() { … }
namespace {
Handle<FixedArray> ReduceFixedArrayTo(Isolate* isolate,
Handle<FixedArray> array, int length) { … }
Handle<FixedArray> GetFastEnumPropertyKeys(Isolate* isolate,
DirectHandle<JSObject> object) { … }
template <bool fast_properties>
MaybeHandle<FixedArray> GetOwnKeysWithElements(Isolate* isolate,
Handle<JSObject> object,
GetKeysConversion convert,
bool skip_indices) { … }
}
MaybeHandle<FixedArray> FastKeyAccumulator::GetKeys(
GetKeysConversion keys_conversion) { … }
MaybeHandle<FixedArray> FastKeyAccumulator::GetKeysFast(
GetKeysConversion keys_conversion) { … }
Handle<FixedArray> FastKeyAccumulator::InitializeFastPropertyEnumCache(
Isolate* isolate, DirectHandle<Map> map, int enum_length,
AllocationType allocation) { … }
MaybeHandle<FixedArray>
FastKeyAccumulator::GetOwnKeysWithUninitializedEnumLength() { … }
MaybeHandle<FixedArray> FastKeyAccumulator::GetKeysSlow(
GetKeysConversion keys_conversion) { … }
MaybeHandle<FixedArray> FastKeyAccumulator::GetKeysWithPrototypeInfoCache(
GetKeysConversion keys_conversion) { … }
bool FastKeyAccumulator::MayHaveElements(Tagged<JSReceiver> receiver) { … }
bool FastKeyAccumulator::TryPrototypeInfoCache(Handle<JSReceiver> receiver) { … }
V8_WARN_UNUSED_RESULT ExceptionStatus
KeyAccumulator::FilterForEnumerableProperties(
DirectHandle<JSReceiver> receiver, DirectHandle<JSObject> object,
Handle<InterceptorInfo> interceptor, Handle<JSObject> result,
IndexedOrNamed type) { … }
Maybe<bool> KeyAccumulator::CollectInterceptorKeysInternal(
DirectHandle<JSReceiver> receiver, DirectHandle<JSObject> object,
Handle<InterceptorInfo> interceptor, IndexedOrNamed type) { … }
Maybe<bool> KeyAccumulator::CollectInterceptorKeys(
DirectHandle<JSReceiver> receiver, DirectHandle<JSObject> object,
IndexedOrNamed type) { … }
Maybe<bool> KeyAccumulator::CollectOwnElementIndices(
DirectHandle<JSReceiver> receiver, Handle<JSObject> object) { … }
namespace {
template <bool skip_symbols>
std::optional<int> CollectOwnPropertyNamesInternal(
DirectHandle<JSObject> object, KeyAccumulator* keys,
DirectHandle<DescriptorArray> descs, int start_index, int limit) { … }
template <typename Dictionary>
void CommonCopyEnumKeysTo(Isolate* isolate, Handle<Dictionary> dictionary,
DirectHandle<FixedArray> storage,
KeyCollectionMode mode, KeyAccumulator* accumulator) { … }
template <typename Dictionary>
void CopyEnumKeysTo(Isolate* isolate, Handle<Dictionary> dictionary,
Handle<FixedArray> storage, KeyCollectionMode mode,
KeyAccumulator* accumulator) { … }
template <>
void CopyEnumKeysTo(Isolate* isolate, Handle<SwissNameDictionary> dictionary,
Handle<FixedArray> storage, KeyCollectionMode mode,
KeyAccumulator* accumulator) { … }
template <class T>
Handle<FixedArray> GetOwnEnumPropertyDictionaryKeys(
Isolate* isolate, KeyCollectionMode mode, KeyAccumulator* accumulator,
DirectHandle<JSObject> object, Tagged<T> raw_dictionary) { … }
template <typename Dictionary>
ExceptionStatus CollectKeysFromDictionary(Handle<Dictionary> dictionary,
KeyAccumulator* keys) { … }
}
Maybe<bool> KeyAccumulator::CollectOwnPropertyNames(
DirectHandle<JSReceiver> receiver, Handle<JSObject> object) { … }
ExceptionStatus KeyAccumulator::CollectPrivateNames(
DirectHandle<JSReceiver> receiver, DirectHandle<JSObject> object) { … }
Maybe<bool> KeyAccumulator::CollectAccessCheckInterceptorKeys(
DirectHandle<AccessCheckInfo> access_check_info,
DirectHandle<JSReceiver> receiver, DirectHandle<JSObject> object) { … }
Maybe<bool> KeyAccumulator::CollectOwnKeys(DirectHandle<JSReceiver> receiver,
Handle<JSObject> object) { … }
Handle<FixedArray> KeyAccumulator::GetOwnEnumPropertyKeys(
Isolate* isolate, DirectHandle<JSObject> object) { … }
namespace {
class NameComparator { … };
}
Maybe<bool> KeyAccumulator::CollectOwnJSProxyKeys(
DirectHandle<JSReceiver> receiver, DirectHandle<JSProxy> proxy) { … }
Maybe<bool> KeyAccumulator::CollectOwnJSProxyTargetKeys(
DirectHandle<JSProxy> proxy, Handle<JSReceiver> target) { … }
#undef RETURN_NOTHING_IF_NOT_SUCCESSFUL
#undef RETURN_FAILURE_IF_NOT_SUCCESSFUL
}