• 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_H_
6 #define V8_OBJECTS_LITERAL_OBJECTS_H_
7 
8 #include "src/base/bit-field.h"
9 #include "src/objects/fixed-array.h"
10 #include "src/objects/struct.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 class ClassLiteral;
19 class StructBodyDescriptor;
20 
21 #include "torque-generated/src/objects/literal-objects-tq.inc"
22 
23 // ObjectBoilerplateDescription is a list of properties consisting of name value
24 // pairs. In addition to the properties, it provides the projected number
25 // of properties in the backing store. This number includes properties with
26 // computed names that are not
27 // in the list.
28 // TODO(ishell): Don't derive from FixedArray as it already has its own map.
29 class ObjectBoilerplateDescription : public FixedArray {
30  public:
31   inline Object name(int index) const;
32   inline Object name(PtrComprCageBase cage_base, int index) const;
33 
34   inline Object value(int index) const;
35   inline Object value(PtrComprCageBase cage_base, int index) const;
36 
37   inline void set_key_value(int index, Object key, Object value);
38 
39   // The number of boilerplate properties.
40   inline int size() const;
41 
42   // Number of boilerplate properties and properties with computed names.
43   inline int backing_store_size() const;
44   inline void set_backing_store_size(int backing_store_size);
45 
46   // Used to encode ObjectLiteral::Flags for nested object literals
47   // Stored as the first element of the fixed array
48   DECL_INT_ACCESSORS(flags)
49   static const int kLiteralTypeOffset = 0;
50   static const int kDescriptionStartIndex = 1;
51 
52   DECL_CAST(ObjectBoilerplateDescription)
53   DECL_VERIFIER(ObjectBoilerplateDescription)
54   DECL_PRINTER(ObjectBoilerplateDescription)
55 
56  private:
57   inline bool has_number_of_properties() const;
58 
59   OBJECT_CONSTRUCTORS(ObjectBoilerplateDescription, FixedArray);
60 };
61 
62 class ArrayBoilerplateDescription
63     : public TorqueGeneratedArrayBoilerplateDescription<
64           ArrayBoilerplateDescription, Struct> {
65  public:
66   inline ElementsKind elements_kind() const;
67   inline void set_elements_kind(ElementsKind kind);
68 
69   inline bool is_empty() const;
70 
71   // Dispatched behavior.
72   DECL_PRINTER(ArrayBoilerplateDescription)
73   void BriefPrintDetails(std::ostream& os);
74 
75   using BodyDescriptor = StructBodyDescriptor;
76 
77  private:
78   TQ_OBJECT_CONSTRUCTORS(ArrayBoilerplateDescription)
79 };
80 
81 class RegExpBoilerplateDescription
82     : public TorqueGeneratedRegExpBoilerplateDescription<
83           RegExpBoilerplateDescription, Struct> {
84  public:
85   // Dispatched behavior.
86   void BriefPrintDetails(std::ostream& os);
87 
88   using BodyDescriptor = StructBodyDescriptor;
89 
90  private:
91   TQ_OBJECT_CONSTRUCTORS(RegExpBoilerplateDescription)
92 };
93 
94 class ClassBoilerplate : public FixedArray {
95  public:
96   enum ValueKind { kData, kGetter, kSetter };
97 
98   struct ComputedEntryFlags {
99 #define COMPUTED_ENTRY_BIT_FIELDS(V, _) \
100   V(ValueKindBits, ValueKind, 2, _)     \
101   V(KeyIndexBits, unsigned, 29, _)
102     DEFINE_BIT_FIELDS(COMPUTED_ENTRY_BIT_FIELDS)
103 #undef COMPUTED_ENTRY_BIT_FIELDS
104   };
105 
106   enum DefineClassArgumentsIndices {
107     kConstructorArgumentIndex = 1,
108     kPrototypeArgumentIndex = 2,
109     // The index of a first dynamic argument passed to Runtime::kDefineClass
110     // function. The dynamic arguments are consist of method closures and
111     // computed property names.
112     kFirstDynamicArgumentIndex = 3,
113   };
114 
115   static const int kMinimumClassPropertiesCount = 6;
116   static const int kMinimumPrototypePropertiesCount = 1;
117 
118   DECL_CAST(ClassBoilerplate)
119 
120   DECL_BOOLEAN_ACCESSORS(install_class_name_accessor)
121   DECL_INT_ACCESSORS(arguments_count)
122   DECL_ACCESSORS(static_properties_template, Object)
123   DECL_ACCESSORS(static_elements_template, Object)
124   DECL_ACCESSORS(static_computed_properties, FixedArray)
125   DECL_ACCESSORS(instance_properties_template, Object)
126   DECL_ACCESSORS(instance_elements_template, Object)
127   DECL_ACCESSORS(instance_computed_properties, FixedArray)
128 
129   template <typename IsolateT, typename Dictionary>
130   static void AddToPropertiesTemplate(IsolateT* isolate,
131                                       Handle<Dictionary> dictionary,
132                                       Handle<Name> name, int key_index,
133                                       ValueKind value_kind, Smi value);
134 
135   template <typename IsolateT>
136   static void AddToElementsTemplate(IsolateT* isolate,
137                                     Handle<NumberDictionary> dictionary,
138                                     uint32_t key, int key_index,
139                                     ValueKind value_kind, Smi value);
140 
141   template <typename IsolateT>
142   static Handle<ClassBoilerplate> BuildClassBoilerplate(IsolateT* isolate,
143                                                         ClassLiteral* expr);
144 
145   enum {
146     kArgumentsCountIndex,
147     kClassPropertiesTemplateIndex,
148     kClassElementsTemplateIndex,
149     kClassComputedPropertiesIndex,
150     kPrototypePropertiesTemplateIndex,
151     kPrototypeElementsTemplateIndex,
152     kPrototypeComputedPropertiesIndex,
153     kBoilerplateLength  // last element
154   };
155 
156  private:
157   DECL_INT_ACCESSORS(flags)
158 
159   OBJECT_CONSTRUCTORS(ClassBoilerplate, FixedArray);
160 };
161 
162 }  // namespace internal
163 }  // namespace v8
164 
165 #include "src/objects/object-macros-undef.h"
166 
167 #endif  // V8_OBJECTS_LITERAL_OBJECTS_H_
168