Skip to content

Commit

Permalink
Adding ElementsAccessor::Pop
Browse files Browse the repository at this point in the history
Moving FastElements path to ElementsAccessor.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#30477}
  • Loading branch information
camillobruni authored and Commit bot committed Aug 31, 2015
1 parent 8ff59e8 commit ca8134c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
21 changes: 13 additions & 8 deletions src/builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}


Expand Down
5 changes: 2 additions & 3 deletions src/elements-kind.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
25 changes: 25 additions & 0 deletions src/elements.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit ca8134c

Please sign in to comment.