| 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 4399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7620 | 7620 |
| 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 JSObject::ElementsKind elements_kind = GetElementsKind(); |
| 7631 case FAST_ELEMENTS: { | 7631 switch (elements_kind) { |
| 7632 int old_capacity = FixedArray::cast(elements())->length(); | 7632 case FAST_ELEMENTS: |
| 7633 case FAST_DOUBLE_ELEMENTS: { |
| 7634 int old_capacity = FixedArrayBase::cast(elements())->length(); |
| 7633 if (value <= old_capacity) { | 7635 if (value <= old_capacity) { |
| 7634 if (IsJSArray()) { | 7636 if (IsJSArray()) { |
| 7635 Object* obj; | 7637 Object* obj; |
| 7636 { MaybeObject* maybe_obj = EnsureWritableFastElements(); | 7638 if (elements_kind == FAST_ELEMENTS) { |
| 7639 MaybeObject* maybe_obj = EnsureWritableFastElements(); |
| 7637 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 7640 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
| 7638 } | 7641 } |
| 7639 FixedArray* fast_elements = FixedArray::cast(elements()); | |
| 7640 if (2 * value <= old_capacity) { | 7642 if (2 * value <= old_capacity) { |
| 7641 // If more than half the elements won't be used, trim the array. | 7643 // If more than half the elements won't be used, trim the array. |
| 7642 if (value == 0) { | 7644 if (value == 0) { |
| 7643 initialize_elements(); | 7645 initialize_elements(); |
| 7644 } else { | 7646 } else { |
| 7645 fast_elements->set_length(value); | 7647 Address filler_start; |
| 7646 Address filler_start = fast_elements->address() + | 7648 int filler_size; |
| 7647 FixedArray::OffsetOfElementAt(value); | 7649 if (GetElementsKind() == FAST_ELEMENTS) { |
| 7648 int filler_size = (old_capacity - value) * kPointerSize; | 7650 FixedArray* fast_elements = FixedArray::cast(elements()); |
| 7651 fast_elements->set_length(value); |
| 7652 filler_start = fast_elements->address() + |
| 7653 FixedArray::OffsetOfElementAt(value); |
| 7654 filler_size = (old_capacity - value) * kPointerSize; |
| 7655 } else { |
| 7656 ASSERT(GetElementsKind() == FAST_DOUBLE_ELEMENTS); |
| 7657 FixedDoubleArray* fast_double_elements = |
| 7658 FixedDoubleArray::cast(elements()); |
| 7659 fast_double_elements->set_length(value); |
| 7660 filler_start = fast_double_elements->address() + |
| 7661 FixedDoubleArray::OffsetOfElementAt(value); |
| 7662 filler_size = (old_capacity - value) * kDoubleSize; |
| 7663 } |
| 7649 GetHeap()->CreateFillerObjectAt(filler_start, filler_size); | 7664 GetHeap()->CreateFillerObjectAt(filler_start, filler_size); |
| 7650 } | 7665 } |
| 7651 } else { | 7666 } else { |
| 7652 // Otherwise, fill the unused tail with holes. | 7667 // Otherwise, fill the unused tail with holes. |
| 7653 int old_length = FastD2I(JSArray::cast(this)->length()->Number()); | 7668 int old_length = FastD2I(JSArray::cast(this)->length()->Number()); |
| 7654 for (int i = value; i < old_length; i++) { | 7669 if (GetElementsKind() == FAST_ELEMENTS) { |
| 7655 fast_elements->set_the_hole(i); | 7670 FixedArray* fast_elements = FixedArray::cast(elements()); |
| 7671 for (int i = value; i < old_length; i++) { |
| 7672 fast_elements->set_the_hole(i); |
| 7673 } |
| 7674 } else { |
| 7675 ASSERT(GetElementsKind() == FAST_DOUBLE_ELEMENTS); |
| 7676 FixedDoubleArray* fast_double_elements = |
| 7677 FixedDoubleArray::cast(elements()); |
| 7678 for (int i = value; i < old_length; i++) { |
| 7679 fast_double_elements->set_the_hole(i); |
| 7680 } |
| 7656 } | 7681 } |
| 7657 } | 7682 } |
| 7658 JSArray::cast(this)->set_length(Smi::cast(smi_length)); | 7683 JSArray::cast(this)->set_length(Smi::cast(smi_length)); |
| 7659 } | 7684 } |
| 7660 return this; | 7685 return this; |
| 7661 } | 7686 } |
| 7662 int min = NewElementsCapacity(old_capacity); | 7687 int min = NewElementsCapacity(old_capacity); |
| 7663 int new_capacity = value > min ? value : min; | 7688 int new_capacity = value > min ? value : min; |
| 7664 if (new_capacity <= kMaxFastElementsLength || | 7689 if (new_capacity <= kMaxFastElementsLength || |
| 7665 !ShouldConvertToSlowElements(new_capacity)) { | 7690 !ShouldConvertToSlowElements(new_capacity)) { |
| 7666 MaybeObject* result = | 7691 MaybeObject* result; |
| 7667 SetFastElementsCapacityAndLength(new_capacity, value); | 7692 if (GetElementsKind() == FAST_ELEMENTS) { |
| 7693 result = SetFastElementsCapacityAndLength(new_capacity, value); |
| 7694 } else { |
| 7695 ASSERT(GetElementsKind() == FAST_DOUBLE_ELEMENTS); |
| 7696 result = SetFastDoubleElementsCapacityAndLength(new_capacity, |
| 7697 value); |
| 7698 } |
| 7668 if (result->IsFailure()) return result; | 7699 if (result->IsFailure()) return result; |
| 7669 return this; | 7700 return this; |
| 7670 } | 7701 } |
| 7671 break; | 7702 break; |
| 7672 } | 7703 } |
| 7673 case DICTIONARY_ELEMENTS: { | 7704 case DICTIONARY_ELEMENTS: { |
| 7674 if (IsJSArray()) { | 7705 if (IsJSArray()) { |
| 7675 if (value == 0) { | 7706 if (value == 0) { |
| 7676 // If the length of a slow array is reset to zero, we clear | 7707 // If the length of a slow array is reset to zero, we clear |
| 7677 // the array and flush backing storage. This has the added | 7708 // the array and flush backing storage. This has the added |
| (...skipping 15 matching lines...) Expand all Loading... |
| 7693 case NON_STRICT_ARGUMENTS_ELEMENTS: | 7724 case NON_STRICT_ARGUMENTS_ELEMENTS: |
| 7694 case EXTERNAL_BYTE_ELEMENTS: | 7725 case EXTERNAL_BYTE_ELEMENTS: |
| 7695 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | 7726 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
| 7696 case EXTERNAL_SHORT_ELEMENTS: | 7727 case EXTERNAL_SHORT_ELEMENTS: |
| 7697 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | 7728 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
| 7698 case EXTERNAL_INT_ELEMENTS: | 7729 case EXTERNAL_INT_ELEMENTS: |
| 7699 case EXTERNAL_UNSIGNED_INT_ELEMENTS: | 7730 case EXTERNAL_UNSIGNED_INT_ELEMENTS: |
| 7700 case EXTERNAL_FLOAT_ELEMENTS: | 7731 case EXTERNAL_FLOAT_ELEMENTS: |
| 7701 case EXTERNAL_DOUBLE_ELEMENTS: | 7732 case EXTERNAL_DOUBLE_ELEMENTS: |
| 7702 case EXTERNAL_PIXEL_ELEMENTS: | 7733 case EXTERNAL_PIXEL_ELEMENTS: |
| 7703 case FAST_DOUBLE_ELEMENTS: | |
| 7704 UNREACHABLE(); | 7734 UNREACHABLE(); |
| 7705 break; | 7735 break; |
| 7706 } | 7736 } |
| 7707 } | 7737 } |
| 7708 | 7738 |
| 7709 // General slow case. | 7739 // General slow case. |
| 7710 if (len->IsNumber()) { | 7740 if (len->IsNumber()) { |
| 7711 uint32_t length; | 7741 uint32_t length; |
| 7712 if (len->ToArrayIndex(&length)) { | 7742 if (len->ToArrayIndex(&length)) { |
| 7713 return SetSlowElements(len); | 7743 return SetSlowElements(len); |
| (...skipping 4075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11789 if (break_point_objects()->IsUndefined()) return 0; | 11819 if (break_point_objects()->IsUndefined()) return 0; |
| 11790 // Single beak point. | 11820 // Single beak point. |
| 11791 if (!break_point_objects()->IsFixedArray()) return 1; | 11821 if (!break_point_objects()->IsFixedArray()) return 1; |
| 11792 // Multiple break points. | 11822 // Multiple break points. |
| 11793 return FixedArray::cast(break_point_objects())->length(); | 11823 return FixedArray::cast(break_point_objects())->length(); |
| 11794 } | 11824 } |
| 11795 #endif | 11825 #endif |
| 11796 | 11826 |
| 11797 | 11827 |
| 11798 } } // namespace v8::internal | 11828 } } // namespace v8::internal |
| OLD | NEW |