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_H_ 61cb0ef41Sopenharmony_ci#define V8_OBJECTS_LITERAL_OBJECTS_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/base/bit-field.h" 91cb0ef41Sopenharmony_ci#include "src/objects/fixed-array.h" 101cb0ef41Sopenharmony_ci#include "src/objects/struct.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_ciclass ClassLiteral; 191cb0ef41Sopenharmony_ciclass StructBodyDescriptor; 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/literal-objects-tq.inc" 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci// ObjectBoilerplateDescription is a list of properties consisting of name value 241cb0ef41Sopenharmony_ci// pairs. In addition to the properties, it provides the projected number 251cb0ef41Sopenharmony_ci// of properties in the backing store. This number includes properties with 261cb0ef41Sopenharmony_ci// computed names that are not 271cb0ef41Sopenharmony_ci// in the list. 281cb0ef41Sopenharmony_ci// TODO(ishell): Don't derive from FixedArray as it already has its own map. 291cb0ef41Sopenharmony_ciclass ObjectBoilerplateDescription : public FixedArray { 301cb0ef41Sopenharmony_ci public: 311cb0ef41Sopenharmony_ci inline Object name(int index) const; 321cb0ef41Sopenharmony_ci inline Object name(PtrComprCageBase cage_base, int index) const; 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci inline Object value(int index) const; 351cb0ef41Sopenharmony_ci inline Object value(PtrComprCageBase cage_base, int index) const; 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci inline void set_key_value(int index, Object key, Object value); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci // The number of boilerplate properties. 401cb0ef41Sopenharmony_ci inline int size() const; 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci // Number of boilerplate properties and properties with computed names. 431cb0ef41Sopenharmony_ci inline int backing_store_size() const; 441cb0ef41Sopenharmony_ci inline void set_backing_store_size(int backing_store_size); 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci // Used to encode ObjectLiteral::Flags for nested object literals 471cb0ef41Sopenharmony_ci // Stored as the first element of the fixed array 481cb0ef41Sopenharmony_ci DECL_INT_ACCESSORS(flags) 491cb0ef41Sopenharmony_ci static const int kLiteralTypeOffset = 0; 501cb0ef41Sopenharmony_ci static const int kDescriptionStartIndex = 1; 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci DECL_CAST(ObjectBoilerplateDescription) 531cb0ef41Sopenharmony_ci DECL_VERIFIER(ObjectBoilerplateDescription) 541cb0ef41Sopenharmony_ci DECL_PRINTER(ObjectBoilerplateDescription) 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci private: 571cb0ef41Sopenharmony_ci inline bool has_number_of_properties() const; 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci OBJECT_CONSTRUCTORS(ObjectBoilerplateDescription, FixedArray); 601cb0ef41Sopenharmony_ci}; 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ciclass ArrayBoilerplateDescription 631cb0ef41Sopenharmony_ci : public TorqueGeneratedArrayBoilerplateDescription< 641cb0ef41Sopenharmony_ci ArrayBoilerplateDescription, Struct> { 651cb0ef41Sopenharmony_ci public: 661cb0ef41Sopenharmony_ci inline ElementsKind elements_kind() const; 671cb0ef41Sopenharmony_ci inline void set_elements_kind(ElementsKind kind); 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci inline bool is_empty() const; 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ci // Dispatched behavior. 721cb0ef41Sopenharmony_ci DECL_PRINTER(ArrayBoilerplateDescription) 731cb0ef41Sopenharmony_ci void BriefPrintDetails(std::ostream& os); 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci using BodyDescriptor = StructBodyDescriptor; 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci private: 781cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(ArrayBoilerplateDescription) 791cb0ef41Sopenharmony_ci}; 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ciclass RegExpBoilerplateDescription 821cb0ef41Sopenharmony_ci : public TorqueGeneratedRegExpBoilerplateDescription< 831cb0ef41Sopenharmony_ci RegExpBoilerplateDescription, Struct> { 841cb0ef41Sopenharmony_ci public: 851cb0ef41Sopenharmony_ci // Dispatched behavior. 861cb0ef41Sopenharmony_ci void BriefPrintDetails(std::ostream& os); 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ci using BodyDescriptor = StructBodyDescriptor; 891cb0ef41Sopenharmony_ci 901cb0ef41Sopenharmony_ci private: 911cb0ef41Sopenharmony_ci TQ_OBJECT_CONSTRUCTORS(RegExpBoilerplateDescription) 921cb0ef41Sopenharmony_ci}; 931cb0ef41Sopenharmony_ci 941cb0ef41Sopenharmony_ciclass ClassBoilerplate : public FixedArray { 951cb0ef41Sopenharmony_ci public: 961cb0ef41Sopenharmony_ci enum ValueKind { kData, kGetter, kSetter }; 971cb0ef41Sopenharmony_ci 981cb0ef41Sopenharmony_ci struct ComputedEntryFlags { 991cb0ef41Sopenharmony_ci#define COMPUTED_ENTRY_BIT_FIELDS(V, _) \ 1001cb0ef41Sopenharmony_ci V(ValueKindBits, ValueKind, 2, _) \ 1011cb0ef41Sopenharmony_ci V(KeyIndexBits, unsigned, 29, _) 1021cb0ef41Sopenharmony_ci DEFINE_BIT_FIELDS(COMPUTED_ENTRY_BIT_FIELDS) 1031cb0ef41Sopenharmony_ci#undef COMPUTED_ENTRY_BIT_FIELDS 1041cb0ef41Sopenharmony_ci }; 1051cb0ef41Sopenharmony_ci 1061cb0ef41Sopenharmony_ci enum DefineClassArgumentsIndices { 1071cb0ef41Sopenharmony_ci kConstructorArgumentIndex = 1, 1081cb0ef41Sopenharmony_ci kPrototypeArgumentIndex = 2, 1091cb0ef41Sopenharmony_ci // The index of a first dynamic argument passed to Runtime::kDefineClass 1101cb0ef41Sopenharmony_ci // function. The dynamic arguments are consist of method closures and 1111cb0ef41Sopenharmony_ci // computed property names. 1121cb0ef41Sopenharmony_ci kFirstDynamicArgumentIndex = 3, 1131cb0ef41Sopenharmony_ci }; 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ci static const int kMinimumClassPropertiesCount = 6; 1161cb0ef41Sopenharmony_ci static const int kMinimumPrototypePropertiesCount = 1; 1171cb0ef41Sopenharmony_ci 1181cb0ef41Sopenharmony_ci DECL_CAST(ClassBoilerplate) 1191cb0ef41Sopenharmony_ci 1201cb0ef41Sopenharmony_ci DECL_BOOLEAN_ACCESSORS(install_class_name_accessor) 1211cb0ef41Sopenharmony_ci DECL_INT_ACCESSORS(arguments_count) 1221cb0ef41Sopenharmony_ci DECL_ACCESSORS(static_properties_template, Object) 1231cb0ef41Sopenharmony_ci DECL_ACCESSORS(static_elements_template, Object) 1241cb0ef41Sopenharmony_ci DECL_ACCESSORS(static_computed_properties, FixedArray) 1251cb0ef41Sopenharmony_ci DECL_ACCESSORS(instance_properties_template, Object) 1261cb0ef41Sopenharmony_ci DECL_ACCESSORS(instance_elements_template, Object) 1271cb0ef41Sopenharmony_ci DECL_ACCESSORS(instance_computed_properties, FixedArray) 1281cb0ef41Sopenharmony_ci 1291cb0ef41Sopenharmony_ci template <typename IsolateT, typename Dictionary> 1301cb0ef41Sopenharmony_ci static void AddToPropertiesTemplate(IsolateT* isolate, 1311cb0ef41Sopenharmony_ci Handle<Dictionary> dictionary, 1321cb0ef41Sopenharmony_ci Handle<Name> name, int key_index, 1331cb0ef41Sopenharmony_ci ValueKind value_kind, Smi value); 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_ci template <typename IsolateT> 1361cb0ef41Sopenharmony_ci static void AddToElementsTemplate(IsolateT* isolate, 1371cb0ef41Sopenharmony_ci Handle<NumberDictionary> dictionary, 1381cb0ef41Sopenharmony_ci uint32_t key, int key_index, 1391cb0ef41Sopenharmony_ci ValueKind value_kind, Smi value); 1401cb0ef41Sopenharmony_ci 1411cb0ef41Sopenharmony_ci template <typename IsolateT> 1421cb0ef41Sopenharmony_ci static Handle<ClassBoilerplate> BuildClassBoilerplate(IsolateT* isolate, 1431cb0ef41Sopenharmony_ci ClassLiteral* expr); 1441cb0ef41Sopenharmony_ci 1451cb0ef41Sopenharmony_ci enum { 1461cb0ef41Sopenharmony_ci kArgumentsCountIndex, 1471cb0ef41Sopenharmony_ci kClassPropertiesTemplateIndex, 1481cb0ef41Sopenharmony_ci kClassElementsTemplateIndex, 1491cb0ef41Sopenharmony_ci kClassComputedPropertiesIndex, 1501cb0ef41Sopenharmony_ci kPrototypePropertiesTemplateIndex, 1511cb0ef41Sopenharmony_ci kPrototypeElementsTemplateIndex, 1521cb0ef41Sopenharmony_ci kPrototypeComputedPropertiesIndex, 1531cb0ef41Sopenharmony_ci kBoilerplateLength // last element 1541cb0ef41Sopenharmony_ci }; 1551cb0ef41Sopenharmony_ci 1561cb0ef41Sopenharmony_ci private: 1571cb0ef41Sopenharmony_ci DECL_INT_ACCESSORS(flags) 1581cb0ef41Sopenharmony_ci 1591cb0ef41Sopenharmony_ci OBJECT_CONSTRUCTORS(ClassBoilerplate, FixedArray); 1601cb0ef41Sopenharmony_ci}; 1611cb0ef41Sopenharmony_ci 1621cb0ef41Sopenharmony_ci} // namespace internal 1631cb0ef41Sopenharmony_ci} // namespace v8 1641cb0ef41Sopenharmony_ci 1651cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h" 1661cb0ef41Sopenharmony_ci 1671cb0ef41Sopenharmony_ci#endif // V8_OBJECTS_LITERAL_OBJECTS_H_ 168