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_FIELD_OFFSET_CONSTANTS(
72 : HeapObject::kHeaderSize,
73 : TORQUE_GENERATED_ARRAY_BOILERPLATE_DESCRIPTION_FIELDS)
74 :
75 : private:
76 : DECL_INT_ACCESSORS(flags)
77 280 : OBJECT_CONSTRUCTORS(ArrayBoilerplateDescription, Struct);
78 : };
79 :
80 : class ClassBoilerplate : public FixedArray {
81 : public:
82 : enum ValueKind { kData, kGetter, kSetter };
83 :
84 : struct Flags {
85 : #define FLAGS_BIT_FIELDS(V, _) \
86 : V(InstallClassNameAccessorBit, bool, 1, _) \
87 : V(ArgumentsCountBits, int, 30, _)
88 : DEFINE_BIT_FIELDS(FLAGS_BIT_FIELDS)
89 : #undef FLAGS_BIT_FIELDS
90 : };
91 :
92 : struct ComputedEntryFlags {
93 : #define COMPUTED_ENTRY_BIT_FIELDS(V, _) \
94 : V(ValueKindBits, ValueKind, 2, _) \
95 : V(KeyIndexBits, unsigned, 29, _)
96 : DEFINE_BIT_FIELDS(COMPUTED_ENTRY_BIT_FIELDS)
97 : #undef COMPUTED_ENTRY_BIT_FIELDS
98 : };
99 :
100 : enum DefineClassArgumentsIndices {
101 : kConstructorArgumentIndex = 1,
102 : kPrototypeArgumentIndex = 2,
103 : // The index of a first dynamic argument passed to Runtime::kDefineClass
104 : // function. The dynamic arguments are consist of method closures and
105 : // computed property names.
106 : kFirstDynamicArgumentIndex = 3,
107 : };
108 :
109 : static const int kMinimumClassPropertiesCount = 6;
110 : static const int kMinimumPrototypePropertiesCount = 1;
111 :
112 : DECL_CAST(ClassBoilerplate)
113 :
114 : DECL_BOOLEAN_ACCESSORS(install_class_name_accessor)
115 : DECL_INT_ACCESSORS(arguments_count)
116 : DECL_ACCESSORS(static_properties_template, Object)
117 : DECL_ACCESSORS(static_elements_template, Object)
118 : DECL_ACCESSORS(static_computed_properties, FixedArray)
119 : DECL_ACCESSORS(instance_properties_template, Object)
120 : DECL_ACCESSORS(instance_elements_template, Object)
121 : DECL_ACCESSORS(instance_computed_properties, FixedArray)
122 :
123 : static void AddToPropertiesTemplate(Isolate* isolate,
124 : Handle<NameDictionary> dictionary,
125 : Handle<Name> name, int key_index,
126 : ValueKind value_kind, Object value);
127 :
128 : static void AddToElementsTemplate(Isolate* isolate,
129 : Handle<NumberDictionary> dictionary,
130 : uint32_t key, int key_index,
131 : ValueKind value_kind, Object value);
132 :
133 : static Handle<ClassBoilerplate> BuildClassBoilerplate(Isolate* isolate,
134 : ClassLiteral* expr);
135 :
136 : enum {
137 : kFlagsIndex,
138 : kClassPropertiesTemplateIndex,
139 : kClassElementsTemplateIndex,
140 : kClassComputedPropertiesIndex,
141 : kPrototypePropertiesTemplateIndex,
142 : kPrototypeElementsTemplateIndex,
143 : kPrototypeComputedPropertiesIndex,
144 : kBoileplateLength // last element
145 : };
146 :
147 : static const int kFullComputedEntrySize = 2;
148 :
149 : private:
150 : DECL_INT_ACCESSORS(flags)
151 :
152 : OBJECT_CONSTRUCTORS(ClassBoilerplate, FixedArray);
153 : };
154 :
155 : } // namespace internal
156 : } // namespace v8
157 :
158 : #include "src/objects/object-macros-undef.h"
159 :
160 : #endif // V8_OBJECTS_LITERAL_OBJECTS_H_
|