• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  // Copyright 2017 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_LITERAL_OBJECTS_INL_H_
6  #define V8_OBJECTS_LITERAL_OBJECTS_INL_H_
7  
8  #include "src/objects/literal-objects.h"
9  
10  #include "src/objects/objects-inl.h"
11  
12  // Has to be the last include (doesn't have include guards):
13  #include "src/objects/object-macros.h"
14  
15  namespace v8 {
16  namespace internal {
17  
18  #include "torque-generated/src/objects/literal-objects-tq-inl.inc"
19  
20  //
21  // ObjectBoilerplateDescription
22  //
23  
OBJECT_CONSTRUCTORS_IMPL(ObjectBoilerplateDescription,FixedArray)24  OBJECT_CONSTRUCTORS_IMPL(ObjectBoilerplateDescription, FixedArray)
25  
26  CAST_ACCESSOR(ObjectBoilerplateDescription)
27  
28  SMI_ACCESSORS(ObjectBoilerplateDescription, flags,
29                FixedArray::OffsetOfElementAt(kLiteralTypeOffset))
30  
31  Object ObjectBoilerplateDescription::name(int index) const {
32    IsolateRoot isolate = GetIsolateForPtrCompr(*this);
33    return name(isolate, index);
34  }
35  
name(IsolateRoot isolate,int index)36  Object ObjectBoilerplateDescription::name(IsolateRoot isolate,
37                                            int index) const {
38    // get() already checks for out of bounds access, but we do not want to allow
39    // access to the last element, if it is the number of properties.
40    DCHECK_NE(size(), index);
41    return get(isolate, 2 * index + kDescriptionStartIndex);
42  }
43  
value(int index)44  Object ObjectBoilerplateDescription::value(int index) const {
45    IsolateRoot isolate = GetIsolateForPtrCompr(*this);
46    return value(isolate, index);
47  }
48  
value(IsolateRoot isolate,int index)49  Object ObjectBoilerplateDescription::value(IsolateRoot isolate,
50                                             int index) const {
51    return get(isolate, 2 * index + 1 + kDescriptionStartIndex);
52  }
53  
set_key_value(int index,Object key,Object value)54  void ObjectBoilerplateDescription::set_key_value(int index, Object key,
55                                                   Object value) {
56    DCHECK_LT(index, size());
57    DCHECK_GE(index, 0);
58    set(2 * index + kDescriptionStartIndex, key);
59    set(2 * index + 1 + kDescriptionStartIndex, value);
60  }
61  
size()62  int ObjectBoilerplateDescription::size() const {
63    DCHECK_EQ(0, (length() - kDescriptionStartIndex -
64                  (this->has_number_of_properties() ? 1 : 0)) %
65                     2);
66    // Rounding is intended.
67    return (length() - kDescriptionStartIndex) / 2;
68  }
69  
has_number_of_properties()70  bool ObjectBoilerplateDescription::has_number_of_properties() const {
71    return (length() - kDescriptionStartIndex) % 2 != 0;
72  }
73  
backing_store_size()74  int ObjectBoilerplateDescription::backing_store_size() const {
75    if (has_number_of_properties()) {
76      // If present, the last entry contains the number of properties.
77      return Smi::ToInt(this->get(length() - 1));
78    }
79    // If the number is not given explicitly, we assume there are no
80    // properties with computed names.
81    return size();
82  }
83  
set_backing_store_size(int backing_store_size)84  void ObjectBoilerplateDescription::set_backing_store_size(
85      int backing_store_size) {
86    DCHECK(has_number_of_properties());
87    DCHECK_NE(size(), backing_store_size);
88    CHECK(Smi::IsValid(backing_store_size));
89    // TODO(ishell): move this value to the header
90    set(length() - 1, Smi::FromInt(backing_store_size));
91  }
92  
93  //
94  // ClassBoilerplate
95  //
96  
OBJECT_CONSTRUCTORS_IMPL(ClassBoilerplate,FixedArray)97  OBJECT_CONSTRUCTORS_IMPL(ClassBoilerplate, FixedArray)
98  CAST_ACCESSOR(ClassBoilerplate)
99  
100  SMI_ACCESSORS(ClassBoilerplate, arguments_count,
101                FixedArray::OffsetOfElementAt(kArgumentsCountIndex))
102  
103  ACCESSORS(ClassBoilerplate, static_properties_template, Object,
104            FixedArray::OffsetOfElementAt(kClassPropertiesTemplateIndex))
105  
106  ACCESSORS(ClassBoilerplate, static_elements_template, Object,
107            FixedArray::OffsetOfElementAt(kClassElementsTemplateIndex))
108  
109  ACCESSORS(ClassBoilerplate, static_computed_properties, FixedArray,
110            FixedArray::OffsetOfElementAt(kClassComputedPropertiesIndex))
111  
112  ACCESSORS(ClassBoilerplate, instance_properties_template, Object,
113            FixedArray::OffsetOfElementAt(kPrototypePropertiesTemplateIndex))
114  
115  ACCESSORS(ClassBoilerplate, instance_elements_template, Object,
116            FixedArray::OffsetOfElementAt(kPrototypeElementsTemplateIndex))
117  
118  ACCESSORS(ClassBoilerplate, instance_computed_properties, FixedArray,
119            FixedArray::OffsetOfElementAt(kPrototypeComputedPropertiesIndex))
120  
121  //
122  // ArrayBoilerplateDescription
123  //
124  
125  TQ_OBJECT_CONSTRUCTORS_IMPL(ArrayBoilerplateDescription)
126  
127  ElementsKind ArrayBoilerplateDescription::elements_kind() const {
128    return static_cast<ElementsKind>(flags());
129  }
130  
set_elements_kind(ElementsKind kind)131  void ArrayBoilerplateDescription::set_elements_kind(ElementsKind kind) {
132    set_flags(kind);
133  }
134  
is_empty()135  bool ArrayBoilerplateDescription::is_empty() const {
136    return constant_elements().length() == 0;
137  }
138  
139  }  // namespace internal
140  }  // namespace v8
141  
142  #include "src/objects/object-macros-undef.h"
143  
144  #endif  // V8_OBJECTS_LITERAL_OBJECTS_INL_H_
145