Chromium Code Reviews| Index: src/elements.cc |
| diff --git a/src/elements.cc b/src/elements.cc |
| index 7f9691bf765fd73382da75a709faedf1e5293367..a8a6e9c09d99a94d6add31673b51a070fd1f2a62 100644 |
| --- a/src/elements.cc |
| +++ b/src/elements.cc |
| @@ -620,7 +620,7 @@ class ElementsAccessorBase : public ElementsAccessor { |
| Handle<JSObject> obj, |
| uint32_t key, |
| Handle<FixedArrayBase> backing_store) { |
| - if (key < ElementsAccessorSubclass::GetCapacityImpl(obj, backing_store)) { |
| + if (key < ElementsAccessorSubclass::GetCapacityImpl(*obj, *backing_store)) { |
| return BackingStore::get(Handle<BackingStore>::cast(backing_store), key); |
| } else { |
| return backing_store->GetIsolate()->factory()->the_hole_value(); |
| @@ -638,7 +638,8 @@ class ElementsAccessorBase : public ElementsAccessor { |
| Handle<JSObject> obj, |
| uint32_t key, |
| Handle<FixedArrayBase> backing_store) { |
| - if (key >= ElementsAccessorSubclass::GetCapacityImpl(obj, backing_store)) { |
| + if (key >= |
| + ElementsAccessorSubclass::GetCapacityImpl(*obj, *backing_store)) { |
| return ABSENT; |
| } |
| return |
| @@ -751,7 +752,7 @@ class ElementsAccessorBase : public ElementsAccessor { |
| // Optimize if 'other' is empty. |
| // We cannot optimize if 'this' is empty, as other may have holes. |
| - uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(holder, from); |
| + uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(*holder, *from); |
| if (len1 == 0) return to; |
| Isolate* isolate = from->GetIsolate(); |
| @@ -759,7 +760,7 @@ class ElementsAccessorBase : public ElementsAccessor { |
| // Compute how many elements are not in other. |
| uint32_t extra = 0; |
| for (uint32_t y = 0; y < len1; y++) { |
| - uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(from, y); |
| + uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(*from, y); |
| if (ElementsAccessorSubclass::HasElementImpl(holder, key, from)) { |
| Handle<Object> value; |
| ASSIGN_RETURN_ON_EXCEPTION( |
| @@ -795,8 +796,7 @@ class ElementsAccessorBase : public ElementsAccessor { |
| // Fill in the extra values. |
| uint32_t index = 0; |
| for (uint32_t y = 0; y < len1; y++) { |
| - uint32_t key = |
| - ElementsAccessorSubclass::GetKeyForIndexImpl(from, y); |
| + uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(*from, y); |
| if (ElementsAccessorSubclass::HasElementImpl(holder, key, from)) { |
| Handle<Object> value; |
| ASSIGN_RETURN_ON_EXCEPTION( |
| @@ -817,26 +817,45 @@ class ElementsAccessorBase : public ElementsAccessor { |
| } |
| protected: |
| - static uint32_t GetCapacityImpl(Handle<JSObject> holder, |
| - Handle<FixedArrayBase> backing_store) { |
| + static uint32_t GetCapacityImpl(JSObject* holder, |
| + FixedArrayBase* backing_store) { |
| return backing_store->length(); |
| } |
| - uint32_t GetCapacity(Handle<JSObject> holder, |
| - Handle<FixedArrayBase> backing_store) final { |
| + uint32_t GetCapacity(JSObject* holder, FixedArrayBase* backing_store) final { |
| return ElementsAccessorSubclass::GetCapacityImpl(holder, backing_store); |
| } |
| - static uint32_t GetKeyForIndexImpl(Handle<FixedArrayBase> backing_store, |
| + static uint32_t GetKeyForIndexImpl(FixedArrayBase* backing_store, |
| uint32_t index) { |
| return index; |
| } |
| - virtual uint32_t GetKeyForIndex(Handle<FixedArrayBase> backing_store, |
| + virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store, |
| uint32_t index) final { |
| return ElementsAccessorSubclass::GetKeyForIndexImpl(backing_store, index); |
| } |
| + static uint32_t GetIndexForKeyImpl(FixedArrayBase* backing_store, |
| + uint32_t key) { |
| + return key; |
| + } |
| + |
| + virtual uint32_t GetIndexForKey(FixedArrayBase* backing_store, |
| + uint32_t key) final { |
| + return ElementsAccessorSubclass::GetIndexForKeyImpl(backing_store, key); |
| + } |
| + |
| + static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store, |
| + uint32_t index) { |
| + return PropertyDetails(NONE, DATA, 0, PropertyCellType::kNoCell); |
| + } |
| + |
| + virtual PropertyDetails GetDetails(FixedArrayBase* backing_store, |
| + uint32_t index) final { |
| + return ElementsAccessorSubclass::GetDetailsImpl(backing_store, index); |
| + } |
| + |
| private: |
| DISALLOW_COPY_AND_ASSIGN(ElementsAccessorBase); |
| }; |
| @@ -1262,7 +1281,7 @@ class TypedElementsAccessor |
| Handle<JSObject> obj, |
| uint32_t key, |
| Handle<FixedArrayBase> backing_store) { |
| - if (key < AccessorClass::GetCapacityImpl(obj, backing_store)) { |
| + if (key < AccessorClass::GetCapacityImpl(*obj, *backing_store)) { |
| return BackingStore::get(Handle<BackingStore>::cast(backing_store), key); |
| } else { |
| return backing_store->GetIsolate()->factory()->undefined_value(); |
| @@ -1273,8 +1292,8 @@ class TypedElementsAccessor |
| Handle<JSObject> obj, |
| uint32_t key, |
| Handle<FixedArrayBase> backing_store) { |
| - return key < AccessorClass::GetCapacityImpl(obj, backing_store) ? NONE |
| - : ABSENT; |
| + return key < AccessorClass::GetCapacityImpl(*obj, *backing_store) ? NONE |
| + : ABSENT; |
| } |
| MUST_USE_RESULT static MaybeHandle<Object> SetLengthImpl( |
| @@ -1294,13 +1313,13 @@ class TypedElementsAccessor |
| static bool HasElementImpl(Handle<JSObject> holder, uint32_t key, |
| Handle<FixedArrayBase> backing_store) { |
| - uint32_t capacity = AccessorClass::GetCapacityImpl(holder, backing_store); |
| + uint32_t capacity = AccessorClass::GetCapacityImpl(*holder, *backing_store); |
| return key < capacity; |
| } |
| - static uint32_t GetCapacityImpl(Handle<JSObject> holder, |
| - Handle<FixedArrayBase> backing_store) { |
| - Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); |
| + static uint32_t GetCapacityImpl(JSObject* holder, |
| + FixedArrayBase* backing_store) { |
| + JSArrayBufferView* view = JSArrayBufferView::cast(holder); |
| if (view->WasNeutered()) return 0; |
| return backing_store->length(); |
| } |
| @@ -1502,14 +1521,27 @@ class DictionaryElementsAccessor |
| return backing_store->FindEntry(key) != SeededNumberDictionary::kNotFound; |
| } |
| - static uint32_t GetKeyForIndexImpl(Handle<FixedArrayBase> store, |
| - uint32_t index) { |
| + static uint32_t GetKeyForIndexImpl(FixedArrayBase* store, uint32_t index) { |
| DisallowHeapAllocation no_gc; |
| - Handle<SeededNumberDictionary> dict = |
| - Handle<SeededNumberDictionary>::cast(store); |
| + SeededNumberDictionary* dict = SeededNumberDictionary::cast(store); |
| Object* key = dict->KeyAt(index); |
| return Smi::cast(key)->value(); |
| } |
| + |
| + static uint32_t GetIndexForKeyImpl(FixedArrayBase* store, uint32_t index) { |
|
Jakob Kummerow
2015/05/19 17:01:14
nit: "...ForKey..." should take a "uint32_t key" p
|
| + DisallowHeapAllocation no_gc; |
| + SeededNumberDictionary* dict = SeededNumberDictionary::cast(store); |
| + int entry = dict->FindEntry(index); |
| + if (entry == SeededNumberDictionary::kNotFound) { |
| + return kMaxUInt32; |
| + } |
| + return static_cast<uint32_t>(entry); |
| + } |
| + |
| + static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store, |
| + uint32_t index) { |
| + return SeededNumberDictionary::cast(backing_store)->DetailsAt(index); |
| + } |
| }; |
| @@ -1639,20 +1671,28 @@ class SloppyArgumentsElementsAccessor : public ElementsAccessorBase< |
| UNREACHABLE(); |
| } |
| - static uint32_t GetCapacityImpl(Handle<JSObject> holder, |
| - Handle<FixedArrayBase> backing_store) { |
| - Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(backing_store); |
| - Handle<FixedArrayBase> arguments( |
| - FixedArrayBase::cast(parameter_map->get(1))); |
| + static uint32_t GetCapacityImpl(JSObject* holder, |
| + FixedArrayBase* backing_store) { |
| + FixedArray* parameter_map = FixedArray::cast(backing_store); |
| + FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); |
| return Max(static_cast<uint32_t>(parameter_map->length() - 2), |
| ForArray(arguments)->GetCapacity(holder, arguments)); |
| } |
| - static uint32_t GetKeyForIndexImpl(Handle<FixedArrayBase> dict, |
| - uint32_t index) { |
| + static uint32_t GetKeyForIndexImpl(FixedArrayBase* dict, uint32_t index) { |
| return index; |
| } |
| + static uint32_t GetIndexForKeyImpl(FixedArrayBase* dict, uint32_t key) { |
| + return key; |
| + } |
| + |
| + static PropertyDetails GetDetailsImpl(FixedArrayBase* backing_store, |
| + uint32_t index) { |
| + return PropertyDetails(NONE, DATA, 0, PropertyCellType::kNoCell); |
| + } |
| + |
| + |
| private: |
| static Handle<Object> GetParameterMapArg(Handle<JSObject> holder, |
| Handle<FixedArray> parameter_map, |
| @@ -1668,8 +1708,13 @@ class SloppyArgumentsElementsAccessor : public ElementsAccessorBase< |
| }; |
| +ElementsAccessor* ElementsAccessor::ForArray(FixedArrayBase* array) { |
| + return elements_accessors_[ElementsKindForArray(array)]; |
| +} |
| + |
| + |
| ElementsAccessor* ElementsAccessor::ForArray(Handle<FixedArrayBase> array) { |
| - return elements_accessors_[ElementsKindForArray(*array)]; |
| + return ForArray(*array); |
| } |