From: ishell@chromium.org Date: Thu, 27 Mar 2014 16:41:09 +0000 (+0000) Subject: ElementsAccessor::CopyElements() and its callers handlified. X-Git-Tag: upstream/4.7.83~9963 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a887597e20ec772ec03a1e3825250b1221656a7a;p=platform%2Fupstream%2Fv8.git ElementsAccessor::CopyElements() and its callers handlified. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/212573007 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20312 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/builtins.cc b/src/builtins.cc index 52cf5e4..689e845 100644 --- a/src/builtins.cc +++ b/src/builtins.cc @@ -651,18 +651,19 @@ BUILTIN(ArrayUnshift) { BUILTIN(ArraySlice) { + HandleScope scope(isolate); Heap* heap = isolate->heap(); - Object* receiver = *args.receiver(); - FixedArrayBase* elms; + Handle receiver = args.receiver(); + Handle elms; int len = -1; if (receiver->IsJSArray()) { - JSArray* array = JSArray::cast(receiver); - if (!IsJSArrayFastElementMovingAllowed(heap, array)) { + Handle array = Handle::cast(receiver); + if (!IsJSArrayFastElementMovingAllowed(heap, *array)) { return CallJsBuiltin(isolate, "ArraySlice", args); } if (array->HasFastElements()) { - elms = array->elements(); + elms = handle(array->elements()); } else { return CallJsBuiltin(isolate, "ArraySlice", args); } @@ -671,33 +672,34 @@ BUILTIN(ArraySlice) { } else { // Array.slice(arguments, ...) is quite a common idiom (notably more // than 50% of invocations in Web apps). Treat it in C++ as well. - Map* arguments_map = isolate->context()->native_context()-> - sloppy_arguments_boilerplate()->map(); + Handle arguments_map(isolate->context()->native_context()-> + sloppy_arguments_boilerplate()->map()); bool is_arguments_object_with_fast_elements = receiver->IsJSObject() && - JSObject::cast(receiver)->map() == arguments_map; + Handle::cast(receiver)->map() == *arguments_map; if (!is_arguments_object_with_fast_elements) { return CallJsBuiltin(isolate, "ArraySlice", args); } - JSObject* object = JSObject::cast(receiver); + Handle object = Handle::cast(receiver); if (object->HasFastElements()) { - elms = object->elements(); + elms = handle(object->elements()); } else { return CallJsBuiltin(isolate, "ArraySlice", args); } - Object* len_obj = object->InObjectPropertyAt(Heap::kArgumentsLengthIndex); + Handle len_obj( + object->InObjectPropertyAt(Heap::kArgumentsLengthIndex), isolate); if (!len_obj->IsSmi()) { return CallJsBuiltin(isolate, "ArraySlice", args); } - len = Smi::cast(len_obj)->value(); + len = Handle::cast(len_obj)->value(); if (len > elms->length()) { return CallJsBuiltin(isolate, "ArraySlice", args); } } - JSObject* object = JSObject::cast(receiver); + Handle object = Handle::cast(receiver); ASSERT(len >= 0); int n_arguments = args.length() - 1; @@ -708,11 +710,11 @@ BUILTIN(ArraySlice) { int relative_start = 0; int relative_end = len; if (n_arguments > 0) { - Object* arg1 = args[1]; + Handle arg1 = args.at(1); if (arg1->IsSmi()) { - relative_start = Smi::cast(arg1)->value(); + relative_start = Handle::cast(arg1)->value(); } else if (arg1->IsHeapNumber()) { - double start = HeapNumber::cast(arg1)->value(); + double start = Handle::cast(arg1)->value(); if (start < kMinInt || start > kMaxInt) { return CallJsBuiltin(isolate, "ArraySlice", args); } @@ -721,11 +723,11 @@ BUILTIN(ArraySlice) { return CallJsBuiltin(isolate, "ArraySlice", args); } if (n_arguments > 1) { - Object* arg2 = args[2]; + Handle arg2 = args.at(2); if (arg2->IsSmi()) { - relative_end = Smi::cast(arg2)->value(); + relative_end = Handle::cast(arg2)->value(); } else if (arg2->IsHeapNumber()) { - double end = HeapNumber::cast(arg2)->value(); + double end = Handle::cast(arg2)->value(); if (end < kMinInt || end > kMaxInt) { return CallJsBuiltin(isolate, "ArraySlice", args); } @@ -752,7 +754,8 @@ BUILTIN(ArraySlice) { bool packed = true; ElementsAccessor* accessor = ElementsAccessor::ForKind(kind); for (int i = k; i < final; i++) { - if (!accessor->HasElement(object, object, i, elms)) { + if (!ElementsAccessorHasElementWrapper( + accessor, object, object, i, elms)) { packed = false; break; } @@ -764,22 +767,16 @@ BUILTIN(ArraySlice) { } } - JSArray* result_array; - MaybeObject* maybe_array = heap->AllocateJSArrayAndStorage(kind, - result_len, - result_len); + Handle result_array = + isolate->factory()->NewJSArray(kind, result_len, result_len); DisallowHeapAllocation no_gc; - if (result_len == 0) return maybe_array; - if (!maybe_array->To(&result_array)) return maybe_array; + if (result_len == 0) return *result_array; ElementsAccessor* accessor = object->GetElementsAccessor(); - MaybeObject* maybe_failure = accessor->CopyElements( - NULL, k, kind, result_array->elements(), 0, result_len, elms); - ASSERT(!maybe_failure->IsFailure()); - USE(maybe_failure); - - return result_array; + accessor->CopyElements(Handle::null(), k, kind, + handle(result_array->elements()), 0, result_len, elms); + return *result_array; } @@ -994,11 +991,12 @@ BUILTIN(ArraySplice) { BUILTIN(ArrayConcat) { + HandleScope scope(isolate); Heap* heap = isolate->heap(); - Context* native_context = isolate->context()->native_context(); - JSObject* array_proto = - JSObject::cast(native_context->array_function()->prototype()); - if (!ArrayPrototypeHasNoElements(heap, native_context, array_proto)) { + Handle native_context(isolate->context()->native_context()); + Handle array_proto( + JSObject::cast(native_context->array_function()->prototype())); + if (!ArrayPrototypeHasNoElements(heap, *native_context, *array_proto)) { return CallJsBuiltin(isolate, "ArrayConcat", args); } @@ -1010,13 +1008,13 @@ BUILTIN(ArrayConcat) { bool has_double = false; bool is_holey = false; for (int i = 0; i < n_arguments; i++) { - Object* arg = args[i]; + Handle arg = args.at(i); if (!arg->IsJSArray() || - !JSArray::cast(arg)->HasFastElements() || - JSArray::cast(arg)->GetPrototype() != array_proto) { + !Handle::cast(arg)->HasFastElements() || + Handle::cast(arg)->GetPrototype() != *array_proto) { return CallJsBuiltin(isolate, "ArrayConcat", args); } - int len = Smi::cast(JSArray::cast(arg)->length())->value(); + int len = Smi::cast(Handle::cast(arg)->length())->value(); // We shouldn't overflow when adding another len. const int kHalfOfMaxInt = 1 << (kBitsPerInt - 2); @@ -1029,7 +1027,7 @@ BUILTIN(ArrayConcat) { return CallJsBuiltin(isolate, "ArrayConcat", args); } - ElementsKind arg_kind = JSArray::cast(arg)->map()->elements_kind(); + ElementsKind arg_kind = Handle::cast(arg)->map()->elements_kind(); has_double = has_double || IsFastDoubleElementsKind(arg_kind); is_holey = is_holey || IsFastHoleyElementsKind(arg_kind); if (IsMoreGeneralElementsKindTransition(elements_kind, arg_kind)) { @@ -1045,34 +1043,29 @@ BUILTIN(ArrayConcat) { ArrayStorageAllocationMode mode = has_double && IsFastObjectElementsKind(elements_kind) ? INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE : DONT_INITIALIZE_ARRAY_ELEMENTS; - JSArray* result_array; - // Allocate result. - MaybeObject* maybe_array = - heap->AllocateJSArrayAndStorage(elements_kind, - result_len, - result_len, - mode); - if (!maybe_array->To(&result_array)) return maybe_array; - if (result_len == 0) return result_array; + Handle result_array = + isolate->factory()->NewJSArray(elements_kind, + result_len, + result_len, + mode); + if (result_len == 0) return *result_array; int j = 0; - FixedArrayBase* storage = result_array->elements(); + Handle storage(result_array->elements()); ElementsAccessor* accessor = ElementsAccessor::ForKind(elements_kind); for (int i = 0; i < n_arguments; i++) { - JSArray* array = JSArray::cast(args[i]); + Handle array = args.at(i); int len = Smi::cast(array->length())->value(); ElementsKind from_kind = array->GetElementsKind(); if (len > 0) { - MaybeObject* maybe_failure = - accessor->CopyElements(array, 0, from_kind, storage, j, len); - if (maybe_failure->IsFailure()) return maybe_failure; + accessor->CopyElements(array, 0, from_kind, storage, j, len); j += len; } } ASSERT(j == result_len); - return result_array; + return *result_array; } diff --git a/src/elements.cc b/src/elements.cc index 3949747..0624a03 100644 --- a/src/elements.cc +++ b/src/elements.cc @@ -168,10 +168,10 @@ static Handle ThrowArrayLengthRangeError(Isolate* isolate) { } -static void CopyObjectToObjectElements(FixedArrayBase* from_base, +static void CopyObjectToObjectElements(Handle from_base, ElementsKind from_kind, uint32_t from_start, - FixedArrayBase* to_base, + Handle to_base, ElementsKind to_kind, uint32_t to_start, int raw_copy_size) { @@ -189,7 +189,7 @@ static void CopyObjectToObjectElements(FixedArrayBase* from_base, int length = to_base->length() - start; if (length > 0) { Heap* heap = from_base->GetHeap(); - MemsetPointer(FixedArray::cast(to_base)->data_start() + start, + MemsetPointer(Handle::cast(to_base)->data_start() + start, heap->the_hole_value(), length); } } @@ -197,8 +197,8 @@ static void CopyObjectToObjectElements(FixedArrayBase* from_base, ASSERT((copy_size + static_cast(to_start)) <= to_base->length() && (copy_size + static_cast(from_start)) <= from_base->length()); if (copy_size == 0) return; - FixedArray* from = FixedArray::cast(from_base); - FixedArray* to = FixedArray::cast(to_base); + Handle from = Handle::cast(from_base); + Handle to = Handle::cast(to_base); ASSERT(IsFastSmiOrObjectElementsKind(from_kind)); ASSERT(IsFastSmiOrObjectElementsKind(to_kind)); Address to_address = to->address() + FixedArray::kHeaderSize; @@ -209,23 +209,24 @@ static void CopyObjectToObjectElements(FixedArrayBase* from_base, if (IsFastObjectElementsKind(from_kind) && IsFastObjectElementsKind(to_kind)) { Heap* heap = from->GetHeap(); - if (!heap->InNewSpace(to)) { + if (!heap->InNewSpace(*to)) { heap->RecordWrites(to->address(), to->OffsetOfElementAt(to_start), copy_size); } - heap->incremental_marking()->RecordWrites(to); + heap->incremental_marking()->RecordWrites(*to); } } -static void CopyDictionaryToObjectElements(FixedArrayBase* from_base, +static void CopyDictionaryToObjectElements(Handle from_base, uint32_t from_start, - FixedArrayBase* to_base, + Handle to_base, ElementsKind to_kind, uint32_t to_start, int raw_copy_size) { - SeededNumberDictionary* from = SeededNumberDictionary::cast(from_base); + Handle from = + Handle::cast(from_base); DisallowHeapAllocation no_allocation; int copy_size = raw_copy_size; Heap* heap = from->GetHeap(); @@ -238,15 +239,15 @@ static void CopyDictionaryToObjectElements(FixedArrayBase* from_base, int length = to_base->length() - start; if (length > 0) { Heap* heap = from->GetHeap(); - MemsetPointer(FixedArray::cast(to_base)->data_start() + start, + MemsetPointer(Handle::cast(to_base)->data_start() + start, heap->the_hole_value(), length); } } } - ASSERT(to_base != from_base); + ASSERT(*to_base != *from_base); ASSERT(IsFastSmiOrObjectElementsKind(to_kind)); if (copy_size == 0) return; - FixedArray* to = FixedArray::cast(to_base); + Handle to = Handle::cast(to_base); uint32_t to_length = to->length(); if (to_start + copy_size > to_length) { copy_size = to_length - to_start; @@ -262,23 +263,22 @@ static void CopyDictionaryToObjectElements(FixedArrayBase* from_base, } } if (IsFastObjectElementsKind(to_kind)) { - if (!heap->InNewSpace(to)) { + if (!heap->InNewSpace(*to)) { heap->RecordWrites(to->address(), to->OffsetOfElementAt(to_start), copy_size); } - heap->incremental_marking()->RecordWrites(to); + heap->incremental_marking()->RecordWrites(*to); } } -MUST_USE_RESULT static MaybeObject* CopyDoubleToObjectElements( - FixedArrayBase* from_base, - uint32_t from_start, - FixedArrayBase* to_base, - ElementsKind to_kind, - uint32_t to_start, - int raw_copy_size) { +static void CopyDoubleToObjectElements(Handle from_base, + uint32_t from_start, + Handle to_base, + ElementsKind to_kind, + uint32_t to_start, + int raw_copy_size) { ASSERT(IsFastSmiOrObjectElementsKind(to_kind)); int copy_size = raw_copy_size; if (raw_copy_size < 0) { @@ -294,49 +294,35 @@ MUST_USE_RESULT static MaybeObject* CopyDoubleToObjectElements( int length = to_base->length() - start; if (length > 0) { Heap* heap = from_base->GetHeap(); - MemsetPointer(FixedArray::cast(to_base)->data_start() + start, + MemsetPointer(Handle::cast(to_base)->data_start() + start, heap->the_hole_value(), length); } } } ASSERT((copy_size + static_cast(to_start)) <= to_base->length() && (copy_size + static_cast(from_start)) <= from_base->length()); - if (copy_size == 0) return from_base; - FixedDoubleArray* from = FixedDoubleArray::cast(from_base); - FixedArray* to = FixedArray::cast(to_base); + if (copy_size == 0) return; + Handle from = Handle::cast(from_base); + Handle to = Handle::cast(to_base); for (int i = 0; i < copy_size; ++i) { + HandleScope scope(from_base->GetIsolate()); if (IsFastSmiElementsKind(to_kind)) { UNIMPLEMENTED(); - return Failure::Exception(); } else { - MaybeObject* maybe_value = from->get(i + from_start); - Object* value; ASSERT(IsFastObjectElementsKind(to_kind)); - // Because Double -> Object elements transitions allocate HeapObjects - // iteratively, the allocate must succeed within a single GC cycle, - // otherwise the retry after the GC will also fail. In order to ensure - // that no GC is triggered, allocate HeapNumbers from old space if they - // can't be taken from new space. - if (!maybe_value->ToObject(&value)) { - ASSERT(maybe_value->IsRetryAfterGC()); - Heap* heap = from->GetHeap(); - MaybeObject* maybe_value_object = - heap->AllocateHeapNumber(from->get_scalar(i + from_start), - TENURED); - if (!maybe_value_object->ToObject(&value)) return maybe_value_object; - } - to->set(i + to_start, value, UPDATE_WRITE_BARRIER); + Handle value = from->get_as_handle(i + from_start); + to->set(i + to_start, *value, UPDATE_WRITE_BARRIER); } } - return to; } -static void CopyDoubleToDoubleElements(FixedArrayBase* from_base, +static void CopyDoubleToDoubleElements(Handle from_base, uint32_t from_start, - FixedArrayBase* to_base, + Handle to_base, uint32_t to_start, int raw_copy_size) { + DisallowHeapAllocation no_allocation; int copy_size = raw_copy_size; if (raw_copy_size < 0) { ASSERT(raw_copy_size == ElementsAccessor::kCopyToEnd || @@ -345,15 +331,15 @@ static void CopyDoubleToDoubleElements(FixedArrayBase* from_base, to_base->length() - to_start); if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) { for (int i = to_start + copy_size; i < to_base->length(); ++i) { - FixedDoubleArray::cast(to_base)->set_the_hole(i); + Handle::cast(to_base)->set_the_hole(i); } } } ASSERT((copy_size + static_cast(to_start)) <= to_base->length() && (copy_size + static_cast(from_start)) <= from_base->length()); if (copy_size == 0) return; - FixedDoubleArray* from = FixedDoubleArray::cast(from_base); - FixedDoubleArray* to = FixedDoubleArray::cast(to_base); + Handle from = Handle::cast(from_base); + Handle to = Handle::cast(to_base); Address to_address = to->address() + FixedDoubleArray::kHeaderSize; Address from_address = from->address() + FixedDoubleArray::kHeaderSize; to_address += kDoubleSize * to_start; @@ -365,11 +351,12 @@ static void CopyDoubleToDoubleElements(FixedArrayBase* from_base, } -static void CopySmiToDoubleElements(FixedArrayBase* from_base, +static void CopySmiToDoubleElements(Handle from_base, uint32_t from_start, - FixedArrayBase* to_base, + Handle to_base, uint32_t to_start, int raw_copy_size) { + DisallowHeapAllocation no_allocation; int copy_size = raw_copy_size; if (raw_copy_size < 0) { ASSERT(raw_copy_size == ElementsAccessor::kCopyToEnd || @@ -377,20 +364,20 @@ static void CopySmiToDoubleElements(FixedArrayBase* from_base, copy_size = from_base->length() - from_start; if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) { for (int i = to_start + copy_size; i < to_base->length(); ++i) { - FixedDoubleArray::cast(to_base)->set_the_hole(i); + Handle::cast(to_base)->set_the_hole(i); } } } ASSERT((copy_size + static_cast(to_start)) <= to_base->length() && (copy_size + static_cast(from_start)) <= from_base->length()); if (copy_size == 0) return; - FixedArray* from = FixedArray::cast(from_base); - FixedDoubleArray* to = FixedDoubleArray::cast(to_base); - Object* the_hole = from->GetHeap()->the_hole_value(); + Handle from = Handle::cast(from_base); + Handle to = Handle::cast(to_base); + Handle the_hole = from->GetIsolate()->factory()->the_hole_value(); for (uint32_t from_end = from_start + static_cast(copy_size); from_start < from_end; from_start++, to_start++) { Object* hole_or_smi = from->get(from_start); - if (hole_or_smi == the_hole) { + if (hole_or_smi == *the_hole) { to->set_the_hole(to_start); } else { to->set(to_start, Smi::cast(hole_or_smi)->value()); @@ -399,12 +386,13 @@ static void CopySmiToDoubleElements(FixedArrayBase* from_base, } -static void CopyPackedSmiToDoubleElements(FixedArrayBase* from_base, +static void CopyPackedSmiToDoubleElements(Handle from_base, uint32_t from_start, - FixedArrayBase* to_base, + Handle to_base, uint32_t to_start, int packed_size, int raw_copy_size) { + DisallowHeapAllocation no_allocation; int copy_size = raw_copy_size; uint32_t to_end; if (raw_copy_size < 0) { @@ -414,7 +402,7 @@ static void CopyPackedSmiToDoubleElements(FixedArrayBase* from_base, if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) { to_end = to_base->length(); for (uint32_t i = to_start + copy_size; i < to_end; ++i) { - FixedDoubleArray::cast(to_base)->set_the_hole(i); + Handle::cast(to_base)->set_the_hole(i); } } else { to_end = to_start + static_cast(copy_size); @@ -427,8 +415,8 @@ static void CopyPackedSmiToDoubleElements(FixedArrayBase* from_base, ASSERT((copy_size + static_cast(to_start)) <= to_base->length() && (copy_size + static_cast(from_start)) <= from_base->length()); if (copy_size == 0) return; - FixedArray* from = FixedArray::cast(from_base); - FixedDoubleArray* to = FixedDoubleArray::cast(to_base); + Handle from = Handle::cast(from_base); + Handle to = Handle::cast(to_base); for (uint32_t from_end = from_start + static_cast(packed_size); from_start < from_end; from_start++, to_start++) { Object* smi = from->get(from_start); @@ -438,11 +426,12 @@ static void CopyPackedSmiToDoubleElements(FixedArrayBase* from_base, } -static void CopyObjectToDoubleElements(FixedArrayBase* from_base, +static void CopyObjectToDoubleElements(Handle from_base, uint32_t from_start, - FixedArrayBase* to_base, + Handle to_base, uint32_t to_start, int raw_copy_size) { + DisallowHeapAllocation no_allocation; int copy_size = raw_copy_size; if (raw_copy_size < 0) { ASSERT(raw_copy_size == ElementsAccessor::kCopyToEnd || @@ -450,20 +439,20 @@ static void CopyObjectToDoubleElements(FixedArrayBase* from_base, copy_size = from_base->length() - from_start; if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) { for (int i = to_start + copy_size; i < to_base->length(); ++i) { - FixedDoubleArray::cast(to_base)->set_the_hole(i); + Handle::cast(to_base)->set_the_hole(i); } } } ASSERT((copy_size + static_cast(to_start)) <= to_base->length() && (copy_size + static_cast(from_start)) <= from_base->length()); if (copy_size == 0) return; - FixedArray* from = FixedArray::cast(from_base); - FixedDoubleArray* to = FixedDoubleArray::cast(to_base); - Object* the_hole = from->GetHeap()->the_hole_value(); + Handle from = Handle::cast(from_base); + Handle to = Handle::cast(to_base); + Handle the_hole = from->GetIsolate()->factory()->the_hole_value(); for (uint32_t from_end = from_start + copy_size; from_start < from_end; from_start++, to_start++) { Object* hole_or_object = from->get(from_start); - if (hole_or_object == the_hole) { + if (hole_or_object == *the_hole) { to->set_the_hole(to_start); } else { to->set(to_start, hole_or_object->Number()); @@ -472,12 +461,14 @@ static void CopyObjectToDoubleElements(FixedArrayBase* from_base, } -static void CopyDictionaryToDoubleElements(FixedArrayBase* from_base, +static void CopyDictionaryToDoubleElements(Handle from_base, uint32_t from_start, - FixedArrayBase* to_base, + Handle to_base, uint32_t to_start, int raw_copy_size) { - SeededNumberDictionary* from = SeededNumberDictionary::cast(from_base); + Handle from = + Handle::cast(from_base); + DisallowHeapAllocation no_allocation; int copy_size = raw_copy_size; if (copy_size < 0) { ASSERT(copy_size == ElementsAccessor::kCopyToEnd || @@ -485,12 +476,12 @@ static void CopyDictionaryToDoubleElements(FixedArrayBase* from_base, copy_size = from->max_number_key() + 1 - from_start; if (raw_copy_size == ElementsAccessor::kCopyToEndAndInitializeToHole) { for (int i = to_start + copy_size; i < to_base->length(); ++i) { - FixedDoubleArray::cast(to_base)->set_the_hole(i); + Handle::cast(to_base)->set_the_hole(i); } } } if (copy_size == 0) return; - FixedDoubleArray* to = FixedDoubleArray::cast(to_base); + Handle to = Handle::cast(to_base); uint32_t to_length = to->length(); if (to_start + copy_size > to_length) { copy_size = to_length - to_start; @@ -756,9 +747,8 @@ class ElementsAccessorBase : public ElementsAccessor { MUST_USE_RESULT virtual Handle SetLength( Handle array, Handle length) V8_FINAL V8_OVERRIDE { - Isolate* isolate = array->GetIsolate(); return ElementsAccessorSubclass::SetLengthImpl( - array, length, handle(array->elements(), isolate)); + array, length, handle(array->elements())); } MUST_USE_RESULT static Handle SetLengthImpl( @@ -786,32 +776,14 @@ class ElementsAccessorBase : public ElementsAccessor { uint32_t key, JSReceiver::DeleteMode mode) V8_OVERRIDE = 0; - MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, - uint32_t from_start, - FixedArrayBase* to, - ElementsKind from_kind, - uint32_t to_start, - int packed_size, - int copy_size) { + static void CopyElementsImpl(Handle from, + uint32_t from_start, + Handle to, + ElementsKind from_kind, + uint32_t to_start, + int packed_size, + int copy_size) { UNREACHABLE(); - return NULL; - } - - // TODO(ishell): Temporary wrapper, remove when CopyElements handlified. - Handle CopyElementsHelper( - Handle from_holder, - uint32_t from_start, - ElementsKind from_kind, - Handle to, - uint32_t to_start, - int copy_size, - Handle from) { - CALL_HEAP_FUNCTION(to->GetIsolate(), - CopyElements( - from_holder.is_null() ? NULL : *from_holder, - from_start, from_kind, *to, to_start, copy_size, - from.is_null() ? NULL : *from), - Object); } virtual void CopyElements( @@ -822,36 +794,23 @@ class ElementsAccessorBase : public ElementsAccessor { uint32_t to_start, int copy_size, Handle from) V8_FINAL V8_OVERRIDE { - Handle result = CopyElementsHelper( - from_holder, from_start, from_kind, to, to_start, copy_size, from); - ASSERT(!result.is_null()); - USE(result); - } - - MUST_USE_RESULT virtual MaybeObject* CopyElements( - JSObject* from_holder, - uint32_t from_start, - ElementsKind from_kind, - FixedArrayBase* to, - uint32_t to_start, - int copy_size, - FixedArrayBase* from) V8_FINAL V8_OVERRIDE { int packed_size = kPackedSizeNotKnown; - if (from == NULL) { - from = from_holder->elements(); + if (from.is_null()) { + from = handle(from_holder->elements()); } - if (from_holder) { + if (!from_holder.is_null()) { bool is_packed = IsFastPackedElementsKind(from_kind) && from_holder->IsJSArray(); if (is_packed) { - packed_size = Smi::cast(JSArray::cast(from_holder)->length())->value(); + packed_size = + Smi::cast(Handle::cast(from_holder)->length())->value(); if (copy_size >= 0 && packed_size > copy_size) { packed_size = copy_size; } } } - return ElementsAccessorSubclass::CopyElementsImpl( + ElementsAccessorSubclass::CopyElementsImpl( from, from_start, to, from_kind, to_start, packed_size, copy_size); } @@ -1041,7 +1000,7 @@ class FastElementsAccessor obj->HasFastArgumentsElements()); Isolate* isolate = obj->GetIsolate(); Heap* heap = obj->GetHeap(); - Handle elements = handle(obj->elements(), isolate); + Handle elements(obj->elements()); if (*elements == heap->empty_fixed_array()) { return isolate->factory()->true_value(); } @@ -1049,8 +1008,8 @@ class FastElementsAccessor bool is_sloppy_arguments_elements_map = backing_store->map() == heap->sloppy_arguments_elements_map(); if (is_sloppy_arguments_elements_map) { - backing_store = Handle::cast( - handle(Handle::cast(backing_store)->get(1), isolate)); + backing_store = handle( + BackingStore::cast(Handle::cast(backing_store)->get(1))); } uint32_t length = static_cast( obj->IsJSArray() @@ -1121,8 +1080,7 @@ class FastElementsAccessor ((map == heap->fixed_array_map() && length == 0) || map == heap->fixed_double_array_map()))); for (int i = 0; i < length; i++) { - typename KindTraits::BackingStore* backing_store = - KindTraits::BackingStore::cast(elements); + BackingStore* backing_store = BackingStore::cast(elements); ASSERT((!IsFastSmiElementsKind(KindTraits::Kind) || static_cast(backing_store->get(i))->IsSmi()) || (IsFastHoleyElementsKind(KindTraits::Kind) == @@ -1172,13 +1130,13 @@ class FastSmiOrObjectElementsAccessor KindTraits, kPointerSize>(name) {} - static MaybeObject* CopyElementsImpl(FixedArrayBase* from, - uint32_t from_start, - FixedArrayBase* to, - ElementsKind from_kind, - uint32_t to_start, - int packed_size, - int copy_size) { + static void CopyElementsImpl(Handle from, + uint32_t from_start, + Handle to, + ElementsKind from_kind, + uint32_t to_start, + int packed_size, + int copy_size) { ElementsKind to_kind = KindTraits::Kind; switch (from_kind) { case FAST_SMI_ELEMENTS: @@ -1187,24 +1145,27 @@ class FastSmiOrObjectElementsAccessor case FAST_HOLEY_ELEMENTS: CopyObjectToObjectElements( from, from_kind, from_start, to, to_kind, to_start, copy_size); - return to->GetHeap()->undefined_value(); + break; case FAST_DOUBLE_ELEMENTS: case FAST_HOLEY_DOUBLE_ELEMENTS: - return CopyDoubleToObjectElements( + CopyDoubleToObjectElements( from, from_start, to, to_kind, to_start, copy_size); + break; case DICTIONARY_ELEMENTS: CopyDictionaryToObjectElements( from, from_start, to, to_kind, to_start, copy_size); - return to->GetHeap()->undefined_value(); + break; case SLOPPY_ARGUMENTS_ELEMENTS: { // TODO(verwaest): This is a temporary hack to support extending // SLOPPY_ARGUMENTS_ELEMENTS in SetFastElementsCapacityAndLength. // This case should be UNREACHABLE(). - FixedArray* parameter_map = FixedArray::cast(from); - FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); - ElementsKind from_kind = ElementsKindForArray(arguments); - return CopyElementsImpl(arguments, from_start, to, from_kind, - to_start, packed_size, copy_size); + Handle parameter_map = Handle::cast(from); + Handle arguments( + FixedArrayBase::cast(parameter_map->get(1))); + ElementsKind from_kind = ElementsKindForArray(*arguments); + CopyElementsImpl(arguments, from_start, to, from_kind, + to_start, packed_size, copy_size); + break; } #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ case EXTERNAL_##TYPE##_ELEMENTS: \ @@ -1213,7 +1174,6 @@ class FastSmiOrObjectElementsAccessor TYPED_ARRAYS(TYPED_ARRAY_CASE) #undef TYPED_ARRAY_CASE } - return NULL; } @@ -1298,13 +1258,13 @@ class FastDoubleElementsAccessor } protected: - static MaybeObject* CopyElementsImpl(FixedArrayBase* from, - uint32_t from_start, - FixedArrayBase* to, - ElementsKind from_kind, - uint32_t to_start, - int packed_size, - int copy_size) { + static void CopyElementsImpl(Handle from, + uint32_t from_start, + Handle to, + ElementsKind from_kind, + uint32_t to_start, + int packed_size, + int copy_size) { switch (from_kind) { case FAST_SMI_ELEMENTS: CopyPackedSmiToDoubleElements( @@ -1335,7 +1295,6 @@ class FastDoubleElementsAccessor TYPED_ARRAYS(TYPED_ARRAY_CASE) #undef TYPED_ARRAY_CASE } - return to->GetHeap()->undefined_value(); } }; @@ -1595,15 +1554,14 @@ class DictionaryElementsAccessor Object); } - MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, - uint32_t from_start, - FixedArrayBase* to, - ElementsKind from_kind, - uint32_t to_start, - int packed_size, - int copy_size) { + static void CopyElementsImpl(Handle from, + uint32_t from_start, + Handle to, + ElementsKind from_kind, + uint32_t to_start, + int packed_size, + int copy_size) { UNREACHABLE(); - return NULL; } @@ -1809,8 +1767,7 @@ class SloppyArgumentsElementsAccessor : public ElementsAccessorBase< uint32_t key, JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE { Isolate* isolate = obj->GetIsolate(); - Handle parameter_map = - handle(FixedArray::cast(obj->elements()), isolate); + Handle parameter_map(FixedArray::cast(obj->elements())); Handle probe = GetParameterMapArg(obj, parameter_map, key); if (!probe->IsTheHole()) { // TODO(kmillikin): We could check if this was the last aliased @@ -1818,8 +1775,7 @@ class SloppyArgumentsElementsAccessor : public ElementsAccessorBase< // would enable GC of the context. parameter_map->set_the_hole(key + 2); } else { - Handle arguments = - handle(FixedArray::cast(parameter_map->get(1)), isolate); + Handle arguments(FixedArray::cast(parameter_map->get(1))); if (arguments->IsDictionary()) { return DictionaryElementsAccessor::DeleteCommon(obj, key, mode); } else { @@ -1832,15 +1788,14 @@ class SloppyArgumentsElementsAccessor : public ElementsAccessorBase< return isolate->factory()->true_value(); } - MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, - uint32_t from_start, - FixedArrayBase* to, - ElementsKind from_kind, - uint32_t to_start, - int packed_size, - int copy_size) { + static void CopyElementsImpl(Handle from, + uint32_t from_start, + Handle to, + ElementsKind from_kind, + uint32_t to_start, + int packed_size, + int copy_size) { UNREACHABLE(); - return NULL; } static uint32_t GetCapacityImpl(FixedArrayBase* backing_store) { diff --git a/src/elements.h b/src/elements.h index ea335aa..44644ab 100644 --- a/src/elements.h +++ b/src/elements.h @@ -158,14 +158,6 @@ class ElementsAccessor { uint32_t destination_start, int copy_size, Handle source = Handle::null()) = 0; - MUST_USE_RESULT virtual MaybeObject* CopyElements( - JSObject* source_holder, - uint32_t source_start, - ElementsKind source_kind, - FixedArrayBase* destination, - uint32_t destination_start, - int copy_size, - FixedArrayBase* source = NULL) = 0; void CopyElements( Handle from_holder, @@ -176,14 +168,6 @@ class ElementsAccessor { kCopyToEndAndInitializeToHole, from); } - MUST_USE_RESULT MaybeObject* CopyElements(JSObject* from_holder, - FixedArrayBase* to, - ElementsKind from_kind, - FixedArrayBase* from = NULL) { - return CopyElements(from_holder, 0, from_kind, to, 0, - kCopyToEndAndInitializeToHole, from); - } - MUST_USE_RESULT virtual MaybeObject* AddElementsToFixedArray( Object* receiver, JSObject* holder, diff --git a/src/factory.cc b/src/factory.cc index f6f6525..0868db8 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -1437,6 +1437,7 @@ Handle Factory::NewJSObjectFromMap( Handle Factory::NewJSArray(ElementsKind elements_kind, int length, int capacity, + ArrayStorageAllocationMode mode, PretenureFlag pretenure) { if (capacity != 0) { elements_kind = GetHoleyElementsKind(elements_kind); @@ -1446,7 +1447,7 @@ Handle Factory::NewJSArray(ElementsKind elements_kind, elements_kind, length, capacity, - INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, + mode, pretenure), JSArray); } diff --git a/src/factory.h b/src/factory.h index e390052..00f20ff 100644 --- a/src/factory.h +++ b/src/factory.h @@ -355,13 +355,15 @@ class Factory { ElementsKind elements_kind, int length, int capacity, + ArrayStorageAllocationMode mode = INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, PretenureFlag pretenure = NOT_TENURED); Handle NewJSArray( int capacity, ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND, PretenureFlag pretenure = NOT_TENURED) { - return NewJSArray(elements_kind, 0, capacity, pretenure); + return NewJSArray(elements_kind, 0, capacity, + INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, pretenure); } Handle NewJSArrayWithElements( diff --git a/src/objects-inl.h b/src/objects-inl.h index acfbb43..9d55037 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -2195,6 +2195,15 @@ MaybeObject* FixedDoubleArray::get(int index) { } +Handle FixedDoubleArray::get_as_handle(int index) { + if (is_the_hole(index)) { + return GetIsolate()->factory()->the_hole_value(); + } else { + return GetIsolate()->factory()->NewNumber(get_scalar(index)); + } +} + + void FixedDoubleArray::set(int index, double value) { ASSERT(map() != GetHeap()->fixed_cow_array_map() && map() != GetHeap()->fixed_array_map()); diff --git a/src/objects.h b/src/objects.h index 0e352a2..e3ed08c 100644 --- a/src/objects.h +++ b/src/objects.h @@ -3137,6 +3137,8 @@ class FixedDoubleArray: public FixedArrayBase { inline double get_scalar(int index); inline int64_t get_representation(int index); MUST_USE_RESULT inline MaybeObject* get(int index); + // TODO(ishell): Rename as get() once all usages handlified. + inline Handle get_as_handle(int index); inline void set(int index, double value); inline void set_the_hole(int index);