OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 "src/key-accumulator.h" | 5 #include "src/keys.h" |
6 | 6 |
7 #include "src/elements.h" | 7 #include "src/elements.h" |
8 #include "src/factory.h" | 8 #include "src/factory.h" |
9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
11 #include "src/property-descriptor.h" | 11 #include "src/property-descriptor.h" |
12 | 12 #include "src/prototype.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 | |
18 KeyAccumulator::~KeyAccumulator() { | 17 KeyAccumulator::~KeyAccumulator() { |
19 for (size_t i = 0; i < elements_.size(); i++) { | 18 for (size_t i = 0; i < elements_.size(); i++) { |
20 delete elements_[i]; | 19 delete elements_[i]; |
21 } | 20 } |
22 } | 21 } |
23 | 22 |
24 | |
25 Handle<FixedArray> KeyAccumulator::GetKeys(GetKeysConversion convert) { | 23 Handle<FixedArray> KeyAccumulator::GetKeys(GetKeysConversion convert) { |
26 if (length_ == 0) { | 24 if (length_ == 0) { |
27 return isolate_->factory()->empty_fixed_array(); | 25 return isolate_->factory()->empty_fixed_array(); |
28 } | 26 } |
29 // Make sure we have all the lengths collected. | 27 // Make sure we have all the lengths collected. |
30 NextPrototype(); | 28 NextPrototype(); |
31 | 29 |
32 if (type_ == OWN_ONLY && !ownProxyKeys_.is_null()) { | 30 if (type_ == OWN_ONLY && !ownProxyKeys_.is_null()) { |
33 return ownProxyKeys_; | 31 return ownProxyKeys_; |
34 } | 32 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 result->set(insertion_index, key); | 77 result->set(insertion_index, key); |
80 insertion_index++; | 78 insertion_index++; |
81 symbol_properties_index++; | 79 symbol_properties_index++; |
82 } | 80 } |
83 } | 81 } |
84 | 82 |
85 DCHECK_EQ(insertion_index, length_); | 83 DCHECK_EQ(insertion_index, length_); |
86 return result; | 84 return result; |
87 } | 85 } |
88 | 86 |
89 | |
90 namespace { | 87 namespace { |
91 | 88 |
92 bool AccumulatorHasKey(std::vector<uint32_t>* sub_elements, uint32_t key) { | 89 bool AccumulatorHasKey(std::vector<uint32_t>* sub_elements, uint32_t key) { |
93 return std::binary_search(sub_elements->begin(), sub_elements->end(), key); | 90 return std::binary_search(sub_elements->begin(), sub_elements->end(), key); |
94 } | 91 } |
95 | 92 |
96 } // namespace | 93 } // namespace |
97 | 94 |
98 bool KeyAccumulator::AddKey(Object* key, AddKeyConversion convert) { | 95 bool KeyAccumulator::AddKey(Object* key, AddKeyConversion convert) { |
99 return AddKey(handle(key, isolate_), convert); | 96 return AddKey(handle(key, isolate_), convert); |
100 } | 97 } |
101 | 98 |
102 | |
103 bool KeyAccumulator::AddKey(Handle<Object> key, AddKeyConversion convert) { | 99 bool KeyAccumulator::AddKey(Handle<Object> key, AddKeyConversion convert) { |
104 if (key->IsSymbol()) { | 100 if (key->IsSymbol()) { |
105 if (filter_ & SKIP_SYMBOLS) return false; | 101 if (filter_ & SKIP_SYMBOLS) return false; |
106 if (Handle<Symbol>::cast(key)->is_private()) return false; | 102 if (Handle<Symbol>::cast(key)->is_private()) return false; |
107 return AddSymbolKey(key); | 103 return AddSymbolKey(key); |
108 } | 104 } |
109 if (filter_ & SKIP_STRINGS) return false; | 105 if (filter_ & SKIP_STRINGS) return false; |
110 // Make sure we do not add keys to a proxy-level (see AddKeysFromProxy). | 106 // Make sure we do not add keys to a proxy-level (see AddKeysFromProxy). |
111 DCHECK_LE(0, level_string_length_); | 107 DCHECK_LE(0, level_string_length_); |
112 // In some cases (e.g. proxies) we might get in String-converted ints which | 108 // In some cases (e.g. proxies) we might get in String-converted ints which |
(...skipping 16 matching lines...) Expand all Loading... |
129 return false; | 125 return false; |
130 } | 126 } |
131 length_ = prev_length; | 127 length_ = prev_length; |
132 level_string_length_ = prev_proto; | 128 level_string_length_ = prev_proto; |
133 } | 129 } |
134 } | 130 } |
135 } | 131 } |
136 return AddStringKey(key, convert); | 132 return AddStringKey(key, convert); |
137 } | 133 } |
138 | 134 |
139 | |
140 bool KeyAccumulator::AddKey(uint32_t key) { return AddIntegerKey(key); } | 135 bool KeyAccumulator::AddKey(uint32_t key) { return AddIntegerKey(key); } |
141 | 136 |
142 | |
143 bool KeyAccumulator::AddIntegerKey(uint32_t key) { | 137 bool KeyAccumulator::AddIntegerKey(uint32_t key) { |
144 // Make sure we do not add keys to a proxy-level (see AddKeysFromProxy). | 138 // Make sure we do not add keys to a proxy-level (see AddKeysFromProxy). |
145 // We mark proxy-levels with a negative length | 139 // We mark proxy-levels with a negative length |
146 DCHECK_LE(0, level_string_length_); | 140 DCHECK_LE(0, level_string_length_); |
147 // Binary search over all but the last level. The last one might not be | 141 // Binary search over all but the last level. The last one might not be |
148 // sorted yet. | 142 // sorted yet. |
149 for (size_t i = 1; i < elements_.size(); i++) { | 143 for (size_t i = 1; i < elements_.size(); i++) { |
150 if (AccumulatorHasKey(elements_[i - 1], key)) return false; | 144 if (AccumulatorHasKey(elements_[i - 1], key)) return false; |
151 } | 145 } |
152 elements_.back()->push_back(key); | 146 elements_.back()->push_back(key); |
153 length_++; | 147 length_++; |
154 return true; | 148 return true; |
155 } | 149 } |
156 | 150 |
157 | |
158 bool KeyAccumulator::AddStringKey(Handle<Object> key, | 151 bool KeyAccumulator::AddStringKey(Handle<Object> key, |
159 AddKeyConversion convert) { | 152 AddKeyConversion convert) { |
160 if (string_properties_.is_null()) { | 153 if (string_properties_.is_null()) { |
161 string_properties_ = OrderedHashSet::Allocate(isolate_, 16); | 154 string_properties_ = OrderedHashSet::Allocate(isolate_, 16); |
162 } | 155 } |
163 // TODO(cbruni): remove this conversion once we throw the correct TypeError | 156 // TODO(cbruni): remove this conversion once we throw the correct TypeError |
164 // for non-string/symbol elements returned by proxies | 157 // for non-string/symbol elements returned by proxies |
165 if (convert == PROXY_MAGIC && key->IsNumber()) { | 158 if (convert == PROXY_MAGIC && key->IsNumber()) { |
166 key = isolate_->factory()->NumberToString(key); | 159 key = isolate_->factory()->NumberToString(key); |
167 } | 160 } |
168 int prev_size = string_properties_->NumberOfElements(); | 161 int prev_size = string_properties_->NumberOfElements(); |
169 string_properties_ = OrderedHashSet::Add(string_properties_, key); | 162 string_properties_ = OrderedHashSet::Add(string_properties_, key); |
170 if (prev_size < string_properties_->NumberOfElements()) { | 163 if (prev_size < string_properties_->NumberOfElements()) { |
171 length_++; | 164 length_++; |
172 level_string_length_++; | 165 level_string_length_++; |
173 return true; | 166 return true; |
174 } else { | 167 } else { |
175 return false; | 168 return false; |
176 } | 169 } |
177 } | 170 } |
178 | 171 |
179 | |
180 bool KeyAccumulator::AddSymbolKey(Handle<Object> key) { | 172 bool KeyAccumulator::AddSymbolKey(Handle<Object> key) { |
181 if (symbol_properties_.is_null()) { | 173 if (symbol_properties_.is_null()) { |
182 symbol_properties_ = OrderedHashSet::Allocate(isolate_, 16); | 174 symbol_properties_ = OrderedHashSet::Allocate(isolate_, 16); |
183 } | 175 } |
184 int prev_size = symbol_properties_->NumberOfElements(); | 176 int prev_size = symbol_properties_->NumberOfElements(); |
185 symbol_properties_ = OrderedHashSet::Add(symbol_properties_, key); | 177 symbol_properties_ = OrderedHashSet::Add(symbol_properties_, key); |
186 if (prev_size < symbol_properties_->NumberOfElements()) { | 178 if (prev_size < symbol_properties_->NumberOfElements()) { |
187 length_++; | 179 length_++; |
188 level_symbol_length_++; | 180 level_symbol_length_++; |
189 return true; | 181 return true; |
190 } else { | 182 } else { |
191 return false; | 183 return false; |
192 } | 184 } |
193 } | 185 } |
194 | 186 |
195 | |
196 void KeyAccumulator::AddKeys(Handle<FixedArray> array, | 187 void KeyAccumulator::AddKeys(Handle<FixedArray> array, |
197 AddKeyConversion convert) { | 188 AddKeyConversion convert) { |
198 int add_length = array->length(); | 189 int add_length = array->length(); |
199 if (add_length == 0) return; | 190 if (add_length == 0) return; |
200 for (int i = 0; i < add_length; i++) { | 191 for (int i = 0; i < add_length; i++) { |
201 Handle<Object> current(array->get(i), isolate_); | 192 Handle<Object> current(array->get(i), isolate_); |
202 AddKey(current, convert); | 193 AddKey(current, convert); |
203 } | 194 } |
204 } | 195 } |
205 | 196 |
206 | |
207 void KeyAccumulator::AddKeys(Handle<JSObject> array_like, | 197 void KeyAccumulator::AddKeys(Handle<JSObject> array_like, |
208 AddKeyConversion convert) { | 198 AddKeyConversion convert) { |
209 DCHECK(array_like->IsJSArray() || array_like->HasSloppyArgumentsElements()); | 199 DCHECK(array_like->IsJSArray() || array_like->HasSloppyArgumentsElements()); |
210 ElementsAccessor* accessor = array_like->GetElementsAccessor(); | 200 ElementsAccessor* accessor = array_like->GetElementsAccessor(); |
211 accessor->AddElementsToKeyAccumulator(array_like, this, convert); | 201 accessor->AddElementsToKeyAccumulator(array_like, this, convert); |
212 } | 202 } |
213 | 203 |
214 | |
215 void KeyAccumulator::AddKeysFromProxy(Handle<JSObject> array_like) { | 204 void KeyAccumulator::AddKeysFromProxy(Handle<JSObject> array_like) { |
216 // Proxies define a complete list of keys with no distinction of | 205 // Proxies define a complete list of keys with no distinction of |
217 // elements and properties, which breaks the normal assumption for the | 206 // elements and properties, which breaks the normal assumption for the |
218 // KeyAccumulator. | 207 // KeyAccumulator. |
219 AddKeys(array_like, PROXY_MAGIC); | 208 AddKeys(array_like, PROXY_MAGIC); |
220 // Invert the current length to indicate a present proxy, so we can ignore | 209 // Invert the current length to indicate a present proxy, so we can ignore |
221 // element keys for this level. Otherwise we would not fully respect the order | 210 // element keys for this level. Otherwise we would not fully respect the order |
222 // given by the proxy. | 211 // given by the proxy. |
223 level_string_length_ = -level_string_length_; | 212 level_string_length_ = -level_string_length_; |
224 } | 213 } |
225 | 214 |
226 | |
227 MaybeHandle<FixedArray> FilterProxyKeys(Isolate* isolate, Handle<JSProxy> owner, | 215 MaybeHandle<FixedArray> FilterProxyKeys(Isolate* isolate, Handle<JSProxy> owner, |
228 Handle<FixedArray> keys, | 216 Handle<FixedArray> keys, |
229 PropertyFilter filter) { | 217 PropertyFilter filter) { |
230 if (filter == ALL_PROPERTIES) { | 218 if (filter == ALL_PROPERTIES) { |
231 // Nothing to do. | 219 // Nothing to do. |
232 return keys; | 220 return keys; |
233 } | 221 } |
234 int store_position = 0; | 222 int store_position = 0; |
235 for (int i = 0; i < keys->length(); ++i) { | 223 for (int i = 0; i < keys->length(); ++i) { |
236 Handle<Name> key(Name::cast(keys->get(i)), isolate); | 224 Handle<Name> key(Name::cast(keys->get(i)), isolate); |
237 if (key->FilterKey(filter)) continue; // Skip this key. | 225 if (key->FilterKey(filter)) continue; // Skip this key. |
238 if (filter & ONLY_ENUMERABLE) { | 226 if (filter & ONLY_ENUMERABLE) { |
239 PropertyDescriptor desc; | 227 PropertyDescriptor desc; |
240 Maybe<bool> found = | 228 Maybe<bool> found = |
241 JSProxy::GetOwnPropertyDescriptor(isolate, owner, key, &desc); | 229 JSProxy::GetOwnPropertyDescriptor(isolate, owner, key, &desc); |
242 MAYBE_RETURN(found, MaybeHandle<FixedArray>()); | 230 MAYBE_RETURN(found, MaybeHandle<FixedArray>()); |
243 if (!found.FromJust() || !desc.enumerable()) continue; // Skip this key. | 231 if (!found.FromJust() || !desc.enumerable()) continue; // Skip this key. |
244 } | 232 } |
245 // Keep this key. | 233 // Keep this key. |
246 if (store_position != i) { | 234 if (store_position != i) { |
247 keys->set(store_position, *key); | 235 keys->set(store_position, *key); |
248 } | 236 } |
249 store_position++; | 237 store_position++; |
250 } | 238 } |
251 if (store_position == 0) return isolate->factory()->empty_fixed_array(); | 239 if (store_position == 0) return isolate->factory()->empty_fixed_array(); |
252 keys->Shrink(store_position); | 240 keys->Shrink(store_position); |
253 return keys; | 241 return keys; |
254 } | 242 } |
255 | 243 |
256 | |
257 // Returns "nothing" in case of exception, "true" on success. | 244 // Returns "nothing" in case of exception, "true" on success. |
258 Maybe<bool> KeyAccumulator::AddKeysFromProxy(Handle<JSProxy> proxy, | 245 Maybe<bool> KeyAccumulator::AddKeysFromProxy(Handle<JSProxy> proxy, |
259 Handle<FixedArray> keys) { | 246 Handle<FixedArray> keys) { |
260 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 247 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
261 isolate_, keys, FilterProxyKeys(isolate_, proxy, keys, filter_), | 248 isolate_, keys, FilterProxyKeys(isolate_, proxy, keys, filter_), |
262 Nothing<bool>()); | 249 Nothing<bool>()); |
263 // Proxies define a complete list of keys with no distinction of | 250 // Proxies define a complete list of keys with no distinction of |
264 // elements and properties, which breaks the normal assumption for the | 251 // elements and properties, which breaks the normal assumption for the |
265 // KeyAccumulator. | 252 // KeyAccumulator. |
266 if (type_ == OWN_ONLY) { | 253 if (type_ == OWN_ONLY) { |
267 ownProxyKeys_ = keys; | 254 ownProxyKeys_ = keys; |
268 level_string_length_ = keys->length(); | 255 level_string_length_ = keys->length(); |
269 length_ = level_string_length_; | 256 length_ = level_string_length_; |
270 } else { | 257 } else { |
271 AddKeys(keys, PROXY_MAGIC); | 258 AddKeys(keys, PROXY_MAGIC); |
272 } | 259 } |
273 // Invert the current length to indicate a present proxy, so we can ignore | 260 // Invert the current length to indicate a present proxy, so we can ignore |
274 // element keys for this level. Otherwise we would not fully respect the order | 261 // element keys for this level. Otherwise we would not fully respect the order |
275 // given by the proxy. | 262 // given by the proxy. |
276 level_string_length_ = -level_string_length_; | 263 level_string_length_ = -level_string_length_; |
277 return Just(true); | 264 return Just(true); |
278 } | 265 } |
279 | 266 |
280 | |
281 void KeyAccumulator::AddElementKeysFromInterceptor( | 267 void KeyAccumulator::AddElementKeysFromInterceptor( |
282 Handle<JSObject> array_like) { | 268 Handle<JSObject> array_like) { |
283 AddKeys(array_like, CONVERT_TO_ARRAY_INDEX); | 269 AddKeys(array_like, CONVERT_TO_ARRAY_INDEX); |
284 // The interceptor might introduce duplicates for the current level, since | 270 // The interceptor might introduce duplicates for the current level, since |
285 // these keys get added after the objects's normal element keys. | 271 // these keys get added after the objects's normal element keys. |
286 SortCurrentElementsListRemoveDuplicates(); | 272 SortCurrentElementsListRemoveDuplicates(); |
287 } | 273 } |
288 | 274 |
289 | |
290 void KeyAccumulator::SortCurrentElementsListRemoveDuplicates() { | 275 void KeyAccumulator::SortCurrentElementsListRemoveDuplicates() { |
291 // Sort and remove duplicates from the current elements level and adjust. | 276 // Sort and remove duplicates from the current elements level and adjust. |
292 // the lengths accordingly. | 277 // the lengths accordingly. |
293 auto last_level = elements_.back(); | 278 auto last_level = elements_.back(); |
294 size_t nof_removed_keys = last_level->size(); | 279 size_t nof_removed_keys = last_level->size(); |
295 std::sort(last_level->begin(), last_level->end()); | 280 std::sort(last_level->begin(), last_level->end()); |
296 last_level->erase(std::unique(last_level->begin(), last_level->end()), | 281 last_level->erase(std::unique(last_level->begin(), last_level->end()), |
297 last_level->end()); | 282 last_level->end()); |
298 // Adjust total length by the number of removed duplicates. | 283 // Adjust total length by the number of removed duplicates. |
299 nof_removed_keys -= last_level->size(); | 284 nof_removed_keys -= last_level->size(); |
300 length_ -= static_cast<int>(nof_removed_keys); | 285 length_ -= static_cast<int>(nof_removed_keys); |
301 } | 286 } |
302 | 287 |
303 | |
304 void KeyAccumulator::SortCurrentElementsList() { | 288 void KeyAccumulator::SortCurrentElementsList() { |
305 if (elements_.empty()) return; | 289 if (elements_.empty()) return; |
306 auto element_keys = elements_.back(); | 290 auto element_keys = elements_.back(); |
307 std::sort(element_keys->begin(), element_keys->end()); | 291 std::sort(element_keys->begin(), element_keys->end()); |
308 } | 292 } |
309 | 293 |
310 | |
311 void KeyAccumulator::NextPrototype() { | 294 void KeyAccumulator::NextPrototype() { |
312 // Store the protoLength on the first call of this method. | 295 // Store the protoLength on the first call of this method. |
313 if (!elements_.empty()) { | 296 if (!elements_.empty()) { |
314 level_lengths_.push_back(level_string_length_); | 297 level_lengths_.push_back(level_string_length_); |
315 level_lengths_.push_back(level_symbol_length_); | 298 level_lengths_.push_back(level_symbol_length_); |
316 } | 299 } |
317 elements_.push_back(new std::vector<uint32_t>()); | 300 elements_.push_back(new std::vector<uint32_t>()); |
318 level_string_length_ = 0; | 301 level_string_length_ = 0; |
319 level_symbol_length_ = 0; | 302 level_symbol_length_ = 0; |
320 } | 303 } |
321 | 304 |
| 305 namespace { |
| 306 |
| 307 void TrySettingEmptyEnumCache(JSReceiver* object) { |
| 308 Map* map = object->map(); |
| 309 DCHECK_EQ(kInvalidEnumCacheSentinel, map->EnumLength()); |
| 310 if (!map->OnlyHasSimpleProperties()) return; |
| 311 if (map->IsJSProxyMap()) return; |
| 312 if (map->NumberOfOwnDescriptors() > 0) { |
| 313 int number_of_enumerable_own_properties = |
| 314 map->NumberOfDescribedProperties(OWN_DESCRIPTORS, ENUMERABLE_STRINGS); |
| 315 if (number_of_enumerable_own_properties > 0) return; |
| 316 } |
| 317 DCHECK(object->IsJSObject()); |
| 318 map->SetEnumLength(0); |
| 319 } |
| 320 |
| 321 bool CheckAndInitalizeSimpleEnumCache(JSReceiver* object) { |
| 322 if (object->map()->EnumLength() == kInvalidEnumCacheSentinel) { |
| 323 TrySettingEmptyEnumCache(object); |
| 324 } |
| 325 if (object->map()->EnumLength() != 0) return false; |
| 326 DCHECK(object->IsJSObject()); |
| 327 return !JSObject::cast(object)->HasEnumerableElements(); |
| 328 } |
| 329 } // namespace |
| 330 |
| 331 void FastKeyAccumulator::Prepare() { |
| 332 DisallowHeapAllocation no_gc; |
| 333 // Directly go for the fast path for OWN_ONLY keys. |
| 334 if (type_ == OWN_ONLY) return; |
| 335 // Fully walk the prototype chain and find the last prototype with keys. |
| 336 is_receiver_simple_enum_ = false; |
| 337 has_empty_prototype_ = true; |
| 338 JSReceiver* first_non_empty_prototype; |
| 339 for (PrototypeIterator iter(isolate_, *receiver_); !iter.IsAtEnd(); |
| 340 iter.Advance()) { |
| 341 JSReceiver* current = iter.GetCurrent<JSReceiver>(); |
| 342 if (CheckAndInitalizeSimpleEnumCache(current)) continue; |
| 343 has_empty_prototype_ = false; |
| 344 first_non_empty_prototype = current; |
| 345 // TODO(cbruni): use the first non-empty prototype. |
| 346 USE(first_non_empty_prototype); |
| 347 return; |
| 348 } |
| 349 DCHECK(has_empty_prototype_); |
| 350 is_receiver_simple_enum_ = |
| 351 receiver_->map()->EnumLength() != kInvalidEnumCacheSentinel && |
| 352 !JSObject::cast(*receiver_)->HasEnumerableElements(); |
| 353 } |
| 354 |
| 355 namespace { |
| 356 Handle<FixedArray> GetOwnKeysWithElements(Isolate* isolate, |
| 357 Handle<JSObject> object, |
| 358 GetKeysConversion convert) { |
| 359 Handle<FixedArray> keys = JSObject::GetFastEnumPropertyKeys(isolate, object); |
| 360 ElementsAccessor* accessor = object->GetElementsAccessor(); |
| 361 return accessor->PrependElementIndices(object, keys, convert, |
| 362 ONLY_ENUMERABLE); |
| 363 } |
| 364 |
| 365 MaybeHandle<FixedArray> GetOwnKeysWithUninitializedEnumCache( |
| 366 Isolate* isolate, Handle<JSObject> object) { |
| 367 // Uninitalized enum cache |
| 368 Map* map = object->map(); |
| 369 if (object->elements() != isolate->heap()->empty_fixed_array() || |
| 370 object->elements() != isolate->heap()->empty_slow_element_dictionary()) { |
| 371 // Assume that there are elements. |
| 372 return MaybeHandle<FixedArray>(); |
| 373 } |
| 374 int number_of_own_descriptors = map->NumberOfOwnDescriptors(); |
| 375 if (number_of_own_descriptors == 0) { |
| 376 map->SetEnumLength(0); |
| 377 return isolate->factory()->empty_fixed_array(); |
| 378 } |
| 379 // We have no elements but possibly enumerable property keys, hence we can |
| 380 // directly initialize the enum cache. |
| 381 return JSObject::GetFastEnumPropertyKeys(isolate, object); |
| 382 } |
| 383 |
| 384 } // namespace |
| 385 |
| 386 MaybeHandle<FixedArray> FastKeyAccumulator::GetKeys(GetKeysConversion convert) { |
| 387 Handle<FixedArray> keys; |
| 388 if (GetKeysFast(convert).ToHandle(&keys)) { |
| 389 return keys; |
| 390 } |
| 391 return GetKeysSlow(convert); |
| 392 } |
| 393 |
| 394 MaybeHandle<FixedArray> FastKeyAccumulator::GetKeysFast( |
| 395 GetKeysConversion convert) { |
| 396 bool own_only = has_empty_prototype_ || type_ == OWN_ONLY; |
| 397 if (!own_only || !receiver_->map()->OnlyHasSimpleProperties()) { |
| 398 return MaybeHandle<FixedArray>(); |
| 399 } |
| 400 |
| 401 Handle<FixedArray> keys; |
| 402 DCHECK(receiver_->IsJSObject()); |
| 403 Handle<JSObject> object = Handle<JSObject>::cast(receiver_); |
| 404 |
| 405 int enum_length = receiver_->map()->EnumLength(); |
| 406 if (enum_length == kInvalidEnumCacheSentinel) { |
| 407 // Try initializing the enum cache and return own properties. |
| 408 if (GetOwnKeysWithUninitializedEnumCache(isolate_, object) |
| 409 .ToHandle(&keys)) { |
| 410 is_receiver_simple_enum_ = |
| 411 object->map()->EnumLength() != kInvalidEnumCacheSentinel; |
| 412 return keys; |
| 413 } |
| 414 } |
| 415 // The properties-only case failed because there were probably elements on the |
| 416 // receiver. |
| 417 return GetOwnKeysWithElements(isolate_, object, convert); |
| 418 } |
| 419 |
| 420 MaybeHandle<FixedArray> FastKeyAccumulator::GetKeysSlow( |
| 421 GetKeysConversion convert) { |
| 422 return JSReceiver::GetKeys(receiver_, type_, ENUMERABLE_STRINGS); |
| 423 } |
322 | 424 |
323 } // namespace internal | 425 } // namespace internal |
324 } // namespace v8 | 426 } // namespace v8 |
OLD | NEW |