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