| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 Handle<Object> receiver, | 360 Handle<Object> receiver, |
| 361 Arguments* args, | 361 Arguments* args, |
| 362 int first_added_arg) { | 362 int first_added_arg) { |
| 363 CALL_HEAP_FUNCTION(isolate, | 363 CALL_HEAP_FUNCTION(isolate, |
| 364 EnsureJSArrayWithWritableFastElements( | 364 EnsureJSArrayWithWritableFastElements( |
| 365 isolate->heap(), *receiver, args, first_added_arg), | 365 isolate->heap(), *receiver, args, first_added_arg), |
| 366 Object); | 366 Object); |
| 367 } | 367 } |
| 368 | 368 |
| 369 | 369 |
| 370 // TODO(ishell): Handlify when all Array* builtins are handlified. |
| 370 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, | 371 static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap, |
| 371 JSArray* receiver) { | 372 JSArray* receiver) { |
| 372 if (!FLAG_clever_optimizations) return false; | 373 if (!FLAG_clever_optimizations) return false; |
| 373 Context* native_context = heap->isolate()->context()->native_context(); | 374 Context* native_context = heap->isolate()->context()->native_context(); |
| 374 JSObject* array_proto = | 375 JSObject* array_proto = |
| 375 JSObject::cast(native_context->array_function()->prototype()); | 376 JSObject::cast(native_context->array_function()->prototype()); |
| 376 return receiver->GetPrototype() == array_proto && | 377 return receiver->GetPrototype() == array_proto && |
| 377 ArrayPrototypeHasNoElements(heap, native_context, array_proto); | 378 ArrayPrototypeHasNoElements(heap, native_context, array_proto); |
| 378 } | 379 } |
| 379 | 380 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 } | 577 } |
| 577 RETURN_IF_EMPTY_HANDLE(isolate, element); | 578 RETURN_IF_EMPTY_HANDLE(isolate, element); |
| 578 RETURN_IF_EMPTY_HANDLE(isolate, | 579 RETURN_IF_EMPTY_HANDLE(isolate, |
| 579 accessor->SetLength( | 580 accessor->SetLength( |
| 580 array, handle(Smi::FromInt(new_length), isolate))); | 581 array, handle(Smi::FromInt(new_length), isolate))); |
| 581 return *element; | 582 return *element; |
| 582 } | 583 } |
| 583 | 584 |
| 584 | 585 |
| 585 BUILTIN(ArrayShift) { | 586 BUILTIN(ArrayShift) { |
| 587 HandleScope scope(isolate); |
| 586 Heap* heap = isolate->heap(); | 588 Heap* heap = isolate->heap(); |
| 587 Object* receiver = *args.receiver(); | 589 Handle<Object> receiver = args.receiver(); |
| 588 FixedArrayBase* elms_obj; | 590 Handle<Object> elms_or_null = |
| 589 MaybeObject* maybe_elms_obj = | 591 EnsureJSArrayWithWritableFastElementsWrapper(isolate, receiver, NULL, 0); |
| 590 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); | 592 RETURN_IF_EMPTY_HANDLE(isolate, elms_or_null); |
| 591 if (maybe_elms_obj == NULL) | 593 if ((*elms_or_null == NULL) || |
| 592 return CallJsBuiltin(isolate, "ArrayShift", args); | 594 !IsJSArrayFastElementMovingAllowed(heap, |
| 593 if (!maybe_elms_obj->To(&elms_obj)) return maybe_elms_obj; | 595 *Handle<JSArray>::cast(receiver))) { |
| 594 | |
| 595 if (!IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(receiver))) { | |
| 596 return CallJsBuiltin(isolate, "ArrayShift", args); | 596 return CallJsBuiltin(isolate, "ArrayShift", args); |
| 597 } | 597 } |
| 598 JSArray* array = JSArray::cast(receiver); | 598 Handle<FixedArrayBase> elms_obj = Handle<FixedArrayBase>::cast(elms_or_null); |
| 599 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
| 599 ASSERT(!array->map()->is_observed()); | 600 ASSERT(!array->map()->is_observed()); |
| 600 | 601 |
| 601 int len = Smi::cast(array->length())->value(); | 602 int len = Smi::cast(array->length())->value(); |
| 602 if (len == 0) return heap->undefined_value(); | 603 if (len == 0) return heap->undefined_value(); |
| 603 | 604 |
| 604 // Get first element | 605 // Get first element |
| 605 ElementsAccessor* accessor = array->GetElementsAccessor(); | 606 ElementsAccessor* accessor = array->GetElementsAccessor(); |
| 606 Object* first; | 607 Handle<Object> first = accessor->Get(receiver, array, 0, elms_obj); |
| 607 MaybeObject* maybe_first = accessor->Get(receiver, array, 0, elms_obj); | |
| 608 if (!maybe_first->To(&first)) return maybe_first; | |
| 609 if (first->IsTheHole()) { | 608 if (first->IsTheHole()) { |
| 610 first = heap->undefined_value(); | 609 first = isolate->factory()->undefined_value(); |
| 611 } | 610 } |
| 612 | 611 |
| 613 if (!heap->lo_space()->Contains(elms_obj)) { | 612 if (!heap->lo_space()->Contains(*elms_obj)) { |
| 614 array->set_elements(LeftTrimFixedArray(heap, elms_obj, 1)); | 613 array->set_elements(LeftTrimFixedArray(heap, *elms_obj, 1)); |
| 615 } else { | 614 } else { |
| 616 // Shift the elements. | 615 // Shift the elements. |
| 617 if (elms_obj->IsFixedArray()) { | 616 if (elms_obj->IsFixedArray()) { |
| 618 FixedArray* elms = FixedArray::cast(elms_obj); | 617 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj); |
| 619 DisallowHeapAllocation no_gc; | 618 DisallowHeapAllocation no_gc; |
| 620 heap->MoveElements(elms, 0, 1, len - 1); | 619 heap->MoveElements(*elms, 0, 1, len - 1); |
| 621 elms->set(len - 1, heap->the_hole_value()); | 620 elms->set(len - 1, heap->the_hole_value()); |
| 622 } else { | 621 } else { |
| 623 FixedDoubleArray* elms = FixedDoubleArray::cast(elms_obj); | 622 Handle<FixedDoubleArray> elms = Handle<FixedDoubleArray>::cast(elms_obj); |
| 624 MoveDoubleElements(elms, 0, elms, 1, len - 1); | 623 MoveDoubleElements(*elms, 0, *elms, 1, len - 1); |
| 625 elms->set_the_hole(len - 1); | 624 elms->set_the_hole(len - 1); |
| 626 } | 625 } |
| 627 } | 626 } |
| 628 | 627 |
| 629 // Set the length. | 628 // Set the length. |
| 630 array->set_length(Smi::FromInt(len - 1)); | 629 array->set_length(Smi::FromInt(len - 1)); |
| 631 | 630 |
| 632 return first; | 631 return *first; |
| 633 } | 632 } |
| 634 | 633 |
| 635 | 634 |
| 636 BUILTIN(ArrayUnshift) { | 635 BUILTIN(ArrayUnshift) { |
| 637 Heap* heap = isolate->heap(); | 636 Heap* heap = isolate->heap(); |
| 638 Object* receiver = *args.receiver(); | 637 Object* receiver = *args.receiver(); |
| 639 FixedArrayBase* elms_obj; | 638 FixedArrayBase* elms_obj; |
| 640 MaybeObject* maybe_elms_obj = | 639 MaybeObject* maybe_elms_obj = |
| 641 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); | 640 EnsureJSArrayWithWritableFastElements(heap, receiver, NULL, 0); |
| 642 if (maybe_elms_obj == NULL) | 641 if (maybe_elms_obj == NULL) |
| (...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1782 } | 1781 } |
| 1783 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1782 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
| 1784 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1783 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 1785 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 1784 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
| 1786 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1785 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
| 1787 #undef DEFINE_BUILTIN_ACCESSOR_C | 1786 #undef DEFINE_BUILTIN_ACCESSOR_C |
| 1788 #undef DEFINE_BUILTIN_ACCESSOR_A | 1787 #undef DEFINE_BUILTIN_ACCESSOR_A |
| 1789 | 1788 |
| 1790 | 1789 |
| 1791 } } // namespace v8::internal | 1790 } } // namespace v8::internal |
| OLD | NEW |