| 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 "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/elements.h" |
| 8 #include "src/factory.h" | 9 #include "src/factory.h" |
| 9 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
| 11 #include "src/keys.h" |
| 10 #include "src/objects-inl.h" | 12 #include "src/objects-inl.h" |
| 11 | 13 |
| 12 namespace v8 { | 14 namespace v8 { |
| 13 namespace internal { | 15 namespace internal { |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 // Returns either a FixedArray or, if the given {receiver} has an enum cache | 19 // Returns either a FixedArray or, if the given {receiver} has an enum cache |
| 18 // that contains all enumerable properties of the {receiver} and its prototypes | 20 // that contains all enumerable properties of the {receiver} and its prototypes |
| 19 // have none, the map of the {receiver}. This is used to speed up the check for | 21 // have none, the map of the {receiver}. This is used to speed up the check for |
| 20 // deletions during a for-in. | 22 // deletions during a for-in. |
| 21 MaybeHandle<HeapObject> Enumerate(Handle<JSReceiver> receiver) { | 23 MaybeHandle<HeapObject> Enumerate(Handle<JSReceiver> receiver) { |
| 22 Isolate* const isolate = receiver->GetIsolate(); | 24 Isolate* const isolate = receiver->GetIsolate(); |
| 25 FastKeyAccumulator accumulator(isolate, receiver, INCLUDE_PROTOS, |
| 26 ENUMERABLE_STRINGS); |
| 23 // Test if we have an enum cache for {receiver}. | 27 // Test if we have an enum cache for {receiver}. |
| 24 if (!receiver->IsSimpleEnum()) { | 28 if (!accumulator.is_receiver_simple_enum()) { |
| 25 Handle<FixedArray> keys; | 29 Handle<FixedArray> keys; |
| 26 ASSIGN_RETURN_ON_EXCEPTION( | 30 ASSIGN_RETURN_ON_EXCEPTION(isolate, keys, accumulator.GetKeys(KEEP_NUMBERS), |
| 27 isolate, keys, | 31 HeapObject); |
| 28 JSReceiver::GetKeys(receiver, INCLUDE_PROTOS, ENUMERABLE_STRINGS), | |
| 29 HeapObject); | |
| 30 // Test again, since cache may have been built by GetKeys() calls above. | 32 // Test again, since cache may have been built by GetKeys() calls above. |
| 31 if (!receiver->IsSimpleEnum()) return keys; | 33 if (!accumulator.is_receiver_simple_enum()) return keys; |
| 32 } | 34 } |
| 33 return handle(receiver->map(), isolate); | 35 return handle(receiver->map(), isolate); |
| 34 } | 36 } |
| 35 | 37 |
| 36 | 38 |
| 37 MaybeHandle<Object> Filter(Handle<JSReceiver> receiver, Handle<Object> key) { | 39 MaybeHandle<Object> Filter(Handle<JSReceiver> receiver, Handle<Object> key) { |
| 38 Isolate* const isolate = receiver->GetIsolate(); | 40 Isolate* const isolate = receiver->GetIsolate(); |
| 39 // TODO(turbofan): Fast case for array indices. | |
| 40 Handle<Name> name; | 41 Handle<Name> name; |
| 41 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, Object::ToName(isolate, key), | 42 ASSIGN_RETURN_ON_EXCEPTION(isolate, name, Object::ToName(isolate, key), |
| 42 Object); | 43 Object); |
| 44 // Directly check for elements if the key is a smi and avoid a conversion |
| 45 // roundtrip (Number -> Name -> Number). |
| 46 if (key->IsNumber() && receiver->map()->OnlyHasSimpleProperties()) { |
| 47 Handle<JSObject> object = Handle<JSObject>::cast(receiver); |
| 48 ElementsAccessor* accessor = object->GetElementsAccessor(); |
| 49 DCHECK_LT(key->Number(), kMaxUInt32); |
| 50 if (accessor->HasElement(object, key->Number(), ONLY_ENUMERABLE)) { |
| 51 return name; |
| 52 } |
| 53 } |
| 43 Maybe<bool> result = JSReceiver::HasProperty(receiver, name); | 54 Maybe<bool> result = JSReceiver::HasProperty(receiver, name); |
| 44 MAYBE_RETURN_NULL(result); | 55 MAYBE_RETURN_NULL(result); |
| 45 if (result.FromJust()) return name; | 56 if (result.FromJust()) return name; |
| 46 return isolate->factory()->undefined_value(); | 57 return isolate->factory()->undefined_value(); |
| 47 } | 58 } |
| 48 | 59 |
| 49 } // namespace | 60 } // namespace |
| 50 | 61 |
| 51 | 62 |
| 52 RUNTIME_FUNCTION(Runtime_ForInEnumerate) { | 63 RUNTIME_FUNCTION(Runtime_ForInEnumerate) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 SealHandleScope scope(isolate); | 144 SealHandleScope scope(isolate); |
| 134 DCHECK_EQ(1, args.length()); | 145 DCHECK_EQ(1, args.length()); |
| 135 CONVERT_SMI_ARG_CHECKED(index, 0); | 146 CONVERT_SMI_ARG_CHECKED(index, 0); |
| 136 DCHECK_LE(0, index); | 147 DCHECK_LE(0, index); |
| 137 DCHECK_LT(index, Smi::kMaxValue); | 148 DCHECK_LT(index, Smi::kMaxValue); |
| 138 return Smi::FromInt(index + 1); | 149 return Smi::FromInt(index + 1); |
| 139 } | 150 } |
| 140 | 151 |
| 141 } // namespace internal | 152 } // namespace internal |
| 142 } // namespace v8 | 153 } // namespace v8 |
| OLD | NEW |