Chromium Code Reviews| Index: src/elements.cc |
| diff --git a/src/elements.cc b/src/elements.cc |
| index 10fc1be97b165430e40f833f54deb2f8f2d8ecef..b6dc8dfa82463001e9c0f9f869e37ec4a544e044 100644 |
| --- a/src/elements.cc |
| +++ b/src/elements.cc |
| @@ -603,7 +603,7 @@ class ElementsAccessorBase : public ElementsAccessor { |
| static bool HasElementImpl(Isolate* isolate, Handle<JSObject> holder, |
| uint32_t index, |
| Handle<FixedArrayBase> backing_store, |
| - PropertyFilter filter) { |
| + PropertyFilter filter = ALL_PROPERTIES) { |
| return Subclass::GetEntryForIndexImpl(isolate, *holder, *backing_store, |
| index, filter) != kMaxUInt32; |
| } |
| @@ -618,15 +618,16 @@ class ElementsAccessorBase : public ElementsAccessor { |
| } |
| Handle<Object> Get(Handle<JSObject> holder, uint32_t entry) final { |
| - return Subclass::GetImpl(holder, entry); |
| + return Subclass::GetInternalImpl(holder, entry); |
| } |
| - static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { |
| - return Subclass::GetImpl(holder->elements(), entry); |
| + static Handle<Object> GetInternalImpl(Handle<JSObject> holder, |
| + uint32_t entry) { |
| + return Subclass::GetImpl(holder->GetIsolate(), holder->elements(), entry); |
| } |
| - static Handle<Object> GetImpl(FixedArrayBase* backing_store, uint32_t entry) { |
| - Isolate* isolate = backing_store->GetIsolate(); |
| + static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* backing_store, |
| + uint32_t entry) { |
| uint32_t index = GetIndexForEntryImpl(backing_store, entry); |
| return handle(BackingStore::cast(backing_store)->get(index), isolate); |
| } |
| @@ -1016,8 +1017,8 @@ class ElementsAccessorBase : public ElementsAccessor { |
| int count = 0; |
| KeyAccumulator accumulator(isolate, KeyCollectionMode::kOwnOnly, |
| ALL_PROPERTIES); |
| - Subclass::CollectElementIndicesImpl( |
| - object, handle(object->elements(), isolate), &accumulator); |
| + Handle<FixedArrayBase> elements(object->elements(), isolate); |
| + Subclass::CollectElementIndicesImpl(object, elements, &accumulator); |
| Handle<FixedArray> keys = accumulator.GetKeys(); |
| for (int i = 0; i < keys->length(); ++i) { |
| @@ -1026,14 +1027,14 @@ class ElementsAccessorBase : public ElementsAccessor { |
| uint32_t index; |
| if (!key->ToUint32(&index)) continue; |
| - uint32_t entry = Subclass::GetEntryForIndexImpl( |
| - isolate, *object, object->elements(), index, filter); |
| + uint32_t entry = Subclass::GetEntryForIndexImpl(isolate, *object, |
| + *elements, index, filter); |
| if (entry == kMaxUInt32) continue; |
| PropertyDetails details = Subclass::GetDetailsImpl(*object, entry); |
| if (details.kind() == kData) { |
| - value = Subclass::GetImpl(object, entry); |
| + value = Subclass::GetImpl(isolate, *elements, entry); |
| } else { |
| LookupIterator it(isolate, object, index, LookupIterator::OWN); |
| ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| @@ -1258,6 +1259,17 @@ class ElementsAccessorBase : public ElementsAccessor { |
| return Subclass::GetDetailsImpl(holder, entry); |
| } |
| + Handle<FixedArray> CreateListFromArrayLike(Isolate* isolate, |
| + Handle<JSArray> array) final { |
| + return Subclass::CreateListFromArrayLikeImpl(isolate, array); |
| + }; |
| + |
| + static Handle<FixedArray> CreateListFromArrayLikeImpl(Isolate* isolate, |
| + Handle<JSArray> array) { |
| + UNREACHABLE(); |
| + return Handle<FixedArray>(); |
| + } |
| + |
| private: |
| DISALLOW_COPY_AND_ASSIGN(ElementsAccessorBase); |
| }; |
| @@ -1383,12 +1395,9 @@ class DictionaryElementsAccessor |
| return backing_store->ValueAt(entry); |
| } |
| - static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { |
| - return GetImpl(holder->elements(), entry); |
| - } |
| - |
| - static Handle<Object> GetImpl(FixedArrayBase* backing_store, uint32_t entry) { |
| - return handle(GetRaw(backing_store, entry), backing_store->GetIsolate()); |
| + static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* backing_store, |
| + uint32_t entry) { |
| + return handle(GetRaw(backing_store, entry), isolate); |
| } |
| static inline void SetImpl(Handle<JSObject> holder, uint32_t entry, |
| @@ -1771,7 +1780,7 @@ class FastElementsAccessor : public ElementsAccessorBase<Subclass, KindTraits> { |
| if (IsHoleyElementsKind(kind)) { |
| if (BackingStore::cast(*store)->is_the_hole(isolate, i)) continue; |
| } |
| - Handle<Object> value = Subclass::GetImpl(*store, i); |
| + Handle<Object> value = Subclass::GetImpl(isolate, *store, i); |
| dictionary = SeededNumberDictionary::AddNumberEntry( |
| dictionary, i, value, details, used_as_prototype); |
| j++; |
| @@ -1932,7 +1941,7 @@ class FastElementsAccessor : public ElementsAccessorBase<Subclass, KindTraits> { |
| for (uint32_t i = 0; i < length; i++) { |
| if (IsFastPackedElementsKind(KindTraits::Kind) || |
| HasEntryImpl(isolate, *elements, i)) { |
| - accumulator->AddKey(Subclass::GetImpl(*elements, i), convert); |
| + accumulator->AddKey(Subclass::GetImpl(isolate, *elements, i), convert); |
| } |
| } |
| } |
| @@ -2073,7 +2082,7 @@ class FastElementsAccessor : public ElementsAccessorBase<Subclass, KindTraits> { |
| uint32_t length = elements->length(); |
| for (uint32_t index = 0; index < length; ++index) { |
| if (!HasEntryImpl(isolate, *elements, index)) continue; |
| - Handle<Object> value = Subclass::GetImpl(*elements, index); |
| + Handle<Object> value = Subclass::GetImpl(isolate, *elements, index); |
| if (get_entries) { |
| value = MakeEntryPair(isolate, index, value); |
| } |
| @@ -2263,6 +2272,24 @@ class FastElementsAccessor : public ElementsAccessorBase<Subclass, KindTraits> { |
| } |
| } |
| + static Handle<FixedArray> CreateListFromArrayLikeImpl(Isolate* isolate, |
| + Handle<JSArray> array) { |
| + uint32_t length = 0; |
| + array->length()->ToArrayLength(&length); |
| + Handle<FixedArray> result = isolate->factory()->NewFixedArray(length); |
| + Handle<FixedArrayBase> elements(array->elements(), isolate); |
| + for (int i = 0; i < elements->length(); i++) { |
|
Jakob Kummerow
2016/11/24 10:55:16
s/elements->length()/length/ for a minor gain in e
|
| + if (!Subclass::HasElementImpl(isolate, array, i, elements)) continue; |
| + Handle<Object> value; |
| + value = Subclass::GetImpl(isolate, *elements, i); |
| + if (value->IsName()) { |
| + value = isolate->factory()->InternalizeName(Handle<Name>::cast(value)); |
| + } |
| + result->set(i, *value); |
| + } |
| + return result; |
| + } |
| + |
| private: |
| // SpliceShrinkStep might modify the backing_store. |
| static void SpliceShrinkStep(Isolate* isolate, Handle<JSArray> receiver, |
| @@ -2321,7 +2348,8 @@ class FastElementsAccessor : public ElementsAccessorBase<Subclass, KindTraits> { |
| DCHECK(length > 0); |
| int new_length = length - 1; |
| int remove_index = remove_position == AT_START ? 0 : new_length; |
| - Handle<Object> result = Subclass::GetImpl(*backing_store, remove_index); |
| + Handle<Object> result = |
| + Subclass::GetImpl(isolate, *backing_store, remove_index); |
| if (remove_position == AT_START) { |
| Subclass::MoveElements(isolate, receiver, backing_store, 0, 1, new_length, |
| 0, 0); |
| @@ -2542,12 +2570,8 @@ class FastDoubleElementsAccessor |
| explicit FastDoubleElementsAccessor(const char* name) |
| : FastElementsAccessor<Subclass, KindTraits>(name) {} |
| - static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { |
| - return GetImpl(holder->elements(), entry); |
| - } |
| - |
| - static Handle<Object> GetImpl(FixedArrayBase* backing_store, uint32_t entry) { |
| - Isolate* isolate = backing_store->GetIsolate(); |
| + static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* backing_store, |
| + uint32_t entry) { |
| return FixedDoubleArray::get(FixedDoubleArray::cast(backing_store), entry, |
| isolate); |
| } |
| @@ -2694,11 +2718,8 @@ class TypedElementsAccessor |
| BackingStore::cast(backing_store)->SetValue(entry, value); |
| } |
| - static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { |
| - return GetImpl(holder->elements(), entry); |
| - } |
| - |
| - static Handle<Object> GetImpl(FixedArrayBase* backing_store, uint32_t entry) { |
| + static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* backing_store, |
| + uint32_t entry) { |
| return BackingStore::get(BackingStore::cast(backing_store), entry); |
| } |
| @@ -2762,10 +2783,11 @@ class TypedElementsAccessor |
| static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver, |
| KeyAccumulator* accumulator, |
| AddKeyConversion convert) { |
| + Isolate* isolate = receiver->GetIsolate(); |
| Handle<FixedArrayBase> elements(receiver->elements()); |
| uint32_t length = AccessorClass::GetCapacityImpl(*receiver, *elements); |
| for (uint32_t i = 0; i < length; i++) { |
| - Handle<Object> value = AccessorClass::GetImpl(*elements, i); |
| + Handle<Object> value = AccessorClass::GetImpl(isolate, *elements, i); |
| accumulator->AddKey(value, convert); |
| } |
| } |
| @@ -2779,7 +2801,8 @@ class TypedElementsAccessor |
| Handle<FixedArrayBase> elements(object->elements()); |
| uint32_t length = AccessorClass::GetCapacityImpl(*object, *elements); |
| for (uint32_t index = 0; index < length; ++index) { |
| - Handle<Object> value = AccessorClass::GetImpl(*elements, index); |
| + Handle<Object> value = |
| + AccessorClass::GetImpl(isolate, *elements, index); |
| if (get_entries) { |
| value = MakeEntryPair(isolate, index, value); |
| } |
| @@ -2902,12 +2925,8 @@ class SloppyArgumentsElementsAccessor |
| USE(KindTraits::Kind); |
| } |
| - static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { |
| - return GetImpl(holder->elements(), entry); |
| - } |
| - |
| - static Handle<Object> GetImpl(FixedArrayBase* parameters, uint32_t entry) { |
| - Isolate* isolate = parameters->GetIsolate(); |
| + static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* parameters, |
| + uint32_t entry) { |
| Handle<FixedArray> parameter_map(FixedArray::cast(parameters), isolate); |
| uint32_t length = parameter_map->length() - 2; |
| if (entry < length) { |
| @@ -2920,7 +2939,7 @@ class SloppyArgumentsElementsAccessor |
| } else { |
| // Object is not mapped, defer to the arguments. |
| Handle<Object> result = ArgumentsAccessor::GetImpl( |
| - FixedArray::cast(parameter_map->get(1)), entry - length); |
| + isolate, FixedArray::cast(parameter_map->get(1)), entry - length); |
| // Elements of the arguments object in slow mode might be slow aliases. |
| if (result->IsAliasedArgumentsEntry()) { |
| DisallowHeapAllocation no_gc; |
| @@ -3018,7 +3037,7 @@ class SloppyArgumentsElementsAccessor |
| uint32_t length = GetCapacityImpl(*receiver, *elements); |
| for (uint32_t entry = 0; entry < length; entry++) { |
| if (!HasEntryImpl(isolate, *elements, entry)) continue; |
| - Handle<Object> value = GetImpl(*elements, entry); |
| + Handle<Object> value = Subclass::GetImpl(isolate, *elements, entry); |
| accumulator->AddKey(value, convert); |
| } |
| } |
| @@ -3154,7 +3173,8 @@ class SloppyArgumentsElementsAccessor |
| continue; |
| } |
| - Handle<Object> element_k = GetImpl(*parameter_map, entry); |
| + Handle<Object> element_k = |
| + Subclass::GetImpl(isolate, *parameter_map, entry); |
| if (element_k->IsAccessorPair()) { |
| LookupIterator it(isolate, object, k, LookupIterator::OWN); |
| @@ -3193,7 +3213,8 @@ class SloppyArgumentsElementsAccessor |
| continue; |
| } |
| - Handle<Object> element_k = GetImpl(*parameter_map, entry); |
| + Handle<Object> element_k = |
| + Subclass::GetImpl(isolate, *parameter_map, entry); |
| if (element_k->IsAccessorPair()) { |
| LookupIterator it(isolate, object, k, LookupIterator::OWN); |
| @@ -3338,7 +3359,7 @@ class FastSloppyArgumentsElementsAccessor |
| uint32_t entry = GetEntryForIndexImpl(isolate, *receiver, parameters, i, |
| ALL_PROPERTIES); |
| if (entry != kMaxUInt32 && HasEntryImpl(isolate, parameters, entry)) { |
| - elements->set(insertion_index, *GetImpl(parameters, entry)); |
| + elements->set(insertion_index, *GetImpl(isolate, parameters, entry)); |
| } else { |
| elements->set_the_hole(insertion_index); |
| } |
| @@ -3438,6 +3459,11 @@ class StringWrapperElementsAccessor |
| USE(KindTraits::Kind); |
| } |
| + static Handle<Object> GetInternalImpl(Handle<JSObject> holder, |
| + uint32_t entry) { |
| + return GetImpl(holder, entry); |
| + } |
| + |
| static Handle<Object> GetImpl(Handle<JSObject> holder, uint32_t entry) { |
| Isolate* isolate = holder->GetIsolate(); |
| Handle<String> string(GetString(*holder), isolate); |
| @@ -3446,7 +3472,14 @@ class StringWrapperElementsAccessor |
| return isolate->factory()->LookupSingleCharacterStringFromCode( |
| String::Flatten(string)->Get(entry)); |
| } |
| - return BackingStoreAccessor::GetImpl(holder, entry - length); |
| + return BackingStoreAccessor::GetImpl(isolate, holder->elements(), |
| + entry - length); |
| + } |
| + |
| + static Handle<Object> GetImpl(Isolate* isolate, FixedArrayBase* elements, |
| + uint32_t entry) { |
| + UNREACHABLE(); |
| + return Handle<Object>(); |
| } |
| static PropertyDetails GetDetailsImpl(JSObject* holder, uint32_t entry) { |