| 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 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1761 | 1761 | 
| 1762 void JSObject::initialize_elements() { | 1762 void JSObject::initialize_elements() { | 
| 1763   if (map()->has_fast_smi_or_object_elements() || | 1763   if (map()->has_fast_smi_or_object_elements() || | 
| 1764       map()->has_fast_double_elements()) { | 1764       map()->has_fast_double_elements()) { | 
| 1765     ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); | 1765     ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); | 
| 1766     WRITE_FIELD(this, kElementsOffset, GetHeap()->empty_fixed_array()); | 1766     WRITE_FIELD(this, kElementsOffset, GetHeap()->empty_fixed_array()); | 
| 1767   } else if (map()->has_external_array_elements()) { | 1767   } else if (map()->has_external_array_elements()) { | 
| 1768     ExternalArray* empty_array = GetHeap()->EmptyExternalArrayForMap(map()); | 1768     ExternalArray* empty_array = GetHeap()->EmptyExternalArrayForMap(map()); | 
| 1769     ASSERT(!GetHeap()->InNewSpace(empty_array)); | 1769     ASSERT(!GetHeap()->InNewSpace(empty_array)); | 
| 1770     WRITE_FIELD(this, kElementsOffset, empty_array); | 1770     WRITE_FIELD(this, kElementsOffset, empty_array); | 
|  | 1771   } else if (map()->has_fixed_typed_array_elements()) { | 
|  | 1772     FixedTypedArrayBase* empty_array = | 
|  | 1773       GetHeap()->EmptyFixedTypedArrayForMap(map()); | 
|  | 1774     ASSERT(!GetHeap()->InNewSpace(empty_array)); | 
|  | 1775     WRITE_FIELD(this, kElementsOffset, empty_array); | 
| 1771   } else { | 1776   } else { | 
| 1772     UNREACHABLE(); | 1777     UNREACHABLE(); | 
| 1773   } | 1778   } | 
| 1774 } | 1779 } | 
| 1775 | 1780 | 
| 1776 | 1781 | 
| 1777 MaybeObject* JSObject::ResetElements() { | 1782 MaybeObject* JSObject::ResetElements() { | 
| 1778   if (map()->is_observed()) { | 1783   if (map()->is_observed()) { | 
| 1779     // Maintain invariant that observed elements are always in dictionary mode. | 1784     // Maintain invariant that observed elements are always in dictionary mode. | 
| 1780     SeededNumberDictionary* dictionary; | 1785     SeededNumberDictionary* dictionary; | 
| (...skipping 1920 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3701 } | 3706 } | 
| 3702 | 3707 | 
| 3703 | 3708 | 
| 3704 void ExternalFloat64Array::set(int index, double value) { | 3709 void ExternalFloat64Array::set(int index, double value) { | 
| 3705   ASSERT((index >= 0) && (index < this->length())); | 3710   ASSERT((index >= 0) && (index < this->length())); | 
| 3706   double* ptr = static_cast<double*>(external_pointer()); | 3711   double* ptr = static_cast<double*>(external_pointer()); | 
| 3707   ptr[index] = value; | 3712   ptr[index] = value; | 
| 3708 } | 3713 } | 
| 3709 | 3714 | 
| 3710 | 3715 | 
|  | 3716 void* FixedTypedArrayBase::DataPtr() { | 
|  | 3717   return FIELD_ADDR(this, kDataOffset); | 
|  | 3718 } | 
|  | 3719 | 
|  | 3720 | 
|  | 3721 int FixedTypedArrayBase::DataSize() { | 
|  | 3722   InstanceType instance_type = map()->instance_type(); | 
|  | 3723   int element_size; | 
|  | 3724   switch (instance_type) { | 
|  | 3725 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size)                       \ | 
|  | 3726     case FIXED_##TYPE##_ARRAY_TYPE:                                           \ | 
|  | 3727       element_size = size;                                                    \ | 
|  | 3728       break; | 
|  | 3729 | 
|  | 3730     TYPED_ARRAYS(TYPED_ARRAY_CASE) | 
|  | 3731 #undef TYPED_ARRAY_CASE | 
|  | 3732     default: | 
|  | 3733       UNREACHABLE(); | 
|  | 3734       return 0; | 
|  | 3735   } | 
|  | 3736   return length() * element_size; | 
|  | 3737 } | 
|  | 3738 | 
|  | 3739 | 
| 3711 int FixedTypedArrayBase::size() { | 3740 int FixedTypedArrayBase::size() { | 
| 3712   InstanceType instance_type = map()->instance_type(); | 3741   return OBJECT_POINTER_ALIGN(kDataOffset + DataSize()); | 
| 3713   int element_size; |  | 
| 3714   switch (instance_type) { |  | 
| 3715     case FIXED_UINT8_ARRAY_TYPE: |  | 
| 3716     case FIXED_INT8_ARRAY_TYPE: |  | 
| 3717     case FIXED_UINT8_CLAMPED_ARRAY_TYPE: |  | 
| 3718       element_size = 1; |  | 
| 3719       break; |  | 
| 3720     case FIXED_UINT16_ARRAY_TYPE: |  | 
| 3721     case FIXED_INT16_ARRAY_TYPE: |  | 
| 3722       element_size = 2; |  | 
| 3723       break; |  | 
| 3724     case FIXED_UINT32_ARRAY_TYPE: |  | 
| 3725     case FIXED_INT32_ARRAY_TYPE: |  | 
| 3726     case FIXED_FLOAT32_ARRAY_TYPE: |  | 
| 3727       element_size = 4; |  | 
| 3728       break; |  | 
| 3729     case FIXED_FLOAT64_ARRAY_TYPE: |  | 
| 3730       element_size = 8; |  | 
| 3731       break; |  | 
| 3732     default: |  | 
| 3733       UNREACHABLE(); |  | 
| 3734       return 0; |  | 
| 3735   } |  | 
| 3736   return OBJECT_POINTER_ALIGN(kDataOffset + length() * element_size); |  | 
| 3737 } | 3742 } | 
| 3738 | 3743 | 
| 3739 | 3744 | 
|  | 3745 uint8_t Uint8ArrayTraits::defaultValue() { return 0; } | 
|  | 3746 | 
|  | 3747 | 
|  | 3748 uint8_t Uint8ClampedArrayTraits::defaultValue() { return 0; } | 
|  | 3749 | 
|  | 3750 | 
|  | 3751 int8_t Int8ArrayTraits::defaultValue() { return 0; } | 
|  | 3752 | 
|  | 3753 | 
|  | 3754 uint16_t Uint16ArrayTraits::defaultValue() { return 0; } | 
|  | 3755 | 
|  | 3756 | 
|  | 3757 int16_t Int16ArrayTraits::defaultValue() { return 0; } | 
|  | 3758 | 
|  | 3759 | 
|  | 3760 uint32_t Uint32ArrayTraits::defaultValue() { return 0; } | 
|  | 3761 | 
|  | 3762 | 
|  | 3763 int32_t Int32ArrayTraits::defaultValue() { return 0; } | 
|  | 3764 | 
|  | 3765 | 
|  | 3766 float Float32ArrayTraits::defaultValue() { | 
|  | 3767   return static_cast<double>(OS::nan_value()); | 
|  | 3768 } | 
|  | 3769 | 
|  | 3770 | 
|  | 3771 double Float64ArrayTraits::defaultValue() { return OS::nan_value(); } | 
|  | 3772 | 
|  | 3773 | 
| 3740 template <class Traits> | 3774 template <class Traits> | 
| 3741 typename Traits::ElementType FixedTypedArray<Traits>::get_scalar(int index) { | 3775 typename Traits::ElementType FixedTypedArray<Traits>::get_scalar(int index) { | 
| 3742   ASSERT((index >= 0) && (index < this->length())); | 3776   ASSERT((index >= 0) && (index < this->length())); | 
| 3743   ElementType* ptr = reinterpret_cast<ElementType*>( | 3777   ElementType* ptr = reinterpret_cast<ElementType*>( | 
| 3744       FIELD_ADDR(this, kDataOffset)); | 3778       FIELD_ADDR(this, kDataOffset)); | 
| 3745   return ptr[index]; | 3779   return ptr[index]; | 
| 3746 } | 3780 } | 
| 3747 | 3781 | 
| 3748 | 3782 | 
| 3749 template<> inline | 3783 template<> inline | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 3765 | 3799 | 
| 3766 template<> inline | 3800 template<> inline | 
| 3767 void FixedTypedArray<Float64ArrayTraits>::set( | 3801 void FixedTypedArray<Float64ArrayTraits>::set( | 
| 3768     int index, Float64ArrayTraits::ElementType value) { | 3802     int index, Float64ArrayTraits::ElementType value) { | 
| 3769   ASSERT((index >= 0) && (index < this->length())); | 3803   ASSERT((index >= 0) && (index < this->length())); | 
| 3770   WRITE_DOUBLE_FIELD(this, ElementOffset(index), value); | 3804   WRITE_DOUBLE_FIELD(this, ElementOffset(index), value); | 
| 3771 } | 3805 } | 
| 3772 | 3806 | 
| 3773 | 3807 | 
| 3774 template <class Traits> | 3808 template <class Traits> | 
|  | 3809 typename Traits::ElementType FixedTypedArray<Traits>::from_int(int value) { | 
|  | 3810   return static_cast<ElementType>(value); | 
|  | 3811 } | 
|  | 3812 | 
|  | 3813 | 
|  | 3814 template <> inline | 
|  | 3815 uint8_t FixedTypedArray<Uint8ClampedArrayTraits>::from_int(int value) { | 
|  | 3816   if (value < 0) return 0; | 
|  | 3817   if (value > 0xFF) return 0xFF; | 
|  | 3818   return static_cast<uint8_t>(value); | 
|  | 3819 } | 
|  | 3820 | 
|  | 3821 | 
|  | 3822 template <class Traits> | 
|  | 3823 typename Traits::ElementType FixedTypedArray<Traits>::from_double( | 
|  | 3824     double value) { | 
|  | 3825   return static_cast<ElementType>(DoubleToInt32(value)); | 
|  | 3826 } | 
|  | 3827 | 
|  | 3828 | 
|  | 3829 template<> inline | 
|  | 3830 uint8_t FixedTypedArray<Uint8ClampedArrayTraits>::from_double(double value) { | 
|  | 3831   if (value < 0) return 0; | 
|  | 3832   if (value > 0xFF) return 0xFF; | 
|  | 3833   return static_cast<uint8_t>(lrint(value)); | 
|  | 3834 } | 
|  | 3835 | 
|  | 3836 | 
|  | 3837 template<> inline | 
|  | 3838 float FixedTypedArray<Float32ArrayTraits>::from_double(double value) { | 
|  | 3839   return static_cast<float>(value); | 
|  | 3840 } | 
|  | 3841 | 
|  | 3842 | 
|  | 3843 template<> inline | 
|  | 3844 double FixedTypedArray<Float64ArrayTraits>::from_double(double value) { | 
|  | 3845   return value; | 
|  | 3846 } | 
|  | 3847 | 
|  | 3848 | 
|  | 3849 template <class Traits> | 
| 3775 MaybeObject* FixedTypedArray<Traits>::get(int index) { | 3850 MaybeObject* FixedTypedArray<Traits>::get(int index) { | 
| 3776   return Traits::ToObject(GetHeap(), get_scalar(index)); | 3851   return Traits::ToObject(GetHeap(), get_scalar(index)); | 
| 3777 } | 3852 } | 
| 3778 | 3853 | 
| 3779 template <class Traits> | 3854 template <class Traits> | 
| 3780 MaybeObject* FixedTypedArray<Traits>::SetValue(uint32_t index, Object* value) { | 3855 MaybeObject* FixedTypedArray<Traits>::SetValue(uint32_t index, Object* value) { | 
| 3781   ElementType cast_value = Traits::defaultValue(); | 3856   ElementType cast_value = Traits::defaultValue(); | 
| 3782   if (index < static_cast<uint32_t>(length())) { | 3857   if (index < static_cast<uint32_t>(length())) { | 
| 3783     if (value->IsSmi()) { | 3858     if (value->IsSmi()) { | 
| 3784       int int_value = Smi::cast(value)->value(); | 3859       int int_value = Smi::cast(value)->value(); | 
| 3785       cast_value = static_cast<ElementType>(int_value); | 3860       cast_value = from_int(int_value); | 
| 3786     } else if (value->IsHeapNumber()) { | 3861     } else if (value->IsHeapNumber()) { | 
| 3787       double double_value = HeapNumber::cast(value)->value(); | 3862       double double_value = HeapNumber::cast(value)->value(); | 
| 3788       cast_value = static_cast<ElementType>(DoubleToInt32(double_value)); | 3863       cast_value = from_double(double_value); | 
| 3789     } else { | 3864     } else { | 
| 3790       // Clamp undefined to the default value. All other types have been | 3865       // Clamp undefined to the default value. All other types have been | 
| 3791       // converted to a number type further up in the call chain. | 3866       // converted to a number type further up in the call chain. | 
| 3792       ASSERT(value->IsUndefined()); | 3867       ASSERT(value->IsUndefined()); | 
| 3793     } | 3868     } | 
| 3794     set(index, cast_value); | 3869     set(index, cast_value); | 
| 3795   } | 3870   } | 
| 3796   return Traits::ToObject(GetHeap(), cast_value); | 3871   return Traits::ToObject(GetHeap(), cast_value); | 
| 3797 } | 3872 } | 
| 3798 | 3873 | 
| (...skipping 2247 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 6046 #undef EXTERNAL_ELEMENTS_CHECK | 6121 #undef EXTERNAL_ELEMENTS_CHECK | 
| 6047 | 6122 | 
| 6048 | 6123 | 
| 6049 bool JSObject::HasFixedTypedArrayElements() { | 6124 bool JSObject::HasFixedTypedArrayElements() { | 
| 6050   HeapObject* array = elements(); | 6125   HeapObject* array = elements(); | 
| 6051   ASSERT(array != NULL); | 6126   ASSERT(array != NULL); | 
| 6052   return array->IsFixedTypedArrayBase(); | 6127   return array->IsFixedTypedArrayBase(); | 
| 6053 } | 6128 } | 
| 6054 | 6129 | 
| 6055 | 6130 | 
|  | 6131 #define FIXED_TYPED_ELEMENTS_CHECK(Type, type, TYPE, ctype, size)         \ | 
|  | 6132 bool JSObject::HasFixed##Type##Elements() {                               \ | 
|  | 6133   HeapObject* array = elements();                                         \ | 
|  | 6134   ASSERT(array != NULL);                                                  \ | 
|  | 6135   if (!array->IsHeapObject())                                             \ | 
|  | 6136     return false;                                                         \ | 
|  | 6137   return array->map()->instance_type() == FIXED_##TYPE##_ARRAY_TYPE;      \ | 
|  | 6138 } | 
|  | 6139 | 
|  | 6140 TYPED_ARRAYS(FIXED_TYPED_ELEMENTS_CHECK) | 
|  | 6141 | 
|  | 6142 #undef FIXED_TYPED_ELEMENTS_CHECK | 
|  | 6143 | 
|  | 6144 | 
| 6056 bool JSObject::HasNamedInterceptor() { | 6145 bool JSObject::HasNamedInterceptor() { | 
| 6057   return map()->has_named_interceptor(); | 6146   return map()->has_named_interceptor(); | 
| 6058 } | 6147 } | 
| 6059 | 6148 | 
| 6060 | 6149 | 
| 6061 bool JSObject::HasIndexedInterceptor() { | 6150 bool JSObject::HasIndexedInterceptor() { | 
| 6062   return map()->has_indexed_interceptor(); | 6151   return map()->has_indexed_interceptor(); | 
| 6063 } | 6152 } | 
| 6064 | 6153 | 
| 6065 | 6154 | 
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 6821 #undef READ_UINT32_FIELD | 6910 #undef READ_UINT32_FIELD | 
| 6822 #undef WRITE_UINT32_FIELD | 6911 #undef WRITE_UINT32_FIELD | 
| 6823 #undef READ_SHORT_FIELD | 6912 #undef READ_SHORT_FIELD | 
| 6824 #undef WRITE_SHORT_FIELD | 6913 #undef WRITE_SHORT_FIELD | 
| 6825 #undef READ_BYTE_FIELD | 6914 #undef READ_BYTE_FIELD | 
| 6826 #undef WRITE_BYTE_FIELD | 6915 #undef WRITE_BYTE_FIELD | 
| 6827 | 6916 | 
| 6828 } }  // namespace v8::internal | 6917 } }  // namespace v8::internal | 
| 6829 | 6918 | 
| 6830 #endif  // V8_OBJECTS_INL_H_ | 6919 #endif  // V8_OBJECTS_INL_H_ | 
| OLD | NEW | 
|---|