OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "test/cctest/test-api.h" | 8 #include "test/cctest/test-api.h" |
9 | 9 |
10 #include "src/v8.h" | 10 #include "src/v8.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 pair->set_getter(*func); | 66 pair->set_getter(*func); |
67 } | 67 } |
68 if (with_setter) { | 68 if (with_setter) { |
69 Handle<JSFunction> func = factory->NewFunction(empty_string); | 69 Handle<JSFunction> func = factory->NewFunction(empty_string); |
70 pair->set_setter(*func); | 70 pair->set_setter(*func); |
71 } | 71 } |
72 return pair; | 72 return pair; |
73 } | 73 } |
74 | 74 |
75 | 75 |
76 static bool EqualDetails(DescriptorArray* descriptors, int descriptor, | |
77 PropertyType type, PropertyAttributes attributes, | |
78 Representation representation, int field_index = -1) { | |
79 PropertyDetails details = descriptors->GetDetails(descriptor); | |
80 if (details.type() != type) return false; | |
81 if (details.attributes() != attributes) return false; | |
82 if (!details.representation().Equals(representation)) return false; | |
83 if (field_index >= 0 && details.field_index() != field_index) return false; | |
84 return true; | |
85 } | |
86 | |
87 | |
88 class Expectations { | 76 class Expectations { |
89 static const int MAX_PROPERTIES = 10; | 77 static const int MAX_PROPERTIES = 10; |
90 Isolate* isolate_; | 78 Isolate* isolate_; |
91 ElementsKind elements_kind_; | 79 ElementsKind elements_kind_; |
92 PropertyType types_[MAX_PROPERTIES]; | 80 PropertyKind kinds_[MAX_PROPERTIES]; |
| 81 PropertyLocation locations_[MAX_PROPERTIES]; |
93 PropertyAttributes attributes_[MAX_PROPERTIES]; | 82 PropertyAttributes attributes_[MAX_PROPERTIES]; |
94 Representation representations_[MAX_PROPERTIES]; | 83 Representation representations_[MAX_PROPERTIES]; |
95 // FieldType for kField, value for DATA_CONSTANT and getter for | 84 // FieldType for kField, value for DATA_CONSTANT and getter for |
96 // ACCESSOR_CONSTANT. | 85 // ACCESSOR_CONSTANT. |
97 Handle<Object> values_[MAX_PROPERTIES]; | 86 Handle<Object> values_[MAX_PROPERTIES]; |
98 // Setter for ACCESSOR_CONSTANT. | 87 // Setter for ACCESSOR_CONSTANT. |
99 Handle<Object> setter_values_[MAX_PROPERTIES]; | 88 Handle<Object> setter_values_[MAX_PROPERTIES]; |
100 int number_of_properties_; | 89 int number_of_properties_; |
101 | 90 |
102 public: | 91 public: |
103 explicit Expectations(Isolate* isolate, ElementsKind elements_kind) | 92 explicit Expectations(Isolate* isolate, ElementsKind elements_kind) |
104 : isolate_(isolate), | 93 : isolate_(isolate), |
105 elements_kind_(elements_kind), | 94 elements_kind_(elements_kind), |
106 number_of_properties_(0) {} | 95 number_of_properties_(0) {} |
107 | 96 |
108 explicit Expectations(Isolate* isolate) | 97 explicit Expectations(Isolate* isolate) |
109 : Expectations( | 98 : Expectations( |
110 isolate, | 99 isolate, |
111 isolate->object_function()->initial_map()->elements_kind()) {} | 100 isolate->object_function()->initial_map()->elements_kind()) {} |
112 | 101 |
113 void Init(int index, PropertyType type, PropertyAttributes attributes, | 102 void Init(int index, PropertyKind kind, PropertyAttributes attributes, |
114 Representation representation, Handle<Object> value) { | 103 PropertyLocation location, Representation representation, |
| 104 Handle<Object> value) { |
115 CHECK(index < MAX_PROPERTIES); | 105 CHECK(index < MAX_PROPERTIES); |
116 types_[index] = type; | 106 kinds_[index] = kind; |
| 107 locations_[index] = location; |
117 attributes_[index] = attributes; | 108 attributes_[index] = attributes; |
118 representations_[index] = representation; | 109 representations_[index] = representation; |
119 values_[index] = value; | 110 values_[index] = value; |
120 } | 111 } |
121 | 112 |
122 void Print() const { | 113 void Print() const { |
123 OFStream os(stdout); | 114 OFStream os(stdout); |
124 os << "Expectations: #" << number_of_properties_ << "\n"; | 115 os << "Expectations: #" << number_of_properties_ << "\n"; |
125 for (int i = 0; i < number_of_properties_; i++) { | 116 for (int i = 0; i < number_of_properties_; i++) { |
126 os << " " << i << ": "; | 117 os << " " << i << ": "; |
127 os << "Descriptor @ "; | 118 os << "Descriptor @ "; |
128 if (types_[i] == ACCESSOR_CONSTANT) { | 119 |
| 120 if (kinds_[i] == kData) { |
| 121 os << Brief(*values_[i]); |
| 122 } else { |
| 123 // kAccessor |
129 os << "(get: " << Brief(*values_[i]) | 124 os << "(get: " << Brief(*values_[i]) |
130 << ", set: " << Brief(*setter_values_[i]) << ") "; | 125 << ", set: " << Brief(*setter_values_[i]) << ") "; |
| 126 } |
| 127 |
| 128 os << " ("; |
| 129 os << (kinds_[i] == kData ? "data " : "accessor "); |
| 130 if (locations_[i] == kField) { |
| 131 os << "field" |
| 132 << ": " << representations_[i].Mnemonic(); |
131 } else { | 133 } else { |
132 os << Brief(*values_[i]); | 134 os << "descriptor"; |
133 } | 135 } |
134 os << " ("; | |
135 switch (types_[i]) { | |
136 case DATA_CONSTANT: | |
137 os << "immutable "; | |
138 // Fall through. | |
139 case DATA: | |
140 os << "data"; | |
141 break; | |
142 | |
143 case ACCESSOR_CONSTANT: | |
144 os << "immutable "; | |
145 // Fall through. | |
146 case ACCESSOR: | |
147 os << "accessor"; | |
148 break; | |
149 } | |
150 os << ": " << representations_[i].Mnemonic(); | |
151 os << ", attrs: " << attributes_[i] << ")\n"; | 136 os << ", attrs: " << attributes_[i] << ")\n"; |
152 } | 137 } |
153 os << "\n"; | 138 os << "\n"; |
154 } | 139 } |
155 | 140 |
156 void SetElementsKind(ElementsKind elements_kind) { | 141 void SetElementsKind(ElementsKind elements_kind) { |
157 elements_kind_ = elements_kind; | 142 elements_kind_ = elements_kind; |
158 } | 143 } |
159 | 144 |
160 Handle<FieldType> GetFieldType(int index) { | 145 Handle<FieldType> GetFieldType(int index) { |
161 CHECK(index < MAX_PROPERTIES); | 146 CHECK(index < MAX_PROPERTIES); |
162 CHECK(types_[index] == DATA || types_[index] == ACCESSOR); | 147 CHECK_EQ(kField, locations_[index]); |
163 return Handle<FieldType>::cast(values_[index]); | 148 return Handle<FieldType>::cast(values_[index]); |
164 } | 149 } |
165 | 150 |
166 void SetDataField(int index, PropertyAttributes attrs, | 151 void SetDataField(int index, PropertyAttributes attrs, |
167 Representation representation, Handle<FieldType> value) { | 152 Representation representation, |
168 Init(index, DATA, attrs, representation, value); | 153 Handle<FieldType> field_type) { |
| 154 Init(index, kData, attrs, kField, representation, field_type); |
169 } | 155 } |
170 | 156 |
171 void SetDataField(int index, Representation representation, | 157 void SetDataField(int index, Representation representation, |
172 Handle<FieldType> value) { | 158 Handle<FieldType> field_type) { |
173 SetDataField(index, attributes_[index], representation, value); | 159 SetDataField(index, attributes_[index], representation, field_type); |
174 } | 160 } |
175 | 161 |
176 void SetAccessorField(int index, PropertyAttributes attrs) { | 162 void SetAccessorField(int index, PropertyAttributes attrs) { |
177 Init(index, ACCESSOR, attrs, Representation::Tagged(), | 163 Init(index, kAccessor, attrs, kDescriptor, Representation::Tagged(), |
178 FieldType::Any(isolate_)); | 164 FieldType::Any(isolate_)); |
179 } | 165 } |
180 | 166 |
181 void SetAccessorField(int index) { | 167 void SetAccessorField(int index) { |
182 SetAccessorField(index, attributes_[index]); | 168 SetAccessorField(index, attributes_[index]); |
183 } | 169 } |
184 | 170 |
185 void SetDataConstant(int index, PropertyAttributes attrs, | 171 void SetDataConstant(int index, PropertyAttributes attrs, |
186 Handle<JSFunction> value) { | 172 Handle<JSFunction> value) { |
187 Init(index, DATA_CONSTANT, attrs, Representation::HeapObject(), value); | 173 Init(index, kData, attrs, kDescriptor, Representation::HeapObject(), value); |
188 } | 174 } |
189 | 175 |
190 void SetDataConstant(int index, Handle<JSFunction> value) { | 176 void SetDataConstant(int index, Handle<JSFunction> value) { |
191 SetDataConstant(index, attributes_[index], value); | 177 SetDataConstant(index, attributes_[index], value); |
192 } | 178 } |
193 | 179 |
194 void SetAccessorConstant(int index, PropertyAttributes attrs, | 180 void SetAccessorConstant(int index, PropertyAttributes attrs, |
195 Handle<Object> getter, Handle<Object> setter) { | 181 Handle<Object> getter, Handle<Object> setter) { |
196 Init(index, ACCESSOR_CONSTANT, attrs, Representation::Tagged(), getter); | 182 Init(index, kAccessor, attrs, kDescriptor, Representation::Tagged(), |
| 183 getter); |
197 setter_values_[index] = setter; | 184 setter_values_[index] = setter; |
198 } | 185 } |
199 | 186 |
200 void SetAccessorConstantComponent(int index, PropertyAttributes attrs, | 187 void SetAccessorConstantComponent(int index, PropertyAttributes attrs, |
201 AccessorComponent component, | 188 AccessorComponent component, |
202 Handle<Object> accessor) { | 189 Handle<Object> accessor) { |
203 CHECK_EQ(ACCESSOR_CONSTANT, types_[index]); | 190 CHECK_EQ(kAccessor, kinds_[index]); |
| 191 CHECK_EQ(kDescriptor, locations_[index]); |
204 CHECK(index < number_of_properties_); | 192 CHECK(index < number_of_properties_); |
205 if (component == ACCESSOR_GETTER) { | 193 if (component == ACCESSOR_GETTER) { |
206 values_[index] = accessor; | 194 values_[index] = accessor; |
207 } else { | 195 } else { |
208 setter_values_[index] = accessor; | 196 setter_values_[index] = accessor; |
209 } | 197 } |
210 } | 198 } |
211 | 199 |
212 void SetAccessorConstant(int index, PropertyAttributes attrs, | 200 void SetAccessorConstant(int index, PropertyAttributes attrs, |
213 Handle<AccessorPair> pair) { | 201 Handle<AccessorPair> pair) { |
214 Handle<Object> getter = handle(pair->getter(), isolate_); | 202 Handle<Object> getter = handle(pair->getter(), isolate_); |
215 Handle<Object> setter = handle(pair->setter(), isolate_); | 203 Handle<Object> setter = handle(pair->setter(), isolate_); |
216 SetAccessorConstant(index, attrs, getter, setter); | 204 SetAccessorConstant(index, attrs, getter, setter); |
217 } | 205 } |
218 | 206 |
219 void SetAccessorConstant(int index, Handle<Object> getter, | 207 void SetAccessorConstant(int index, Handle<Object> getter, |
220 Handle<Object> setter) { | 208 Handle<Object> setter) { |
221 SetAccessorConstant(index, attributes_[index], getter, setter); | 209 SetAccessorConstant(index, attributes_[index], getter, setter); |
222 } | 210 } |
223 | 211 |
224 void SetAccessorConstant(int index, Handle<AccessorPair> pair) { | 212 void SetAccessorConstant(int index, Handle<AccessorPair> pair) { |
225 Handle<Object> getter = handle(pair->getter(), isolate_); | 213 Handle<Object> getter = handle(pair->getter(), isolate_); |
226 Handle<Object> setter = handle(pair->setter(), isolate_); | 214 Handle<Object> setter = handle(pair->setter(), isolate_); |
227 SetAccessorConstant(index, getter, setter); | 215 SetAccessorConstant(index, getter, setter); |
228 } | 216 } |
229 | 217 |
230 void GeneralizeRepresentation(int index) { | 218 void GeneralizeRepresentation(int index) { |
231 CHECK(index < number_of_properties_); | 219 CHECK(index < number_of_properties_); |
232 representations_[index] = Representation::Tagged(); | 220 representations_[index] = Representation::Tagged(); |
233 if (types_[index] == DATA || types_[index] == ACCESSOR) { | 221 if (locations_[index] == kField) { |
234 values_[index] = FieldType::Any(isolate_); | 222 values_[index] = FieldType::Any(isolate_); |
235 } | 223 } |
236 } | 224 } |
237 | 225 |
238 | 226 |
239 bool Check(DescriptorArray* descriptors, int descriptor) const { | 227 bool Check(DescriptorArray* descriptors, int descriptor) const { |
240 PropertyType type = types_[descriptor]; | 228 PropertyDetails details = descriptors->GetDetails(descriptor); |
241 if (!EqualDetails(descriptors, descriptor, type, attributes_[descriptor], | 229 |
242 representations_[descriptor])) { | 230 if (details.kind() != kinds_[descriptor]) return false; |
243 return false; | 231 if (details.location() != locations_[descriptor]) return false; |
244 } | 232 |
| 233 PropertyAttributes expected_attributes = attributes_[descriptor]; |
| 234 if (details.attributes() != expected_attributes) return false; |
| 235 |
| 236 Representation expected_representation = representations_[descriptor]; |
| 237 if (!details.representation().Equals(expected_representation)) return false; |
| 238 |
245 Object* value = descriptors->GetValue(descriptor); | 239 Object* value = descriptors->GetValue(descriptor); |
246 Object* expected_value = *values_[descriptor]; | 240 Object* expected_value = *values_[descriptor]; |
247 switch (type) { | 241 if (details.location() == kField) { |
248 case DATA: | 242 if (details.kind() == kData) { |
249 case ACCESSOR: { | |
250 FieldType* type = descriptors->GetFieldType(descriptor); | 243 FieldType* type = descriptors->GetFieldType(descriptor); |
251 return FieldType::cast(expected_value) == type; | 244 return FieldType::cast(expected_value) == type; |
| 245 } else { |
| 246 // kAccessor |
| 247 UNREACHABLE(); |
| 248 return false; |
252 } | 249 } |
253 | 250 } else { |
254 case DATA_CONSTANT: | 251 // kDescriptor |
| 252 if (details.kind() == kData) { |
255 return value == expected_value; | 253 return value == expected_value; |
256 | 254 } else { |
257 case ACCESSOR_CONSTANT: { | 255 // kAccessor |
258 if (value == expected_value) return true; | 256 if (value == expected_value) return true; |
259 if (!value->IsAccessorPair()) return false; | 257 if (!value->IsAccessorPair()) return false; |
260 AccessorPair* pair = AccessorPair::cast(value); | 258 AccessorPair* pair = AccessorPair::cast(value); |
261 return pair->Equals(expected_value, *setter_values_[descriptor]); | 259 return pair->Equals(expected_value, *setter_values_[descriptor]); |
262 } | 260 } |
263 } | 261 } |
264 UNREACHABLE(); | 262 UNREACHABLE(); |
265 return false; | 263 return false; |
266 } | 264 } |
267 | 265 |
(...skipping 2165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2433 Isolate* isolate = CcTest::i_isolate(); | 2431 Isolate* isolate = CcTest::i_isolate(); |
2434 | 2432 |
2435 Zone zone(isolate->allocator(), ZONE_NAME); | 2433 Zone zone(isolate->allocator(), ZONE_NAME); |
2436 | 2434 |
2437 CHECK_EQ(FieldType::Any()->Convert(&zone), AstType::NonInternal()); | 2435 CHECK_EQ(FieldType::Any()->Convert(&zone), AstType::NonInternal()); |
2438 CHECK_EQ(FieldType::None()->Convert(&zone), AstType::None()); | 2436 CHECK_EQ(FieldType::None()->Convert(&zone), AstType::None()); |
2439 } | 2437 } |
2440 | 2438 |
2441 // TODO(ishell): add this test once IS_ACCESSOR_FIELD_SUPPORTED is supported. | 2439 // TODO(ishell): add this test once IS_ACCESSOR_FIELD_SUPPORTED is supported. |
2442 // TEST(TransitionAccessorConstantToAnotherAccessorConstant) | 2440 // TEST(TransitionAccessorConstantToAnotherAccessorConstant) |
OLD | NEW |