From: ishell@chromium.org Date: Fri, 21 Mar 2014 08:12:16 +0000 (+0000) Subject: ArrayUnshift builtin handlified. X-Git-Tag: upstream/4.7.83~10108 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=863b5d30cd1d75df7e902d8b81bfb768e9ec6c30;p=platform%2Fupstream%2Fv8.git 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 --- diff --git a/src/builtins.cc b/src/builtins.cc index be9051c..031d054 100644 --- a/src/builtins.cc +++ b/src/builtins.cc @@ -625,24 +625,24 @@ BUILTIN(ArrayShift) { BUILTIN(ArrayUnshift) { + HandleScope scope(isolate); Heap* heap = isolate->heap(); - Object* receiver = *args.receiver(); - FixedArrayBase* elms_obj; - MaybeObject* maybe_elms_obj = - EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); - if (maybe_elms_obj == NULL) - return CallJsBuiltin(isolate, "ArrayUnshift", args); - if (!maybe_elms_obj->To(&elms_obj)) return maybe_elms_obj; - - if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { + Handle receiver = args.receiver(); + Handle elms_or_null = + EnsureJSArrayWithWritableFastElementsWrapper(isolate, receiver, NULL, 0); + RETURN_IF_EMPTY_HANDLE(isolate, elms_or_null); + if ((*elms_or_null == NULL) || + !IsJSArrayFastElementMovingAllowed(heap, + *Handle::cast(receiver))) { return CallJsBuiltin(isolate, "ArrayUnshift", args); } - JSArray* array = JSArray::cast(receiver); + Handle elms_obj = Handle::cast(elms_or_null); + Handle array = Handle::cast(receiver); ASSERT(!array->map()->is_observed()); if (!array->HasFastSmiOrObjectElements()) { return CallJsBuiltin(isolate, "ArrayUnshift", args); } - FixedArray* elms = FixedArray::cast(elms_obj); + Handle elms = Handle::cast(elms_obj); int len = Smi::cast(array->length())->value(); int to_add = args.length() - 1; @@ -651,31 +651,26 @@ BUILTIN(ArrayUnshift) { // we should never hit this case. ASSERT(to_add <= (Smi::kMaxValue - len)); - MaybeObject* maybe_object = - array->EnsureCanContainElements(&args, 1, to_add, - DONT_ALLOW_DOUBLE_ELEMENTS); - if (maybe_object->IsFailure()) return maybe_object; + JSObject::EnsureCanContainElements(array, &args, 1, to_add, + DONT_ALLOW_DOUBLE_ELEMENTS); if (new_length > elms->length()) { // New backing storage is needed. int capacity = new_length + (new_length >> 1) + 16; - FixedArray* new_elms; - MaybeObject* maybe_elms = heap->AllocateUninitializedFixedArray(capacity); - if (!maybe_elms->To(&new_elms)) return maybe_elms; + Handle new_elms = + isolate->factory()->NewUninitializedFixedArray(capacity); ElementsKind kind = array->GetElementsKind(); ElementsAccessor* accessor = array->GetElementsAccessor(); - MaybeObject* maybe_failure = accessor->CopyElements( - NULL, 0, kind, new_elms, to_add, - ElementsAccessor::kCopyToEndAndInitializeToHole, elms); - ASSERT(!maybe_failure->IsFailure()); - USE(maybe_failure); + accessor->CopyElements( + Handle::null(), 0, kind, new_elms, to_add, + ElementsAccessor::kCopyToEndAndInitializeToHole, elms); elms = new_elms; - array->set_elements(elms); + array->set_elements(*elms); } else { DisallowHeapAllocation no_gc; - heap->MoveElements(elms, to_add, 0, len); + heap->MoveElements(*elms, to_add, 0, len); } // Add the provided values.