OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/base/once.h" | 9 #include "src/base/once.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 if (!maybe_elms_obj.ToHandle(&elms_obj)) { | 413 if (!maybe_elms_obj.ToHandle(&elms_obj)) { |
414 return CallJsBuiltin(isolate, "ArrayPop", args); | 414 return CallJsBuiltin(isolate, "ArrayPop", args); |
415 } | 415 } |
416 | 416 |
417 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 417 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
418 DCHECK(!array->map()->is_observed()); | 418 DCHECK(!array->map()->is_observed()); |
419 | 419 |
420 int len = Smi::cast(array->length())->value(); | 420 int len = Smi::cast(array->length())->value(); |
421 if (len == 0) return isolate->heap()->undefined_value(); | 421 if (len == 0) return isolate->heap()->undefined_value(); |
422 | 422 |
| 423 if (JSArray::HasReadOnlyLength(array)) { |
| 424 return CallJsBuiltin(isolate, "ArrayPop", args); |
| 425 } |
| 426 |
423 ElementsAccessor* accessor = array->GetElementsAccessor(); | 427 ElementsAccessor* accessor = array->GetElementsAccessor(); |
424 int new_length = len - 1; | 428 int new_length = len - 1; |
425 Handle<Object> element = | 429 Handle<Object> element = |
426 accessor->Get(array, array, new_length, elms_obj).ToHandleChecked(); | 430 accessor->Get(array, array, new_length, elms_obj).ToHandleChecked(); |
427 if (element->IsTheHole()) { | 431 if (element->IsTheHole()) { |
428 return CallJsBuiltin(isolate, "ArrayPop", args); | 432 return CallJsBuiltin(isolate, "ArrayPop", args); |
429 } | 433 } |
430 RETURN_FAILURE_ON_EXCEPTION( | 434 RETURN_FAILURE_ON_EXCEPTION( |
431 isolate, | 435 isolate, |
432 accessor->SetLength(array, handle(Smi::FromInt(new_length), isolate))); | 436 accessor->SetLength(array, handle(Smi::FromInt(new_length), isolate))); |
(...skipping 11 matching lines...) Expand all Loading... |
444 if (!maybe_elms_obj.ToHandle(&elms_obj) || | 448 if (!maybe_elms_obj.ToHandle(&elms_obj) || |
445 !IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(*receiver))) { | 449 !IsJSArrayFastElementMovingAllowed(heap, JSArray::cast(*receiver))) { |
446 return CallJsBuiltin(isolate, "ArrayShift", args); | 450 return CallJsBuiltin(isolate, "ArrayShift", args); |
447 } | 451 } |
448 Handle<JSArray> array = Handle<JSArray>::cast(receiver); | 452 Handle<JSArray> array = Handle<JSArray>::cast(receiver); |
449 DCHECK(!array->map()->is_observed()); | 453 DCHECK(!array->map()->is_observed()); |
450 | 454 |
451 int len = Smi::cast(array->length())->value(); | 455 int len = Smi::cast(array->length())->value(); |
452 if (len == 0) return heap->undefined_value(); | 456 if (len == 0) return heap->undefined_value(); |
453 | 457 |
| 458 if (JSArray::HasReadOnlyLength(array)) { |
| 459 return CallJsBuiltin(isolate, "ArrayShift", args); |
| 460 } |
| 461 |
454 // Get first element | 462 // Get first element |
455 ElementsAccessor* accessor = array->GetElementsAccessor(); | 463 ElementsAccessor* accessor = array->GetElementsAccessor(); |
456 Handle<Object> first = | 464 Handle<Object> first = |
457 accessor->Get(array, array, 0, elms_obj).ToHandleChecked(); | 465 accessor->Get(array, array, 0, elms_obj).ToHandleChecked(); |
458 if (first->IsTheHole()) { | 466 if (first->IsTheHole()) { |
459 return CallJsBuiltin(isolate, "ArrayShift", args); | 467 return CallJsBuiltin(isolate, "ArrayShift", args); |
460 } | 468 } |
461 | 469 |
462 if (heap->CanMoveObjectStart(*elms_obj)) { | 470 if (heap->CanMoveObjectStart(*elms_obj)) { |
463 array->set_elements(heap->LeftTrimFixedArray(*elms_obj, 1)); | 471 array->set_elements(heap->LeftTrimFixedArray(*elms_obj, 1)); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 ElementsKind elements_kind = array->GetElementsKind(); | 757 ElementsKind elements_kind = array->GetElementsKind(); |
750 | 758 |
751 int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0; | 759 int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0; |
752 int new_length = len - actual_delete_count + item_count; | 760 int new_length = len - actual_delete_count + item_count; |
753 | 761 |
754 // For double mode we do not support changing the length. | 762 // For double mode we do not support changing the length. |
755 if (new_length > len && IsFastDoubleElementsKind(elements_kind)) { | 763 if (new_length > len && IsFastDoubleElementsKind(elements_kind)) { |
756 return CallJsBuiltin(isolate, "ArraySplice", args); | 764 return CallJsBuiltin(isolate, "ArraySplice", args); |
757 } | 765 } |
758 | 766 |
| 767 if (new_length != len && JSArray::HasReadOnlyLength(array)) { |
| 768 AllowHeapAllocation allow_allocation; |
| 769 return CallJsBuiltin(isolate, "ArraySplice", args); |
| 770 } |
| 771 |
759 if (new_length == 0) { | 772 if (new_length == 0) { |
760 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements( | 773 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements( |
761 elms_obj, elements_kind, actual_delete_count); | 774 elms_obj, elements_kind, actual_delete_count); |
762 array->set_elements(heap->empty_fixed_array()); | 775 array->set_elements(heap->empty_fixed_array()); |
763 array->set_length(Smi::FromInt(0)); | 776 array->set_length(Smi::FromInt(0)); |
764 return *result; | 777 return *result; |
765 } | 778 } |
766 | 779 |
767 Handle<JSArray> result_array = | 780 Handle<JSArray> result_array = |
768 isolate->factory()->NewJSArray(elements_kind, | 781 isolate->factory()->NewJSArray(elements_kind, |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 } | 1645 } |
1633 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 1646 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
1634 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 1647 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
1635 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 1648 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
1636 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 1649 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
1637 #undef DEFINE_BUILTIN_ACCESSOR_C | 1650 #undef DEFINE_BUILTIN_ACCESSOR_C |
1638 #undef DEFINE_BUILTIN_ACCESSOR_A | 1651 #undef DEFINE_BUILTIN_ACCESSOR_A |
1639 | 1652 |
1640 | 1653 |
1641 } } // namespace v8::internal | 1654 } } // namespace v8::internal |
OLD | NEW |