Commit 863b5d30 authored by ishell@chromium.org's avatar ishell@chromium.org

ArrayUnshift builtin handlified.

R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20143 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 586f64e1
...@@ -625,24 +625,24 @@ BUILTIN(ArrayShift) { ...@@ -625,24 +625,24 @@ BUILTIN(ArrayShift) {
BUILTIN(ArrayUnshift) { BUILTIN(ArrayUnshift) {
HandleScope scope(isolate);
Heap* heap = isolate->heap(); Heap* heap = isolate->heap();
Object* receiver = *args.receiver(); Handle<Object> receiver = args.receiver();
FixedArrayBase* elms_obj; Handle<Object> elms_or_null =
MaybeObject* maybe_elms_obj = EnsureJSArrayWithWritableFastElementsWrapper(isolate, receiver, NULL, 0);
EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); RETURN_IF_EMPTY_HANDLE(isolate, elms_or_null);
if (maybe_elms_obj == NULL) if ((*elms_or_null == NULL) ||
return CallJsBuiltin(isolate, "ArrayUnshift", args); !IsJSArrayFastElementMovingAllowed(heap,
if (!maybe_elms_obj->To(&elms_obj)) return maybe_elms_obj; *Handle<JSArray>::cast(receiver))) {
if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) {
return CallJsBuiltin(isolate, "ArrayUnshift", args); return CallJsBuiltin(isolate, "ArrayUnshift", args);
} }
JSArray* array = JSArray::cast(receiver); Handle<FixedArrayBase> elms_obj = Handle<FixedArrayBase>::cast(elms_or_null);
Handle<JSArray> array = Handle<JSArray>::cast(receiver);
ASSERT(!array->map()->is_observed()); ASSERT(!array->map()->is_observed());
if (!array->HasFastSmiOrObjectElements()) { if (!array->HasFastSmiOrObjectElements()) {
return CallJsBuiltin(isolate, "ArrayUnshift", args); return CallJsBuiltin(isolate, "ArrayUnshift", args);
} }
FixedArray* elms = FixedArray::cast(elms_obj); Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj);
int len = Smi::cast(array->length())->value(); int len = Smi::cast(array->length())->value();
int to_add = args.length() - 1; int to_add = args.length() - 1;
...@@ -651,31 +651,26 @@ BUILTIN(ArrayUnshift) { ...@@ -651,31 +651,26 @@ BUILTIN(ArrayUnshift) {
// we should never hit this case. // we should never hit this case.
ASSERT(to_add <= (Smi::kMaxValue - len)); ASSERT(to_add <= (Smi::kMaxValue - len));
MaybeObject* maybe_object = JSObject::EnsureCanContainElements(array, &args, 1, to_add,
array->EnsureCanContainElements(&args, 1, to_add,
DONT_ALLOW_DOUBLE_ELEMENTS); DONT_ALLOW_DOUBLE_ELEMENTS);
if (maybe_object->IsFailure()) return maybe_object;
if (new_length > elms->length()) { if (new_length > elms->length()) {
// New backing storage is needed. // New backing storage is needed.
int capacity = new_length + (new_length >> 1) + 16; int capacity = new_length + (new_length >> 1) + 16;
FixedArray* new_elms; Handle<FixedArray> new_elms =
MaybeObject* maybe_elms = heap->AllocateUninitializedFixedArray(capacity); isolate->factory()->NewUninitializedFixedArray(capacity);
if (!maybe_elms->To(&new_elms)) return maybe_elms;
ElementsKind kind = array->GetElementsKind(); ElementsKind kind = array->GetElementsKind();
ElementsAccessor* accessor = array->GetElementsAccessor(); ElementsAccessor* accessor = array->GetElementsAccessor();
MaybeObject* maybe_failure = accessor->CopyElements( accessor->CopyElements(
NULL, 0, kind, new_elms, to_add, Handle<JSObject>::null(), 0, kind, new_elms, to_add,
ElementsAccessor::kCopyToEndAndInitializeToHole, elms); ElementsAccessor::kCopyToEndAndInitializeToHole, elms);
ASSERT(!maybe_failure->IsFailure());
USE(maybe_failure);
elms = new_elms; elms = new_elms;
array->set_elements(elms); array->set_elements(*elms);
} else { } else {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
heap->MoveElements(elms, to_add, 0, len); heap->MoveElements(*elms, to_add, 0, len);
} }
// Add the provided values. // Add the provided values.
......
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