| 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 1718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1729 | 1729 |
| 1730 void JSObject::initialize_elements() { | 1730 void JSObject::initialize_elements() { |
| 1731 if (map()->has_fast_smi_or_object_elements() || | 1731 if (map()->has_fast_smi_or_object_elements() || |
| 1732 map()->has_fast_double_elements()) { | 1732 map()->has_fast_double_elements()) { |
| 1733 ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); | 1733 ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); |
| 1734 WRITE_FIELD(this, kElementsOffset, GetHeap()->empty_fixed_array()); | 1734 WRITE_FIELD(this, kElementsOffset, GetHeap()->empty_fixed_array()); |
| 1735 } else if (map()->has_external_array_elements()) { | 1735 } else if (map()->has_external_array_elements()) { |
| 1736 ExternalArray* empty_array = GetHeap()->EmptyExternalArrayForMap(map()); | 1736 ExternalArray* empty_array = GetHeap()->EmptyExternalArrayForMap(map()); |
| 1737 ASSERT(!GetHeap()->InNewSpace(empty_array)); | 1737 ASSERT(!GetHeap()->InNewSpace(empty_array)); |
| 1738 WRITE_FIELD(this, kElementsOffset, empty_array); | 1738 WRITE_FIELD(this, kElementsOffset, empty_array); |
| 1739 } else if (map()->has_fixed_typed_array_elements()) { | |
| 1740 FixedTypedArrayBase* empty_array = | |
| 1741 GetHeap()->EmptyFixedTypedArrayForMap(map()); | |
| 1742 ASSERT(!GetHeap()->InNewSpace(empty_array)); | |
| 1743 WRITE_FIELD(this, kElementsOffset, empty_array); | |
| 1744 } else { | 1739 } else { |
| 1745 UNREACHABLE(); | 1740 UNREACHABLE(); |
| 1746 } | 1741 } |
| 1747 } | 1742 } |
| 1748 | 1743 |
| 1749 | 1744 |
| 1750 MaybeObject* JSObject::ResetElements() { | 1745 MaybeObject* JSObject::ResetElements() { |
| 1751 if (map()->is_observed()) { | 1746 if (map()->is_observed()) { |
| 1752 // Maintain invariant that observed elements are always in dictionary mode. | 1747 // Maintain invariant that observed elements are always in dictionary mode. |
| 1753 SeededNumberDictionary* dictionary; | 1748 SeededNumberDictionary* dictionary; |
| (...skipping 1920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3674 } | 3669 } |
| 3675 | 3670 |
| 3676 | 3671 |
| 3677 void ExternalFloat64Array::set(int index, double value) { | 3672 void ExternalFloat64Array::set(int index, double value) { |
| 3678 ASSERT((index >= 0) && (index < this->length())); | 3673 ASSERT((index >= 0) && (index < this->length())); |
| 3679 double* ptr = static_cast<double*>(external_pointer()); | 3674 double* ptr = static_cast<double*>(external_pointer()); |
| 3680 ptr[index] = value; | 3675 ptr[index] = value; |
| 3681 } | 3676 } |
| 3682 | 3677 |
| 3683 | 3678 |
| 3684 void* FixedTypedArrayBase::DataPtr() { | 3679 int FixedTypedArrayBase::size() { |
| 3685 return FIELD_ADDR(this, kDataOffset); | |
| 3686 } | |
| 3687 | |
| 3688 | |
| 3689 int FixedTypedArrayBase::DataSize() { | |
| 3690 InstanceType instance_type = map()->instance_type(); | 3680 InstanceType instance_type = map()->instance_type(); |
| 3691 int element_size; | 3681 int element_size; |
| 3692 switch (instance_type) { | 3682 switch (instance_type) { |
| 3693 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 3683 case FIXED_UINT8_ARRAY_TYPE: |
| 3694 case FIXED_##TYPE##_ARRAY_TYPE: \ | 3684 case FIXED_INT8_ARRAY_TYPE: |
| 3695 element_size = size; \ | 3685 case FIXED_UINT8_CLAMPED_ARRAY_TYPE: |
| 3686 element_size = 1; |
| 3696 break; | 3687 break; |
| 3697 | 3688 case FIXED_UINT16_ARRAY_TYPE: |
| 3698 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 3689 case FIXED_INT16_ARRAY_TYPE: |
| 3699 #undef TYPED_ARRAY_CASE | 3690 element_size = 2; |
| 3691 break; |
| 3692 case FIXED_UINT32_ARRAY_TYPE: |
| 3693 case FIXED_INT32_ARRAY_TYPE: |
| 3694 case FIXED_FLOAT32_ARRAY_TYPE: |
| 3695 element_size = 4; |
| 3696 break; |
| 3697 case FIXED_FLOAT64_ARRAY_TYPE: |
| 3698 element_size = 8; |
| 3699 break; |
| 3700 default: | 3700 default: |
| 3701 UNREACHABLE(); | 3701 UNREACHABLE(); |
| 3702 return 0; | 3702 return 0; |
| 3703 } | 3703 } |
| 3704 return length() * element_size; | 3704 return OBJECT_POINTER_ALIGN(kDataOffset + length() * element_size); |
| 3705 } | 3705 } |
| 3706 | 3706 |
| 3707 | 3707 |
| 3708 int FixedTypedArrayBase::size() { | |
| 3709 return OBJECT_POINTER_ALIGN(kDataOffset + DataSize()); | |
| 3710 } | |
| 3711 | |
| 3712 | |
| 3713 uint8_t Uint8ArrayTraits::defaultValue() { return 0; } | |
| 3714 | |
| 3715 | |
| 3716 uint8_t Uint8ClampedArrayTraits::defaultValue() { return 0; } | |
| 3717 | |
| 3718 | |
| 3719 int8_t Int8ArrayTraits::defaultValue() { return 0; } | |
| 3720 | |
| 3721 | |
| 3722 uint16_t Uint16ArrayTraits::defaultValue() { return 0; } | |
| 3723 | |
| 3724 | |
| 3725 int16_t Int16ArrayTraits::defaultValue() { return 0; } | |
| 3726 | |
| 3727 | |
| 3728 uint32_t Uint32ArrayTraits::defaultValue() { return 0; } | |
| 3729 | |
| 3730 | |
| 3731 int32_t Int32ArrayTraits::defaultValue() { return 0; } | |
| 3732 | |
| 3733 | |
| 3734 float Float32ArrayTraits::defaultValue() { | |
| 3735 return static_cast<float>(OS::nan_value()); | |
| 3736 } | |
| 3737 | |
| 3738 | |
| 3739 double Float64ArrayTraits::defaultValue() { return OS::nan_value(); } | |
| 3740 | |
| 3741 | |
| 3742 template <class Traits> | 3708 template <class Traits> |
| 3743 typename Traits::ElementType FixedTypedArray<Traits>::get_scalar(int index) { | 3709 typename Traits::ElementType FixedTypedArray<Traits>::get_scalar(int index) { |
| 3744 ASSERT((index >= 0) && (index < this->length())); | 3710 ASSERT((index >= 0) && (index < this->length())); |
| 3745 ElementType* ptr = reinterpret_cast<ElementType*>( | 3711 ElementType* ptr = reinterpret_cast<ElementType*>( |
| 3746 FIELD_ADDR(this, kDataOffset)); | 3712 FIELD_ADDR(this, kDataOffset)); |
| 3747 return ptr[index]; | 3713 return ptr[index]; |
| 3748 } | 3714 } |
| 3749 | 3715 |
| 3750 | 3716 |
| 3751 template<> inline | 3717 template<> inline |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3767 | 3733 |
| 3768 template<> inline | 3734 template<> inline |
| 3769 void FixedTypedArray<Float64ArrayTraits>::set( | 3735 void FixedTypedArray<Float64ArrayTraits>::set( |
| 3770 int index, Float64ArrayTraits::ElementType value) { | 3736 int index, Float64ArrayTraits::ElementType value) { |
| 3771 ASSERT((index >= 0) && (index < this->length())); | 3737 ASSERT((index >= 0) && (index < this->length())); |
| 3772 WRITE_DOUBLE_FIELD(this, ElementOffset(index), value); | 3738 WRITE_DOUBLE_FIELD(this, ElementOffset(index), value); |
| 3773 } | 3739 } |
| 3774 | 3740 |
| 3775 | 3741 |
| 3776 template <class Traits> | 3742 template <class Traits> |
| 3777 typename Traits::ElementType FixedTypedArray<Traits>::from_int(int value) { | |
| 3778 return static_cast<ElementType>(value); | |
| 3779 } | |
| 3780 | |
| 3781 | |
| 3782 template <> inline | |
| 3783 uint8_t FixedTypedArray<Uint8ClampedArrayTraits>::from_int(int value) { | |
| 3784 if (value < 0) return 0; | |
| 3785 if (value > 0xFF) return 0xFF; | |
| 3786 return static_cast<uint8_t>(value); | |
| 3787 } | |
| 3788 | |
| 3789 | |
| 3790 template <class Traits> | |
| 3791 typename Traits::ElementType FixedTypedArray<Traits>::from_double( | |
| 3792 double value) { | |
| 3793 return static_cast<ElementType>(DoubleToInt32(value)); | |
| 3794 } | |
| 3795 | |
| 3796 | |
| 3797 template<> inline | |
| 3798 uint8_t FixedTypedArray<Uint8ClampedArrayTraits>::from_double(double value) { | |
| 3799 if (value < 0) return 0; | |
| 3800 if (value > 0xFF) return 0xFF; | |
| 3801 return static_cast<uint8_t>(lrint(value)); | |
| 3802 } | |
| 3803 | |
| 3804 | |
| 3805 template<> inline | |
| 3806 float FixedTypedArray<Float32ArrayTraits>::from_double(double value) { | |
| 3807 return static_cast<float>(value); | |
| 3808 } | |
| 3809 | |
| 3810 | |
| 3811 template<> inline | |
| 3812 double FixedTypedArray<Float64ArrayTraits>::from_double(double value) { | |
| 3813 return value; | |
| 3814 } | |
| 3815 | |
| 3816 | |
| 3817 template <class Traits> | |
| 3818 MaybeObject* FixedTypedArray<Traits>::get(int index) { | 3743 MaybeObject* FixedTypedArray<Traits>::get(int index) { |
| 3819 return Traits::ToObject(GetHeap(), get_scalar(index)); | 3744 return Traits::ToObject(GetHeap(), get_scalar(index)); |
| 3820 } | 3745 } |
| 3821 | 3746 |
| 3822 template <class Traits> | 3747 template <class Traits> |
| 3823 MaybeObject* FixedTypedArray<Traits>::SetValue(uint32_t index, Object* value) { | 3748 MaybeObject* FixedTypedArray<Traits>::SetValue(uint32_t index, Object* value) { |
| 3824 ElementType cast_value = Traits::defaultValue(); | 3749 ElementType cast_value = Traits::defaultValue(); |
| 3825 if (index < static_cast<uint32_t>(length())) { | 3750 if (index < static_cast<uint32_t>(length())) { |
| 3826 if (value->IsSmi()) { | 3751 if (value->IsSmi()) { |
| 3827 int int_value = Smi::cast(value)->value(); | 3752 int int_value = Smi::cast(value)->value(); |
| 3828 cast_value = from_int(int_value); | 3753 cast_value = static_cast<ElementType>(int_value); |
| 3829 } else if (value->IsHeapNumber()) { | 3754 } else if (value->IsHeapNumber()) { |
| 3830 double double_value = HeapNumber::cast(value)->value(); | 3755 double double_value = HeapNumber::cast(value)->value(); |
| 3831 cast_value = from_double(double_value); | 3756 cast_value = static_cast<ElementType>(DoubleToInt32(double_value)); |
| 3832 } else { | 3757 } else { |
| 3833 // Clamp undefined to the default value. All other types have been | 3758 // Clamp undefined to the default value. All other types have been |
| 3834 // converted to a number type further up in the call chain. | 3759 // converted to a number type further up in the call chain. |
| 3835 ASSERT(value->IsUndefined()); | 3760 ASSERT(value->IsUndefined()); |
| 3836 } | 3761 } |
| 3837 set(index, cast_value); | 3762 set(index, cast_value); |
| 3838 } | 3763 } |
| 3839 return Traits::ToObject(GetHeap(), cast_value); | 3764 return Traits::ToObject(GetHeap(), cast_value); |
| 3840 } | 3765 } |
| 3841 | 3766 |
| (...skipping 2247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6089 #undef EXTERNAL_ELEMENTS_CHECK | 6014 #undef EXTERNAL_ELEMENTS_CHECK |
| 6090 | 6015 |
| 6091 | 6016 |
| 6092 bool JSObject::HasFixedTypedArrayElements() { | 6017 bool JSObject::HasFixedTypedArrayElements() { |
| 6093 HeapObject* array = elements(); | 6018 HeapObject* array = elements(); |
| 6094 ASSERT(array != NULL); | 6019 ASSERT(array != NULL); |
| 6095 return array->IsFixedTypedArrayBase(); | 6020 return array->IsFixedTypedArrayBase(); |
| 6096 } | 6021 } |
| 6097 | 6022 |
| 6098 | 6023 |
| 6099 #define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype, size) \ | |
| 6100 bool JSObject::HasFixed##Type##Elements() { \ | |
| 6101 HeapObject* array = elements(); \ | |
| 6102 ASSERT(array != NULL); \ | |
| 6103 if (!array->IsHeapObject()) \ | |
| 6104 return false; \ | |
| 6105 return array->map()->instance_type() == FIXED_##TYPE##_ARRAY_TYPE; \ | |
| 6106 } | |
| 6107 | |
| 6108 TYPED_ARRAYS(FIXED_TYPED_ELEMENTS_CHECK) | |
| 6109 | |
| 6110 #undef FIXED_TYPED_ELEMENTS_CHECK | |
| 6111 | |
| 6112 | |
| 6113 bool JSObject::HasNamedInterceptor() { | 6024 bool JSObject::HasNamedInterceptor() { |
| 6114 return map()->has_named_interceptor(); | 6025 return map()->has_named_interceptor(); |
| 6115 } | 6026 } |
| 6116 | 6027 |
| 6117 | 6028 |
| 6118 bool JSObject::HasIndexedInterceptor() { | 6029 bool JSObject::HasIndexedInterceptor() { |
| 6119 return map()->has_indexed_interceptor(); | 6030 return map()->has_indexed_interceptor(); |
| 6120 } | 6031 } |
| 6121 | 6032 |
| 6122 | 6033 |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6878 #undef READ_UINT32_FIELD | 6789 #undef READ_UINT32_FIELD |
| 6879 #undef WRITE_UINT32_FIELD | 6790 #undef WRITE_UINT32_FIELD |
| 6880 #undef READ_SHORT_FIELD | 6791 #undef READ_SHORT_FIELD |
| 6881 #undef WRITE_SHORT_FIELD | 6792 #undef WRITE_SHORT_FIELD |
| 6882 #undef READ_BYTE_FIELD | 6793 #undef READ_BYTE_FIELD |
| 6883 #undef WRITE_BYTE_FIELD | 6794 #undef WRITE_BYTE_FIELD |
| 6884 | 6795 |
| 6885 } } // namespace v8::internal | 6796 } } // namespace v8::internal |
| 6886 | 6797 |
| 6887 #endif // V8_OBJECTS_INL_H_ | 6798 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |