Commit ca8134c8 authored by cbruni's avatar cbruni Committed by Commit bot

Adding ElementsAccessor::Pop

Moving FastElements path to ElementsAccessor.

BUG=

Review URL: https://codereview.chromium.org/1325483002

Cr-Commit-Position: refs/heads/master@{#30477}
parent 8ff59e8d
......@@ -218,7 +218,7 @@ inline bool GetSloppyArgumentsLength(Isolate* isolate, Handle<JSObject> object,
}
bool PrototypeHasNoElements(PrototypeIterator* iter) {
inline bool PrototypeHasNoElements(PrototypeIterator* iter) {
DisallowHeapAllocation no_gc;
for (; !iter->IsAtEnd(); iter->Advance()) {
if (iter->GetCurrent()->IsJSProxy()) return false;
......@@ -396,13 +396,18 @@ BUILTIN(ArrayPop) {
return CallJsIntrinsic(isolate, isolate->array_pop(), args);
}
uint32_t new_length = len - 1;
Handle<Object> element;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, element, Object::GetElement(isolate, array, new_length));
JSArray::SetLength(array, new_length);
return *element;
Handle<Object> result;
if (IsJSArrayFastElementMovingAllowed(isolate, JSArray::cast(*receiver))) {
// Fast Elements Path
result = array->GetElementsAccessor()->Pop(array, elms_obj);
} else {
// Use Slow Lookup otherwise
uint32_t new_length = len - 1;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result, Object::GetElement(isolate, array, new_length));
JSArray::SetLength(array, new_length);
}
return *result;
}
......
......@@ -158,9 +158,8 @@ inline bool IsHoleyElementsKind(ElementsKind kind) {
inline bool IsFastPackedElementsKind(ElementsKind kind) {
return kind == FAST_SMI_ELEMENTS ||
kind == FAST_DOUBLE_ELEMENTS ||
kind == FAST_ELEMENTS;
return kind == FAST_SMI_ELEMENTS || kind == FAST_DOUBLE_ELEMENTS ||
kind == FAST_ELEMENTS;
}
......
......@@ -639,6 +639,16 @@ class ElementsAccessorBase : public ElementsAccessor {
return Handle<JSArray>();
}
virtual Handle<Object> Pop(Handle<JSArray> receiver,
Handle<FixedArrayBase> backing_store) final {
return ElementsAccessorSubclass::PopImpl(receiver, backing_store);
}
static Handle<Object> PopImpl(Handle<JSArray> receiver,
Handle<FixedArrayBase> backing_store) {
UNREACHABLE();
return Handle<Object>();
}
virtual void SetLength(Handle<JSArray> array, uint32_t length) final {
ElementsAccessorSubclass::SetLengthImpl(array, length,
......@@ -1219,6 +1229,21 @@ class FastElementsAccessor
#endif
}
static Handle<Object> PopImpl(Handle<JSArray> receiver,
Handle<FixedArrayBase> backing_store) {
uint32_t new_length =
static_cast<uint32_t>(Smi::cast(receiver->length())->value()) - 1;
Handle<Object> result =
FastElementsAccessorSubclass::GetImpl(backing_store, new_length);
FastElementsAccessorSubclass::SetLengthImpl(receiver, new_length,
backing_store);
if (IsHoleyElementsKind(KindTraits::Kind) && result->IsTheHole()) {
result = receiver->GetIsolate()->factory()->undefined_value();
}
return result;
}
static uint32_t PushImpl(Handle<JSArray> receiver,
Handle<FixedArrayBase> backing_store,
Object** objects, uint32_t push_size,
......
......@@ -145,6 +145,9 @@ class ElementsAccessor {
uint32_t start, uint32_t delete_count,
Arguments args, uint32_t add_count) = 0;
virtual Handle<Object> Pop(Handle<JSArray> receiver,
Handle<FixedArrayBase> backing_store) = 0;
protected:
friend class LookupIterator;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment