1// Copyright 2018 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_OBJECTS_PROTOTYPE_INFO_INL_H_
6#define V8_OBJECTS_PROTOTYPE_INFO_INL_H_
7
8#include "src/objects/prototype-info.h"
9
10#include "src/heap/heap-write-barrier-inl.h"
11#include "src/objects-inl.h"
12#include "src/objects/fixed-array-inl.h"
13#include "src/objects/map-inl.h"
14#include "src/objects/maybe-object.h"
15#include "src/objects/struct-inl.h"
16
17// Has to be the last include (doesn't have include guards):
18#include "src/objects/object-macros.h"
19
20namespace v8 {
21namespace internal {
22
23OBJECT_CONSTRUCTORS_IMPL(PrototypeInfo, Struct)
24
25CAST_ACCESSOR(PrototypeInfo)
26
27Map PrototypeInfo::ObjectCreateMap() {
28 return Map::cast(object_create_map()->GetHeapObjectAssumeWeak());
29}
30
31// static
32void PrototypeInfo::SetObjectCreateMap(Handle<PrototypeInfo> info,
33 Handle<Map> map) {
34 info->set_object_create_map(HeapObjectReference::Weak(*map));
35}
36
37bool PrototypeInfo::HasObjectCreateMap() {
38 MaybeObject cache = object_create_map();
39 return cache->IsWeak();
40}
41
42ACCESSORS(PrototypeInfo, module_namespace, Object, kJsModuleNamespaceOffset)
43ACCESSORS(PrototypeInfo, prototype_users, Object, kPrototypeUsersOffset)
44WEAK_ACCESSORS(PrototypeInfo, object_create_map, kObjectCreateMapOffset)
45SMI_ACCESSORS(PrototypeInfo, registry_slot, kRegistrySlotOffset)
46SMI_ACCESSORS(PrototypeInfo, bit_field, kBitFieldOffset)
47BOOL_ACCESSORS(PrototypeInfo, bit_field, should_be_fast_map, kShouldBeFastBit)
48
49void PrototypeUsers::MarkSlotEmpty(WeakArrayList array, int index) {
50 DCHECK_GT(index, 0);
51 DCHECK_LT(index, array->length());
52 // Chain the empty slots into a linked list (each empty slot contains the
53 // index of the next empty slot).
54 array->Set(index, MaybeObject::FromObject(empty_slot_index(array)));
55 set_empty_slot_index(array, index);
56}
57
58Smi PrototypeUsers::empty_slot_index(WeakArrayList array) {
59 return array->Get(kEmptySlotIndex).ToSmi();
60}
61
62void PrototypeUsers::set_empty_slot_index(WeakArrayList array, int index) {
63 array->Set(kEmptySlotIndex, MaybeObject::FromObject(Smi::FromInt(index)));
64}
65
66} // namespace internal
67} // namespace v8
68
69#include "src/objects/object-macros-undef.h"
70
71#endif // V8_OBJECTS_PROTOTYPE_INFO_INL_H_
72