18void PrepareMapCommon(Tagged<Map> map) {
19 DCHECK(IsAlwaysSharedSpaceJSObjectMap(map));
22 map->SetInObjectUnusedPropertyFields(0);
24 map->set_is_extensible(
false);
36 PrepareMapCommon(map);
37 map->SetEnumLength(0);
43 PrepareMapCommon(map);
44 map->InitializeDescriptors(isolate, *descriptors);
45 DCHECK_EQ(0, map->NumberOfEnumerableProperties());
46 map->SetEnumLength(0);
53 PrepareMapCommon(*map);
56 map->InitializeDescriptors(isolate, *descriptors);
59 DCHECK_EQ(enum_length, map->EnumLength());
83 desc->ToAttributes() != current.ToAttributes()) {
84 DCHECK(!shared_obj->map()->is_extensible());
86 NewTypeError(MessageTemplate::kDefineDisallowedFixedLayout,
89 DCHECK(it.property_attributes() == desc->ToAttributes());
90 if (desc->has_value()) {
99 if (!constructor->has_prototype_slot() || !constructor->has_initial_map() ||
100 !IsJSReceiver(*
object)) {
122constexpr int kSpecialSlots = 2;
126 DCHECK(IsJSSharedStructMap(instance_map));
130 int end = std::min(
static_cast<int>(descriptors->number_of_all_descriptors()),
132 for (
int i = 0;
i <
end; ++
i) {
134 if (descriptors->GetKey(idx) == special_slot_name) {
136 descriptors->GetDetails(idx).location());
144MaybeHandle<T> GetSpecialSlotValue(Isolate* isolate, Tagged<Map> instance_map,
148 InternalIndex entry = GetSpecialSlotIndex(instance_map, special_slot_name);
149 if (entry.is_found()) {
152 ReadOnlyRoots(isolate).shared_struct_map_registry_key_symbol(),
153 entry.as_int() == 0);
155 handle(
Cast<T>(instance_map->instance_descriptors()->GetStrongValue(
167 const std::set<uint32_t>& element_names,
169 auto* factory = isolate->factory();
172 int num_elements = 0;
174 int num_descriptors =
static_cast<int>(field_names.size());
177 if (!element_names.empty()) num_descriptors++;
181 if (!maybe_registry_key.
is_null()) num_descriptors++;
185 if (num_descriptors != 0) {
186 descriptors = factory->NewDescriptorArray(num_descriptors, 0,
189 int special_slots = 0;
194 if (maybe_registry_key.
ToHandle(®istry_key)) {
196 factory->shared_struct_map_registry_key_symbol(), registry_key,
204 if (!element_names.empty()) {
206 num_elements =
static_cast<int>(element_names.size());
207 elements_template = NumberDictionary::New(isolate, num_elements,
209 for (uint32_t index : element_names) {
215 isolate->factory()->undefined_value(), details);
217 elements_template->SetInitialNumberOfElements(num_elements);
221 factory->shared_struct_map_elements_template_symbol(),
233 descriptors->Set(
InternalIndex(special_slots + num_fields), *field_name,
243 int in_object_properties;
245 num_fields, &instance_size,
246 &in_object_properties);
252 if (num_descriptors == 0) {
256 }
else if (num_fields == 0) {
259 isolate, *instance_map, *descriptors);
263 isolate, instance_map, descriptors, num_fields);
267 int out_of_object_properties = num_fields - in_object_properties;
268 if (out_of_object_properties != 0) {
269 instance_map->SetOutOfObjectUnusedPropertyFields(0);
278 return GetSpecialSlotValue<String>(
279 isolate, *instance_map,
280 ReadOnlyRoots(isolate).shared_struct_map_registry_key_symbol());
287 DCHECK(IsJSSharedStructMap(instance_map));
288 return instance_map->instance_descriptors(isolate)->GetKey(
i) ==
289 ReadOnlyRoots(isolate).shared_struct_map_registry_key_symbol();
295 return GetSpecialSlotValue<NumberDictionary>(
296 isolate, instance_map,
297 ReadOnlyRoots(isolate).shared_struct_map_elements_template_symbol());
304 DCHECK(IsJSSharedStructMap(instance_map));
305 return instance_map->instance_descriptors(isolate)->GetKey(
i) ==
306 ReadOnlyRoots(isolate).shared_struct_map_elements_template_symbol();
327 template <
typename IsolateT>
334 DCHECK(IsInternalizedString(*existing));
335 return *
key == *existing;
354 static std::unique_ptr<Data>
New(
int capacity) {
355 return std::unique_ptr<Data>(
new (capacity)
Data(capacity));
365 void*
operator new(
size_t size) =
delete;
380 const std::set<uint32_t>& element_names) {
392 int num_descriptors =
static_cast<int>(field_names.size()) + 1;
393 if (!element_names.empty()) {
400 if (num_descriptors != existing_map->NumberOfOwnDescriptors()) {
405 existing_map->instance_descriptors(isolate);
406 auto field_names_iter = field_names.begin();
412 existing_map->instance_descriptors()->GetStrongValue(isolate,
i)),
414 if (
static_cast<int>(element_names.size()) !=
415 elements_template->NumberOfElements()) {
418 for (
int element : element_names) {
419 if (elements_template->FindEntry(isolate, element).is_not_found()) {
431 Tagged<Name> existing_name = existing_descriptors->GetKey(
i);
445 const std::set<uint32_t>& element_names) {
446 key = isolate->factory()->InternalizeString(
key);
462 isolate, field_names, element_names,
key);
469 data_->FindEntryOrInsertionEntry(isolate,
key,
key->hash());
472 data_->AddAt(isolate, entry, *map);
475 data_->OverwriteDeletedAt(isolate, entry, *map);
486 const std::set<uint32_t>& element_names) {
492 NewTypeError(MessageTemplate::kSharedStructTypeRegistryMismatch,
key));
494 return canonical_map;
508 data_->IterateElements(Root::kSharedStructTypeRegistry, visitor);
516 int additional_elements) {
520 if (
data_->ShouldResizeToAdd(additional_elements, &new_capacity)) {
521 std::unique_ptr<Data> new_data(
Data::New(new_capacity));
522 data_->RehashInto(cage_base, new_data.get());
523 data_ = std::move(new_data);
uint8_t data_[MAX_STACK_LENGTH]
V8_INLINE void AssertHeld() const
static void PrepareMapNoEnumerableProperties(Tagged< Map > map)
static void PrepareMapWithEnumerableProperties(Isolate *isolate, DirectHandle< Map > map, DirectHandle< DescriptorArray > descriptors, int enum_length)
static V8_WARN_UNUSED_RESULT Maybe< bool > DefineOwnProperty(Isolate *isolate, DirectHandle< AlwaysSharedSpaceJSObject > shared_obj, DirectHandle< Object > key, PropertyDescriptor *desc, Maybe< ShouldThrow > should_throw)
static Maybe< bool > HasInstance(Isolate *isolate, DirectHandle< JSFunction > constructor, DirectHandle< Object > object)
static Descriptor DataConstant(DirectHandle< Name > key, DirectHandle< Object > value, PropertyAttributes attributes)
V8_INLINE bool is_identical_to(Handle< S > other) const
static Handle< FixedArray > InitializeFastPropertyEnumCache(Isolate *isolate, DirectHandle< Map > map, int enum_length, AllocationType allocation=AllocationType::kOld)
static V8_EXPORT_PRIVATE Tagged< FieldType > Any()
Tagged< Object > load() const
void store(Tagged< Object > value) const
static V8_INLINE bool InAnySharedSpace(Tagged< HeapObject > object)
static InternalIndex NotFound()
static void CalculateInstanceSizeHelper(InstanceType instance_type, bool has_prototype_slot, int requested_embedder_fields, int requested_in_object_properties, int *instance_size, int *in_object_properties)
static bool IsRegistryKeyDescriptor(Isolate *isolate, Tagged< Map > instance_map, InternalIndex i)
static MaybeHandle< String > GetRegistryKey(Isolate *isolate, Tagged< Map > instance_map)
static MaybeDirectHandle< NumberDictionary > GetElementsTemplate(Isolate *isolate, Tagged< Map > instance_map)
static DirectHandle< Map > CreateInstanceMap(Isolate *isolate, const base::Vector< const DirectHandle< Name > > field_names, const std::set< uint32_t > &element_names, MaybeDirectHandle< String > maybe_registry_key)
static bool IsElementsTemplateDescriptor(Isolate *isolate, Tagged< Map > instance_map, InternalIndex i)
static constexpr Tagged< Smi > kPrototypeChainValidSmi
V8_WARN_UNUSED_RESULT V8_INLINE bool ToHandle(DirectHandle< S > *out) const
V8_INLINE bool is_null() const
static V8_WARN_UNUSED_RESULT Maybe< bool > SetDataProperty(LookupIterator *it, DirectHandle< Object > value)
static constexpr Tagged< Smi > deleted_element()
static void Free(void *container)
OffHeapObjectSlot slot(InternalIndex index, int offset=0) const
static constexpr Tagged< Smi > empty_element()
static bool IsDataDescriptor(PropertyDescriptor *desc)
V8_WARN_UNUSED_RESULT bool AdvanceFollowingProxies()
Tagged< T > GetCurrent() const
static constexpr Representation Tagged()
Tagged< Object > GetKey(PtrComprCageBase cage_base, InternalIndex index) const
void CopyEntryExcludingKeyInto(PtrComprCageBase cage_base, InternalIndex from_index, Data *to, InternalIndex to_index)
static constexpr int kEntrySize
static constexpr int kMinCapacity
void SetKey(InternalIndex index, Tagged< Object > key)
static constexpr int kMaxEmptyFactor
static std::unique_ptr< Data > New(int capacity)
static uint32_t Hash(PtrComprCageBase cage_base, Tagged< Object > key)
static bool KeyIsMatch(IsolateT *isolate, DirectHandle< String > key, Tagged< Object > obj)
void Set(InternalIndex index, Tagged< Map > map)
SharedStructTypeRegistry()
~SharedStructTypeRegistry()
MaybeDirectHandle< Map > RegisterNoThrow(Isolate *isolate, Handle< String > key, const base::Vector< const DirectHandle< Name > > field_names, const std::set< uint32_t > &element_names)
std::unique_ptr< Data > data_
void IterateElements(Isolate *isolate, RootVisitor *visitor)
MaybeDirectHandle< Map > Register(Isolate *isolate, Handle< String > key, const base::Vector< const DirectHandle< Name > > field_names, const std::set< uint32_t > &element_names)
void EnsureCapacity(PtrComprCageBase cage_base, int additional_elements)
MaybeDirectHandle< Map > CheckIfEntryMatches(Isolate *isolate, InternalIndex entry, DirectHandle< String > key, const base::Vector< const DirectHandle< Name > > field_names, const std::set< uint32_t > &element_names)
static constexpr Tagged< Smi > deleted_element()
void NotifyElementsRemoved(int count)
#define RETURN_FAILURE(isolate, should_throw, call)
#define THROW_NEW_ERROR(isolate, call)
#define MAYBE_RETURN(call, value)
ZoneVector< RpoNumber > & result
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
PerThreadAssertScopeDebugOnly< false, SAFEPOINTS_ASSERT, HEAP_ALLOCATION_ASSERT > DisallowGarbageCollection
bool IsNumber(Tagged< Object > obj)
Tagged(T object) -> Tagged< T >
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
return Cast< NumberDictionary >(elements(cage_base))
ShouldThrow GetShouldThrow(Isolate *isolate, Maybe< ShouldThrow > should_throw)
bool IsUniqueName(Tagged< Name > obj)
bool IsPrivateSymbol(Tagged< Object > obj)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
static constexpr RelaxedStoreTag kRelaxedStore
Maybe< T > Just(const T &t)
#define DCHECK_LE(v1, v2)
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK_GE(v1, v2)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)