11cb0ef41Sopenharmony_ci// Copyright 2017 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_OBJECTS_LITERAL_OBJECTS_INL_H_ 61cb0ef41Sopenharmony_ci#define V8_OBJECTS_LITERAL_OBJECTS_INL_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/objects/literal-objects.h" 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci#include "src/objects/objects-inl.h" 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards): 131cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h" 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cinamespace v8 { 161cb0ef41Sopenharmony_cinamespace internal { 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/literal-objects-tq-inl.inc" 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci// 211cb0ef41Sopenharmony_ci// ObjectBoilerplateDescription 221cb0ef41Sopenharmony_ci// 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciOBJECT_CONSTRUCTORS_IMPL(ObjectBoilerplateDescription, FixedArray) 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ciCAST_ACCESSOR(ObjectBoilerplateDescription) 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ciSMI_ACCESSORS(ObjectBoilerplateDescription, flags, 291cb0ef41Sopenharmony_ci FixedArray::OffsetOfElementAt(kLiteralTypeOffset)) 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ciObject ObjectBoilerplateDescription::name(int index) const { 321cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 331cb0ef41Sopenharmony_ci return name(cage_base, index); 341cb0ef41Sopenharmony_ci} 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ciObject ObjectBoilerplateDescription::name(PtrComprCageBase cage_base, 371cb0ef41Sopenharmony_ci int index) const { 381cb0ef41Sopenharmony_ci // get() already checks for out of bounds access, but we do not want to allow 391cb0ef41Sopenharmony_ci // access to the last element, if it is the number of properties. 401cb0ef41Sopenharmony_ci DCHECK_NE(size(), index); 411cb0ef41Sopenharmony_ci return get(cage_base, 2 * index + kDescriptionStartIndex); 421cb0ef41Sopenharmony_ci} 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ciObject ObjectBoilerplateDescription::value(int index) const { 451cb0ef41Sopenharmony_ci PtrComprCageBase cage_base = GetPtrComprCageBase(*this); 461cb0ef41Sopenharmony_ci return value(cage_base, index); 471cb0ef41Sopenharmony_ci} 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ciObject ObjectBoilerplateDescription::value(PtrComprCageBase cage_base, 501cb0ef41Sopenharmony_ci int index) const { 511cb0ef41Sopenharmony_ci return get(cage_base, 2 * index + 1 + kDescriptionStartIndex); 521cb0ef41Sopenharmony_ci} 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_civoid ObjectBoilerplateDescription::set_key_value(int index, Object key, 551cb0ef41Sopenharmony_ci Object value) { 561cb0ef41Sopenharmony_ci DCHECK_LT(index, size()); 571cb0ef41Sopenharmony_ci DCHECK_GE(index, 0); 581cb0ef41Sopenharmony_ci set(2 * index + kDescriptionStartIndex, key); 591cb0ef41Sopenharmony_ci set(2 * index + 1 + kDescriptionStartIndex, value); 601cb0ef41Sopenharmony_ci} 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ciint ObjectBoilerplateDescription::size() const { 631cb0ef41Sopenharmony_ci DCHECK_EQ(0, (length() - kDescriptionStartIndex - 641cb0ef41Sopenharmony_ci (this->has_number_of_properties() ? 1 : 0)) % 651cb0ef41Sopenharmony_ci 2); 661cb0ef41Sopenharmony_ci // Rounding is intended. 671cb0ef41Sopenharmony_ci return (length() - kDescriptionStartIndex) / 2; 681cb0ef41Sopenharmony_ci} 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_cibool ObjectBoilerplateDescription::has_number_of_properties() const { 711cb0ef41Sopenharmony_ci return (length() - kDescriptionStartIndex) % 2 != 0; 721cb0ef41Sopenharmony_ci} 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ciint ObjectBoilerplateDescription::backing_store_size() const { 751cb0ef41Sopenharmony_ci if (has_number_of_properties()) { 761cb0ef41Sopenharmony_ci // If present, the last entry contains the number of properties. 771cb0ef41Sopenharmony_ci return Smi::ToInt(this->get(length() - 1)); 781cb0ef41Sopenharmony_ci } 791cb0ef41Sopenharmony_ci // If the number is not given explicitly, we assume there are no 801cb0ef41Sopenharmony_ci // properties with computed names. 811cb0ef41Sopenharmony_ci return size(); 821cb0ef41Sopenharmony_ci} 831cb0ef41Sopenharmony_ci 841cb0ef41Sopenharmony_civoid ObjectBoilerplateDescription::set_backing_store_size( 851cb0ef41Sopenharmony_ci int backing_store_size) { 861cb0ef41Sopenharmony_ci DCHECK(has_number_of_properties()); 871cb0ef41Sopenharmony_ci DCHECK_NE(size(), backing_store_size); 881cb0ef41Sopenharmony_ci CHECK(Smi::IsValid(backing_store_size)); 891cb0ef41Sopenharmony_ci // TODO(ishell): move this value to the header 901cb0ef41Sopenharmony_ci set(length() - 1, Smi::FromInt(backing_store_size)); 911cb0ef41Sopenharmony_ci} 921cb0ef41Sopenharmony_ci 931cb0ef41Sopenharmony_ci// 941cb0ef41Sopenharmony_ci// ClassBoilerplate 951cb0ef41Sopenharmony_ci// 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ciOBJECT_CONSTRUCTORS_IMPL(ClassBoilerplate, FixedArray) 981cb0ef41Sopenharmony_ciCAST_ACCESSOR(ClassBoilerplate) 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ciSMI_ACCESSORS(ClassBoilerplate, arguments_count, 1011cb0ef41Sopenharmony_ci FixedArray::OffsetOfElementAt(kArgumentsCountIndex)) 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ciACCESSORS(ClassBoilerplate, static_properties_template, Object, 1041cb0ef41Sopenharmony_ci FixedArray::OffsetOfElementAt(kClassPropertiesTemplateIndex)) 1051cb0ef41Sopenharmony_ci 1061cb0ef41Sopenharmony_ciACCESSORS(ClassBoilerplate, static_elements_template, Object, 1071cb0ef41Sopenharmony_ci FixedArray::OffsetOfElementAt(kClassElementsTemplateIndex)) 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_ciACCESSORS(ClassBoilerplate, static_computed_properties, FixedArray, 1101cb0ef41Sopenharmony_ci FixedArray::OffsetOfElementAt(kClassComputedPropertiesIndex)) 1111cb0ef41Sopenharmony_ci 1121cb0ef41Sopenharmony_ciACCESSORS(ClassBoilerplate, instance_properties_template, Object, 1131cb0ef41Sopenharmony_ci FixedArray::OffsetOfElementAt(kPrototypePropertiesTemplateIndex)) 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ciACCESSORS(ClassBoilerplate, instance_elements_template, Object, 1161cb0ef41Sopenharmony_ci FixedArray::OffsetOfElementAt(kPrototypeElementsTemplateIndex)) 1171cb0ef41Sopenharmony_ci 1181cb0ef41Sopenharmony_ciACCESSORS(ClassBoilerplate, instance_computed_properties, FixedArray, 1191cb0ef41Sopenharmony_ci FixedArray::OffsetOfElementAt(kPrototypeComputedPropertiesIndex)) 1201cb0ef41Sopenharmony_ci 1211cb0ef41Sopenharmony_ci// 1221cb0ef41Sopenharmony_ci// ArrayBoilerplateDescription 1231cb0ef41Sopenharmony_ci// 1241cb0ef41Sopenharmony_ci 1251cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(ArrayBoilerplateDescription) 1261cb0ef41Sopenharmony_ci 1271cb0ef41Sopenharmony_ciElementsKind ArrayBoilerplateDescription::elements_kind() const { 1281cb0ef41Sopenharmony_ci return static_cast<ElementsKind>(flags()); 1291cb0ef41Sopenharmony_ci} 1301cb0ef41Sopenharmony_ci 1311cb0ef41Sopenharmony_civoid ArrayBoilerplateDescription::set_elements_kind(ElementsKind kind) { 1321cb0ef41Sopenharmony_ci set_flags(kind); 1331cb0ef41Sopenharmony_ci} 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_cibool ArrayBoilerplateDescription::is_empty() const { 1361cb0ef41Sopenharmony_ci return constant_elements().length() == 0; 1371cb0ef41Sopenharmony_ci} 1381cb0ef41Sopenharmony_ci 1391cb0ef41Sopenharmony_ci// 1401cb0ef41Sopenharmony_ci// RegExpBoilerplateDescription 1411cb0ef41Sopenharmony_ci// 1421cb0ef41Sopenharmony_ci 1431cb0ef41Sopenharmony_ciTQ_OBJECT_CONSTRUCTORS_IMPL(RegExpBoilerplateDescription) 1441cb0ef41Sopenharmony_ci 1451cb0ef41Sopenharmony_ci} // namespace internal 1461cb0ef41Sopenharmony_ci} // namespace v8 1471cb0ef41Sopenharmony_ci 1481cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h" 1491cb0ef41Sopenharmony_ci 1501cb0ef41Sopenharmony_ci#endif // V8_OBJECTS_LITERAL_OBJECTS_INL_H_ 151