OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 3189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3200 switch (GetElementsKind()) { | 3200 switch (GetElementsKind()) { |
3201 case FAST_ELEMENTS: | 3201 case FAST_ELEMENTS: |
3202 return DeleteFastElement(index); | 3202 return DeleteFastElement(index); |
3203 | 3203 |
3204 case DICTIONARY_ELEMENTS: | 3204 case DICTIONARY_ELEMENTS: |
3205 return DeleteDictionaryElement(index, mode); | 3205 return DeleteDictionaryElement(index, mode); |
3206 | 3206 |
3207 case FAST_DOUBLE_ELEMENTS: { | 3207 case FAST_DOUBLE_ELEMENTS: { |
3208 int length = IsJSArray() | 3208 int length = IsJSArray() |
3209 ? Smi::cast(JSArray::cast(this)->length())->value() | 3209 ? Smi::cast(JSArray::cast(this)->length())->value() |
3210 : FixedArray::cast(elements())->length(); | 3210 : FixedDoubleArray::cast(elements())->length(); |
3211 if (index < static_cast<uint32_t>(length)) { | 3211 if (index < static_cast<uint32_t>(length)) { |
3212 FixedDoubleArray::cast(elements())->set_the_hole(index); | 3212 FixedDoubleArray::cast(elements())->set_the_hole(index); |
3213 } | 3213 } |
3214 break; | 3214 break; |
3215 } | 3215 } |
3216 case EXTERNAL_PIXEL_ELEMENTS: | 3216 case EXTERNAL_PIXEL_ELEMENTS: |
3217 case EXTERNAL_BYTE_ELEMENTS: | 3217 case EXTERNAL_BYTE_ELEMENTS: |
3218 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | 3218 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
3219 case EXTERNAL_SHORT_ELEMENTS: | 3219 case EXTERNAL_SHORT_ELEMENTS: |
3220 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | 3220 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
(...skipping 4400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7621 MaybeObject* JSObject::SetElementsLength(Object* len) { | 7621 MaybeObject* JSObject::SetElementsLength(Object* len) { |
7622 // We should never end in here with a pixel or external array. | 7622 // We should never end in here with a pixel or external array. |
7623 ASSERT(AllowsSetElementsLength()); | 7623 ASSERT(AllowsSetElementsLength()); |
7624 | 7624 |
7625 MaybeObject* maybe_smi_length = len->ToSmi(); | 7625 MaybeObject* maybe_smi_length = len->ToSmi(); |
7626 Object* smi_length = Smi::FromInt(0); | 7626 Object* smi_length = Smi::FromInt(0); |
7627 if (maybe_smi_length->ToObject(&smi_length) && smi_length->IsSmi()) { | 7627 if (maybe_smi_length->ToObject(&smi_length) && smi_length->IsSmi()) { |
7628 const int value = Smi::cast(smi_length)->value(); | 7628 const int value = Smi::cast(smi_length)->value(); |
7629 if (value < 0) return ArrayLengthRangeError(GetHeap()); | 7629 if (value < 0) return ArrayLengthRangeError(GetHeap()); |
7630 switch (GetElementsKind()) { | 7630 switch (GetElementsKind()) { |
7631 case FAST_ELEMENTS: { | 7631 case FAST_ELEMENTS: |
7632 int old_capacity = FixedArray::cast(elements())->length(); | 7632 case FAST_DOUBLE_ELEMENTS: { |
| 7633 int old_capacity = FixedArrayBase::cast(elements())->length(); |
7633 if (value <= old_capacity) { | 7634 if (value <= old_capacity) { |
7634 if (IsJSArray()) { | 7635 if (IsJSArray()) { |
7635 Object* obj; | |
7636 { MaybeObject* maybe_obj = EnsureWritableFastElements(); | |
7637 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | |
7638 } | |
7639 FixedArray* fast_elements = FixedArray::cast(elements()); | |
7640 if (2 * value <= old_capacity) { | 7636 if (2 * value <= old_capacity) { |
7641 // If more than half the elements won't be used, trim the array. | 7637 // If more than half the elements won't be used, trim the array. |
7642 if (value == 0) { | 7638 if (value == 0) { |
7643 initialize_elements(); | 7639 initialize_elements(); |
7644 } else { | 7640 } else { |
7645 fast_elements->set_length(value); | 7641 Address filler_start; |
7646 Address filler_start = fast_elements->address() + | 7642 int filler_size; |
7647 FixedArray::OffsetOfElementAt(value); | 7643 if (GetElementsKind() == FAST_ELEMENTS) { |
7648 int filler_size = (old_capacity - value) * kPointerSize; | 7644 Object* obj; |
| 7645 { MaybeObject* maybe_obj = EnsureWritableFastElements(); |
| 7646 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 7647 } |
| 7648 FixedArray* fast_elements = FixedArray::cast(elements()); |
| 7649 fast_elements->set_length(value); |
| 7650 filler_start = fast_elements->address() + |
| 7651 FixedArray::OffsetOfElementAt(value); |
| 7652 filler_size = (old_capacity - value) * kPointerSize; |
| 7653 } else { |
| 7654 ASSERT(GetElementsKind() == FAST_DOUBLE_ELEMENTS); |
| 7655 FixedDoubleArray* fast_double_elements = |
| 7656 FixedDoubleArray::cast(elements()); |
| 7657 fast_double_elements->set_length(value); |
| 7658 filler_start = fast_double_elements->address() + |
| 7659 FixedDoubleArray::OffsetOfElementAt(value); |
| 7660 filler_size = (old_capacity - value) * kDoubleSize; |
| 7661 } |
7649 GetHeap()->CreateFillerObjectAt(filler_start, filler_size); | 7662 GetHeap()->CreateFillerObjectAt(filler_start, filler_size); |
7650 } | 7663 } |
7651 } else { | 7664 } else { |
7652 // Otherwise, fill the unused tail with holes. | 7665 // Otherwise, fill the unused tail with holes. |
7653 int old_length = FastD2I(JSArray::cast(this)->length()->Number()); | 7666 int old_length = FastD2I(JSArray::cast(this)->length()->Number()); |
7654 for (int i = value; i < old_length; i++) { | 7667 if (GetElementsKind() == FAST_ELEMENTS) { |
7655 fast_elements->set_the_hole(i); | 7668 FixedArray* fast_elements = FixedArray::cast(elements()); |
| 7669 for (int i = value; i < old_length; i++) { |
| 7670 fast_elements->set_the_hole(i); |
| 7671 } |
| 7672 } else { |
| 7673 ASSERT(GetElementsKind() == FAST_DOUBLE_ELEMENTS); |
| 7674 FixedDoubleArray* fast_double_elements = |
| 7675 FixedDoubleArray::cast(elements()); |
| 7676 for (int i = value; i < old_length; i++) { |
| 7677 fast_double_elements->set_the_hole(i); |
| 7678 } |
7656 } | 7679 } |
7657 } | 7680 } |
7658 JSArray::cast(this)->set_length(Smi::cast(smi_length)); | 7681 JSArray::cast(this)->set_length(Smi::cast(smi_length)); |
7659 } | 7682 } |
7660 return this; | 7683 return this; |
7661 } | 7684 } |
7662 int min = NewElementsCapacity(old_capacity); | 7685 int min = NewElementsCapacity(old_capacity); |
7663 int new_capacity = value > min ? value : min; | 7686 int new_capacity = value > min ? value : min; |
7664 if (new_capacity <= kMaxFastElementsLength || | 7687 if (new_capacity <= kMaxFastElementsLength || |
7665 !ShouldConvertToSlowElements(new_capacity)) { | 7688 !ShouldConvertToSlowElements(new_capacity)) { |
7666 MaybeObject* result = | 7689 MaybeObject* result; |
7667 SetFastElementsCapacityAndLength(new_capacity, value); | 7690 if (GetElementsKind() == FAST_ELEMENTS) { |
| 7691 Object* obj; |
| 7692 { MaybeObject* maybe_obj = EnsureWritableFastElements(); |
| 7693 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 7694 } |
| 7695 result = SetFastElementsCapacityAndLength(new_capacity, value); |
| 7696 } else { |
| 7697 ASSERT(GetElementsKind() == FAST_DOUBLE_ELEMENTS); |
| 7698 result = SetFastDoubleElementsCapacityAndLength(new_capacity, |
| 7699 value); |
| 7700 } |
7668 if (result->IsFailure()) return result; | 7701 if (result->IsFailure()) return result; |
7669 return this; | 7702 return this; |
7670 } | 7703 } |
7671 break; | 7704 break; |
7672 } | 7705 } |
7673 case DICTIONARY_ELEMENTS: { | 7706 case DICTIONARY_ELEMENTS: { |
7674 if (IsJSArray()) { | 7707 if (IsJSArray()) { |
7675 if (value == 0) { | 7708 if (value == 0) { |
7676 // If the length of a slow array is reset to zero, we clear | 7709 // If the length of a slow array is reset to zero, we clear |
7677 // the array and flush backing storage. This has the added | 7710 // the array and flush backing storage. This has the added |
(...skipping 15 matching lines...) Expand all Loading... |
7693 case NON_STRICT_ARGUMENTS_ELEMENTS: | 7726 case NON_STRICT_ARGUMENTS_ELEMENTS: |
7694 case EXTERNAL_BYTE_ELEMENTS: | 7727 case EXTERNAL_BYTE_ELEMENTS: |
7695 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | 7728 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
7696 case EXTERNAL_SHORT_ELEMENTS: | 7729 case EXTERNAL_SHORT_ELEMENTS: |
7697 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | 7730 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
7698 case EXTERNAL_INT_ELEMENTS: | 7731 case EXTERNAL_INT_ELEMENTS: |
7699 case EXTERNAL_UNSIGNED_INT_ELEMENTS: | 7732 case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
7700 case EXTERNAL_FLOAT_ELEMENTS: | 7733 case EXTERNAL_FLOAT_ELEMENTS: |
7701 case EXTERNAL_DOUBLE_ELEMENTS: | 7734 case EXTERNAL_DOUBLE_ELEMENTS: |
7702 case EXTERNAL_PIXEL_ELEMENTS: | 7735 case EXTERNAL_PIXEL_ELEMENTS: |
7703 case FAST_DOUBLE_ELEMENTS: | |
7704 UNREACHABLE(); | 7736 UNREACHABLE(); |
7705 break; | 7737 break; |
7706 } | 7738 } |
7707 } | 7739 } |
7708 | 7740 |
7709 // General slow case. | 7741 // General slow case. |
7710 if (len->IsNumber()) { | 7742 if (len->IsNumber()) { |
7711 uint32_t length; | 7743 uint32_t length; |
7712 if (len->ToArrayIndex(&length)) { | 7744 if (len->ToArrayIndex(&length)) { |
7713 return SetSlowElements(len); | 7745 return SetSlowElements(len); |
(...skipping 4075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11789 if (break_point_objects()->IsUndefined()) return 0; | 11821 if (break_point_objects()->IsUndefined()) return 0; |
11790 // Single beak point. | 11822 // Single beak point. |
11791 if (!break_point_objects()->IsFixedArray()) return 1; | 11823 if (!break_point_objects()->IsFixedArray()) return 1; |
11792 // Multiple break points. | 11824 // Multiple break points. |
11793 return FixedArray::cast(break_point_objects())->length(); | 11825 return FixedArray::cast(break_point_objects())->length(); |
11794 } | 11826 } |
11795 #endif | 11827 #endif |
11796 | 11828 |
11797 | 11829 |
11798 } } // namespace v8::internal | 11830 } } // namespace v8::internal |
OLD | NEW |