Line data Source code
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/objects/fixed-array.h"
9 : #include "src/objects/struct.h"
10 :
11 : // Has to be the last include (doesn't have include guards):
12 : #include "src/objects/object-macros.h"
13 :
14 : namespace v8 {
15 : namespace internal {
16 :
17 : class ClassLiteral;
18 :
19 : // ObjectBoilerplateDescription is a list of properties consisting of name value
20 : // pairs. In addition to the properties, it provides the projected number
21 : // of properties in the backing store. This number includes properties with
22 : // computed names that are not
23 : // in the list.
24 : class ObjectBoilerplateDescription : public FixedArray {
25 : public:
26 : Object name(int index) const;
27 : Object value(int index) const;
28 :
29 : void set_key_value(int index, Object key, Object value);
30 :
31 : // The number of boilerplate properties.
32 : int size() const;
33 :
34 : // Number of boilerplate properties and properties with computed names.
35 : int backing_store_size() const;
36 :
37 : void set_backing_store_size(Isolate* isolate, int backing_store_size);
38 :
39 : // Used to encode ObjectLiteral::Flags for nested object literals
40 : // Stored as the first element of the fixed array
41 : DECL_INT_ACCESSORS(flags)
42 : static const int kLiteralTypeOffset = 0;
43 : static const int kDescriptionStartIndex = 1;
44 :
45 : DECL_CAST(ObjectBoilerplateDescription)
46 : DECL_VERIFIER(ObjectBoilerplateDescription)
47 : DECL_PRINTER(ObjectBoilerplateDescription)
48 :
49 : private:
50 : bool has_number_of_properties() const;
51 :
52 56 : OBJECT_CONSTRUCTORS(ObjectBoilerplateDescription, FixedArray);
53 : };
54 :
55 : class ArrayBoilerplateDescription : public Struct {
56 : public:
57 : // store constant_elements of a fixed array
58 : DECL_ACCESSORS(constant_elements, FixedArrayBase)
59 :
60 : inline ElementsKind elements_kind() const;
61 : inline void set_elements_kind(ElementsKind kind);
62 :
63 : inline bool is_empty() const;
64 :
65 : DECL_CAST(ArrayBoilerplateDescription)
66 : // Dispatched behavior.
67 : DECL_PRINTER(ArrayBoilerplateDescription)
68 : DECL_VERIFIER(ArrayBoilerplateDescription)
69 : void BriefPrintDetails(std::ostream& os);
70 :
71 : #define ARRAY_BOILERPLATE_DESCRIPTION_FIELDS(V) \
72 : V(kFlagsOffset, kTaggedSize) \
73 : V(kConstantElementsOffset, kTaggedSize) \
74 : /* Total size. */ \
75 : V(kSize, 0)
76 :
77 : DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
78 : ARRAY_BOILERPLATE_DESCRIPTION_FIELDS)
79 : #undef ARRAY_BOILERPLATE_DESCRIPTION_FIELDS
80 :
81 : private:
82 : DECL_INT_ACCESSORS(flags)
83 280 : OBJECT_CONSTRUCTORS(ArrayBoilerplateDescription, Struct);
84 : };
85 :
86 : class ClassBoilerplate : public FixedArray {
87 : public:
88 : enum ValueKind { kData, kGetter, kSetter };
89 :
90 : struct Flags {
91 : #define FLAGS_BIT_FIELDS(V, _) \
92 : V(InstallClassNameAccessorBit, bool, 1, _) \
93 : V(ArgumentsCountBits, int, 30, _)
94 : DEFINE_BIT_FIELDS(FLAGS_BIT_FIELDS)
95 : #undef FLAGS_BIT_FIELDS
96 : };
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 : static void AddToPropertiesTemplate(Isolate* isolate,
130 : Handle<NameDictionary> dictionary,
131 : Handle<Name> name, int key_index,
132 : ValueKind value_kind, Object value);
133 :
134 : static void AddToElementsTemplate(Isolate* isolate,
135 : Handle<NumberDictionary> dictionary,
136 : uint32_t key, int key_index,
137 : ValueKind value_kind, Object value);
138 :
139 : static Handle<ClassBoilerplate> BuildClassBoilerplate(Isolate* isolate,
140 : ClassLiteral* expr);
141 :
142 : enum {
143 : kFlagsIndex,
144 : kClassPropertiesTemplateIndex,
145 : kClassElementsTemplateIndex,
146 : kClassComputedPropertiesIndex,
147 : kPrototypePropertiesTemplateIndex,
148 : kPrototypeElementsTemplateIndex,
149 : kPrototypeComputedPropertiesIndex,
150 : kBoileplateLength // last element
151 : };
152 :
153 : static const int kFullComputedEntrySize = 2;
154 :
155 : private:
156 : DECL_INT_ACCESSORS(flags)
157 :
158 : OBJECT_CONSTRUCTORS(ClassBoilerplate, FixedArray);
159 : };
160 :
161 : } // namespace internal
162 : } // namespace v8
163 :
164 : #include "src/objects/object-macros-undef.h"
165 :
166 : #endif // V8_OBJECTS_LITERAL_OBJECTS_H_
|