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 15namespace v8 { 16namespace internal { 17 18#include "torque-generated/src/objects/literal-objects-tq-inl.inc" 19 20// 21// ObjectBoilerplateDescription 22// 23 24OBJECT_CONSTRUCTORS_IMPL(ObjectBoilerplateDescription, FixedArray) 25 26CAST_ACCESSOR(ObjectBoilerplateDescription) 27 28SMI_ACCESSORS(ObjectBoilerplateDescription, flags, 29 FixedArray::OffsetOfElementAt(kLiteralTypeOffset)) 30 31Object ObjectBoilerplateDescription::name(int index) const { 32 PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 33 return name(cage_base, index); 34} 35 36Object ObjectBoilerplateDescription::name(PtrComprCageBase cage_base, 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(cage_base, 2 * index + kDescriptionStartIndex); 42} 43 44Object ObjectBoilerplateDescription::value(int index) const { 45 PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 46 return value(cage_base, index); 47} 48 49Object ObjectBoilerplateDescription::value(PtrComprCageBase cage_base, 50 int index) const { 51 return get(cage_base, 2 * index + 1 + kDescriptionStartIndex); 52} 53 54void 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 62int 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 70bool ObjectBoilerplateDescription::has_number_of_properties() const { 71 return (length() - kDescriptionStartIndex) % 2 != 0; 72} 73 74int 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 84void 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 97OBJECT_CONSTRUCTORS_IMPL(ClassBoilerplate, FixedArray) 98CAST_ACCESSOR(ClassBoilerplate) 99 100SMI_ACCESSORS(ClassBoilerplate, arguments_count, 101 FixedArray::OffsetOfElementAt(kArgumentsCountIndex)) 102 103ACCESSORS(ClassBoilerplate, static_properties_template, Object, 104 FixedArray::OffsetOfElementAt(kClassPropertiesTemplateIndex)) 105 106ACCESSORS(ClassBoilerplate, static_elements_template, Object, 107 FixedArray::OffsetOfElementAt(kClassElementsTemplateIndex)) 108 109ACCESSORS(ClassBoilerplate, static_computed_properties, FixedArray, 110 FixedArray::OffsetOfElementAt(kClassComputedPropertiesIndex)) 111 112ACCESSORS(ClassBoilerplate, instance_properties_template, Object, 113 FixedArray::OffsetOfElementAt(kPrototypePropertiesTemplateIndex)) 114 115ACCESSORS(ClassBoilerplate, instance_elements_template, Object, 116 FixedArray::OffsetOfElementAt(kPrototypeElementsTemplateIndex)) 117 118ACCESSORS(ClassBoilerplate, instance_computed_properties, FixedArray, 119 FixedArray::OffsetOfElementAt(kPrototypeComputedPropertiesIndex)) 120 121// 122// ArrayBoilerplateDescription 123// 124 125TQ_OBJECT_CONSTRUCTORS_IMPL(ArrayBoilerplateDescription) 126 127ElementsKind ArrayBoilerplateDescription::elements_kind() const { 128 return static_cast<ElementsKind>(flags()); 129} 130 131void ArrayBoilerplateDescription::set_elements_kind(ElementsKind kind) { 132 set_flags(kind); 133} 134 135bool ArrayBoilerplateDescription::is_empty() const { 136 return constant_elements().length() == 0; 137} 138 139// 140// RegExpBoilerplateDescription 141// 142 143TQ_OBJECT_CONSTRUCTORS_IMPL(RegExpBoilerplateDescription) 144 145} // namespace internal 146} // namespace v8 147 148#include "src/objects/object-macros-undef.h" 149 150#endif // V8_OBJECTS_LITERAL_OBJECTS_INL_H_ 151