Index: src/elements.cc |
diff --git a/src/elements.cc b/src/elements.cc |
index 7109342902bd6d6bbbd64dc1cb98ba1988023769..54988dc081b744a95a96a14488025983ffc8be6b 100644 |
--- a/src/elements.cc |
+++ b/src/elements.cc |
@@ -503,12 +503,6 @@ class ElementsAccessorBase : public ElementsAccessor { |
ElementsAccessorSubclass::ValidateImpl(holder); |
} |
- bool IsPacked(Handle<JSObject> holder, Handle<FixedArrayBase> backing_store, |
- uint32_t start, uint32_t end) final { |
- return ElementsAccessorSubclass::IsPackedImpl(holder, backing_store, start, |
- end); |
- } |
- |
static bool IsPackedImpl(Handle<JSObject> holder, |
Handle<FixedArrayBase> backing_store, uint32_t start, |
uint32_t end) { |
@@ -598,81 +592,67 @@ class ElementsAccessorBase : public ElementsAccessor { |
UNREACHABLE(); |
} |
- uint32_t Push(Handle<JSArray> receiver, Handle<FixedArrayBase> backing_store, |
- Arguments* args, uint32_t push_size) final { |
- return ElementsAccessorSubclass::PushImpl(receiver, backing_store, args, |
- push_size); |
+ uint32_t Push(Handle<JSArray> receiver, Arguments* args, |
+ uint32_t push_size) final { |
+ return ElementsAccessorSubclass::PushImpl(receiver, args, push_size); |
} |
- static uint32_t PushImpl(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> elms_obj, Arguments* args, |
+ static uint32_t PushImpl(Handle<JSArray> receiver, Arguments* args, |
uint32_t push_sized) { |
UNREACHABLE(); |
return 0; |
} |
- uint32_t Unshift(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> backing_store, Arguments* args, |
+ uint32_t Unshift(Handle<JSArray> receiver, Arguments* args, |
uint32_t unshift_size) final { |
- return ElementsAccessorSubclass::UnshiftImpl(receiver, backing_store, args, |
- unshift_size); |
+ return ElementsAccessorSubclass::UnshiftImpl(receiver, args, unshift_size); |
} |
- static uint32_t UnshiftImpl(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> elms_obj, Arguments* args, |
+ static uint32_t UnshiftImpl(Handle<JSArray> receiver, Arguments* args, |
uint32_t unshift_size) { |
UNREACHABLE(); |
return 0; |
} |
- Handle<JSArray> Slice(Handle<JSObject> receiver, |
- Handle<FixedArrayBase> backing_store, uint32_t start, |
+ Handle<JSArray> Slice(Handle<JSObject> receiver, uint32_t start, |
uint32_t end) final { |
- return ElementsAccessorSubclass::SliceImpl(receiver, backing_store, start, |
- end); |
+ return ElementsAccessorSubclass::SliceImpl(receiver, start, end); |
} |
static Handle<JSArray> SliceImpl(Handle<JSObject> receiver, |
- Handle<FixedArrayBase> backing_store, |
uint32_t start, uint32_t end) { |
UNREACHABLE(); |
return Handle<JSArray>(); |
} |
- Handle<JSArray> Splice(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> backing_store, uint32_t start, |
+ Handle<JSArray> Splice(Handle<JSArray> receiver, uint32_t start, |
uint32_t delete_count, Arguments* args, |
uint32_t add_count) final { |
- return ElementsAccessorSubclass::SpliceImpl(receiver, backing_store, start, |
- delete_count, args, add_count); |
+ return ElementsAccessorSubclass::SpliceImpl(receiver, start, delete_count, |
+ args, add_count); |
} |
static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> backing_store, |
uint32_t start, uint32_t delete_count, |
Arguments* args, uint32_t add_count) { |
UNREACHABLE(); |
return Handle<JSArray>(); |
} |
- Handle<Object> Pop(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> backing_store) final { |
- return ElementsAccessorSubclass::PopImpl(receiver, backing_store); |
+ Handle<Object> Pop(Handle<JSArray> receiver) final { |
+ return ElementsAccessorSubclass::PopImpl(receiver); |
} |
- static Handle<Object> PopImpl(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> backing_store) { |
+ static Handle<Object> PopImpl(Handle<JSArray> receiver) { |
UNREACHABLE(); |
return Handle<Object>(); |
} |
- Handle<Object> Shift(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> backing_store) final { |
- return ElementsAccessorSubclass::ShiftImpl(receiver, backing_store); |
+ Handle<Object> Shift(Handle<JSArray> receiver) final { |
+ return ElementsAccessorSubclass::ShiftImpl(receiver); |
} |
- static Handle<Object> ShiftImpl(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> backing_store) { |
+ static Handle<Object> ShiftImpl(Handle<JSArray> receiver) { |
UNREACHABLE(); |
return Handle<Object>(); |
} |
@@ -704,7 +684,7 @@ class ElementsAccessorBase : public ElementsAccessor { |
if (length == 0) { |
array->initialize_elements(); |
} else if (length <= capacity) { |
- if (array->HasFastSmiOrObjectElements()) { |
+ if (IsFastSmiOrObjectElementsKind(kind())) { |
JSObject::EnsureWritableFastElements(array); |
if (array->elements() != *backing_store) { |
backing_store = handle(array->elements(), isolate); |
@@ -1358,28 +1338,24 @@ class FastElementsAccessor |
#endif |
} |
- static Handle<Object> PopImpl(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> backing_store) { |
- return FastElementsAccessorSubclass::RemoveElement(receiver, backing_store, |
- AT_END); |
+ static Handle<Object> PopImpl(Handle<JSArray> receiver) { |
+ return FastElementsAccessorSubclass::RemoveElement(receiver, AT_END); |
} |
- static Handle<Object> ShiftImpl(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> backing_store) { |
- return FastElementsAccessorSubclass::RemoveElement(receiver, backing_store, |
- AT_START); |
+ static Handle<Object> ShiftImpl(Handle<JSArray> receiver) { |
+ return FastElementsAccessorSubclass::RemoveElement(receiver, AT_START); |
} |
static uint32_t PushImpl(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> backing_store, |
Arguments* args, uint32_t push_size) { |
+ Handle<FixedArrayBase> backing_store(receiver->elements()); |
return FastElementsAccessorSubclass::AddArguments(receiver, backing_store, |
args, push_size, AT_END); |
} |
static uint32_t UnshiftImpl(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> backing_store, |
Arguments* args, uint32_t unshift_size) { |
+ Handle<FixedArrayBase> backing_store(receiver->elements()); |
return FastElementsAccessorSubclass::AddArguments( |
receiver, backing_store, args, unshift_size, AT_START); |
} |
@@ -1392,11 +1368,10 @@ class FastElementsAccessor |
} |
static Handle<JSArray> SliceImpl(Handle<JSObject> receiver, |
- Handle<FixedArrayBase> backing_store, |
uint32_t start, uint32_t end) { |
- DCHECK(start < end); |
Isolate* isolate = receiver->GetIsolate(); |
- int result_len = end - start; |
+ Handle<FixedArrayBase> backing_store(receiver->elements(), isolate); |
+ int result_len = end < start ? 0u : end - start; |
Handle<JSArray> result_array = isolate->factory()->NewJSArray( |
KindTraits::Kind, result_len, result_len); |
DisallowHeapAllocation no_gc; |
@@ -1409,7 +1384,6 @@ class FastElementsAccessor |
} |
static Handle<JSArray> SpliceImpl(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> backing_store, |
uint32_t start, uint32_t delete_count, |
Arguments* args, uint32_t add_count) { |
Isolate* isolate = receiver->GetIsolate(); |
@@ -1417,6 +1391,15 @@ class FastElementsAccessor |
uint32_t length = Smi::cast(receiver->length())->value(); |
uint32_t new_length = length - delete_count + add_count; |
+ ElementsKind kind = KindTraits::Kind; |
+ if (new_length <= static_cast<uint32_t>(receiver->elements()->length()) && |
+ IsFastSmiOrObjectElementsKind(kind)) { |
+ HandleScope scope(isolate); |
+ JSObject::EnsureWritableFastElements(receiver); |
+ } |
+ |
+ Handle<FixedArrayBase> backing_store(receiver->elements(), isolate); |
+ |
if (new_length == 0) { |
receiver->set_elements(heap->empty_fixed_array()); |
receiver->set_length(Smi::FromInt(0)); |
@@ -1501,9 +1484,14 @@ class FastElementsAccessor |
} |
static Handle<Object> RemoveElement(Handle<JSArray> receiver, |
- Handle<FixedArrayBase> backing_store, |
Where remove_position) { |
Isolate* isolate = receiver->GetIsolate(); |
+ ElementsKind kind = KindTraits::Kind; |
+ if (IsFastSmiOrObjectElementsKind(kind)) { |
+ HandleScope scope(isolate); |
+ JSObject::EnsureWritableFastElements(receiver); |
+ } |
+ Handle<FixedArrayBase> backing_store(receiver->elements(), isolate); |
uint32_t length = |
static_cast<uint32_t>(Smi::cast(receiver->length())->value()); |
DCHECK(length > 0); |
@@ -1518,8 +1506,8 @@ class FastElementsAccessor |
FastElementsAccessorSubclass::SetLengthImpl(isolate, receiver, new_length, |
backing_store); |
- if (IsHoleyElementsKind(KindTraits::Kind) && result->IsTheHole()) { |
- return receiver->GetIsolate()->factory()->undefined_value(); |
+ if (IsHoleyElementsKind(kind) && result->IsTheHole()) { |
+ return isolate->factory()->undefined_value(); |
} |
return result; |
} |
@@ -1529,7 +1517,7 @@ class FastElementsAccessor |
Arguments* args, uint32_t add_size, |
Where remove_position) { |
uint32_t length = Smi::cast(receiver->length())->value(); |
- DCHECK(add_size > 0); |
+ DCHECK(0 < add_size); |
uint32_t elms_len = backing_store->length(); |
// Check we do not overflow the new_length. |
DCHECK(add_size <= static_cast<uint32_t>(Smi::kMaxValue - length)); |
@@ -1938,8 +1926,7 @@ class TypedElementsAccessor |
static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver, |
KeyAccumulator* accumulator, |
AddKeyConversion convert) { |
- Handle<FixedArrayBase> elements(receiver->elements(), |
- 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); |