| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 14773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14784 TYPED_ARRAYS(INSTANCE_TYPE_TO_ELEMENT_SIZE) | 14784 TYPED_ARRAYS(INSTANCE_TYPE_TO_ELEMENT_SIZE) |
| 14785 #undef INSTANCE_TYPE_TO_ELEMENT_SIZE | 14785 #undef INSTANCE_TYPE_TO_ELEMENT_SIZE |
| 14786 | 14786 |
| 14787 default: | 14787 default: |
| 14788 UNREACHABLE(); | 14788 UNREACHABLE(); |
| 14789 return 0; | 14789 return 0; |
| 14790 } | 14790 } |
| 14791 } | 14791 } |
| 14792 | 14792 |
| 14793 | 14793 |
| 14794 Object* ExternalUint8ClampedArray::SetValue(uint32_t index, Object* value) { | 14794 Handle<Object> ExternalUint8ClampedArray::SetValue( |
| 14795 Handle<ExternalUint8ClampedArray> array, |
| 14796 uint32_t index, |
| 14797 Handle<Object> value) { |
| 14795 uint8_t clamped_value = 0; | 14798 uint8_t clamped_value = 0; |
| 14796 if (index < static_cast<uint32_t>(length())) { | 14799 if (index < static_cast<uint32_t>(array->length())) { |
| 14797 if (value->IsSmi()) { | 14800 if (value->IsSmi()) { |
| 14798 int int_value = Smi::cast(value)->value(); | 14801 int int_value = Handle<Smi>::cast(value)->value(); |
| 14799 if (int_value < 0) { | 14802 if (int_value < 0) { |
| 14800 clamped_value = 0; | 14803 clamped_value = 0; |
| 14801 } else if (int_value > 255) { | 14804 } else if (int_value > 255) { |
| 14802 clamped_value = 255; | 14805 clamped_value = 255; |
| 14803 } else { | 14806 } else { |
| 14804 clamped_value = static_cast<uint8_t>(int_value); | 14807 clamped_value = static_cast<uint8_t>(int_value); |
| 14805 } | 14808 } |
| 14806 } else if (value->IsHeapNumber()) { | 14809 } else if (value->IsHeapNumber()) { |
| 14807 double double_value = HeapNumber::cast(value)->value(); | 14810 double double_value = Handle<HeapNumber>::cast(value)->value(); |
| 14808 if (!(double_value > 0)) { | 14811 if (!(double_value > 0)) { |
| 14809 // NaN and less than zero clamp to zero. | 14812 // NaN and less than zero clamp to zero. |
| 14810 clamped_value = 0; | 14813 clamped_value = 0; |
| 14811 } else if (double_value > 255) { | 14814 } else if (double_value > 255) { |
| 14812 // Greater than 255 clamp to 255. | 14815 // Greater than 255 clamp to 255. |
| 14813 clamped_value = 255; | 14816 clamped_value = 255; |
| 14814 } else { | 14817 } else { |
| 14815 // Other doubles are rounded to the nearest integer. | 14818 // Other doubles are rounded to the nearest integer. |
| 14816 clamped_value = static_cast<uint8_t>(lrint(double_value)); | 14819 clamped_value = static_cast<uint8_t>(lrint(double_value)); |
| 14817 } | 14820 } |
| 14818 } else { | 14821 } else { |
| 14819 // Clamp undefined to zero (default). All other types have been | 14822 // Clamp undefined to zero (default). All other types have been |
| 14820 // converted to a number type further up in the call chain. | 14823 // converted to a number type further up in the call chain. |
| 14821 ASSERT(value->IsUndefined()); | 14824 ASSERT(value->IsUndefined()); |
| 14822 } | 14825 } |
| 14823 set(index, clamped_value); | 14826 array->set(index, clamped_value); |
| 14824 } | 14827 } |
| 14825 return Smi::FromInt(clamped_value); | 14828 return handle(Smi::FromInt(clamped_value), array->GetIsolate()); |
| 14826 } | |
| 14827 | |
| 14828 | |
| 14829 Handle<Object> ExternalUint8ClampedArray::SetValue( | |
| 14830 Handle<ExternalUint8ClampedArray> array, | |
| 14831 uint32_t index, | |
| 14832 Handle<Object> value) { | |
| 14833 return Handle<Object>(array->SetValue(index, *value), array->GetIsolate()); | |
| 14834 } | 14829 } |
| 14835 | 14830 |
| 14836 | 14831 |
| 14837 template<typename ExternalArrayClass, typename ValueType> | 14832 template<typename ExternalArrayClass, typename ValueType> |
| 14838 static MaybeObject* ExternalArrayIntSetter(Heap* heap, | 14833 static Handle<Object> ExternalArrayIntSetter( |
| 14839 ExternalArrayClass* receiver, | 14834 Isolate* isolate, |
| 14840 uint32_t index, | 14835 Handle<ExternalArrayClass> receiver, |
| 14841 Object* value) { | 14836 uint32_t index, |
| 14837 Handle<Object> value) { |
| 14842 ValueType cast_value = 0; | 14838 ValueType cast_value = 0; |
| 14843 if (index < static_cast<uint32_t>(receiver->length())) { | 14839 if (index < static_cast<uint32_t>(receiver->length())) { |
| 14844 if (value->IsSmi()) { | 14840 if (value->IsSmi()) { |
| 14845 int int_value = Smi::cast(value)->value(); | 14841 int int_value = Handle<Smi>::cast(value)->value(); |
| 14846 cast_value = static_cast<ValueType>(int_value); | 14842 cast_value = static_cast<ValueType>(int_value); |
| 14847 } else if (value->IsHeapNumber()) { | 14843 } else if (value->IsHeapNumber()) { |
| 14848 double double_value = HeapNumber::cast(value)->value(); | 14844 double double_value = Handle<HeapNumber>::cast(value)->value(); |
| 14849 cast_value = static_cast<ValueType>(DoubleToInt32(double_value)); | 14845 cast_value = static_cast<ValueType>(DoubleToInt32(double_value)); |
| 14850 } else { | 14846 } else { |
| 14851 // Clamp undefined to zero (default). All other types have been | 14847 // Clamp undefined to zero (default). All other types have been |
| 14852 // converted to a number type further up in the call chain. | 14848 // converted to a number type further up in the call chain. |
| 14853 ASSERT(value->IsUndefined()); | 14849 ASSERT(value->IsUndefined()); |
| 14854 } | 14850 } |
| 14855 receiver->set(index, cast_value); | 14851 receiver->set(index, cast_value); |
| 14856 } | 14852 } |
| 14857 return heap->NumberFromInt32(cast_value); | 14853 return isolate->factory()->NewNumberFromInt(cast_value); |
| 14858 } | 14854 } |
| 14859 | 14855 |
| 14860 | 14856 |
| 14861 Handle<Object> ExternalInt8Array::SetValue(Handle<ExternalInt8Array> array, | 14857 Handle<Object> ExternalInt8Array::SetValue(Handle<ExternalInt8Array> array, |
| 14862 uint32_t index, | 14858 uint32_t index, |
| 14863 Handle<Object> value) { | 14859 Handle<Object> value) { |
| 14864 CALL_HEAP_FUNCTION(array->GetIsolate(), | 14860 return ExternalArrayIntSetter<ExternalInt8Array, int8_t>( |
| 14865 array->SetValue(index, *value), | 14861 array->GetIsolate(), array, index, value); |
| 14866 Object); | |
| 14867 } | 14862 } |
| 14868 | 14863 |
| 14869 | 14864 |
| 14870 MaybeObject* ExternalInt8Array::SetValue(uint32_t index, Object* value) { | 14865 Handle<Object> ExternalUint8Array::SetValue(Handle<ExternalUint8Array> array, |
| 14871 return ExternalArrayIntSetter<ExternalInt8Array, int8_t> | 14866 uint32_t index, |
| 14872 (GetHeap(), this, index, value); | 14867 Handle<Object> value) { |
| 14868 return ExternalArrayIntSetter<ExternalUint8Array, uint8_t>( |
| 14869 array->GetIsolate(), array, index, value); |
| 14873 } | 14870 } |
| 14874 | 14871 |
| 14875 | 14872 |
| 14876 Handle<Object> ExternalUint8Array::SetValue( | 14873 Handle<Object> ExternalInt16Array::SetValue(Handle<ExternalInt16Array> array, |
| 14877 Handle<ExternalUint8Array> array, | 14874 uint32_t index, |
| 14878 uint32_t index, | 14875 Handle<Object> value) { |
| 14879 Handle<Object> value) { | 14876 return ExternalArrayIntSetter<ExternalInt16Array, int16_t>( |
| 14880 CALL_HEAP_FUNCTION(array->GetIsolate(), | 14877 array->GetIsolate(), array, index, value); |
| 14881 array->SetValue(index, *value), | |
| 14882 Object); | |
| 14883 } | 14878 } |
| 14884 | 14879 |
| 14885 | 14880 |
| 14886 MaybeObject* ExternalUint8Array::SetValue(uint32_t index, | 14881 Handle<Object> ExternalUint16Array::SetValue(Handle<ExternalUint16Array> array, |
| 14887 Object* value) { | 14882 uint32_t index, |
| 14888 return ExternalArrayIntSetter<ExternalUint8Array, uint8_t> | 14883 Handle<Object> value) { |
| 14889 (GetHeap(), this, index, value); | 14884 return ExternalArrayIntSetter<ExternalUint16Array, uint16_t>( |
| 14890 } | 14885 array->GetIsolate(), array, index, value); |
| 14891 | |
| 14892 | |
| 14893 Handle<Object> ExternalInt16Array::SetValue( | |
| 14894 Handle<ExternalInt16Array> array, | |
| 14895 uint32_t index, | |
| 14896 Handle<Object> value) { | |
| 14897 CALL_HEAP_FUNCTION(array->GetIsolate(), | |
| 14898 array->SetValue(index, *value), | |
| 14899 Object); | |
| 14900 } | |
| 14901 | |
| 14902 | |
| 14903 MaybeObject* ExternalInt16Array::SetValue(uint32_t index, | |
| 14904 Object* value) { | |
| 14905 return ExternalArrayIntSetter<ExternalInt16Array, int16_t> | |
| 14906 (GetHeap(), this, index, value); | |
| 14907 } | |
| 14908 | |
| 14909 | |
| 14910 Handle<Object> ExternalUint16Array::SetValue( | |
| 14911 Handle<ExternalUint16Array> array, | |
| 14912 uint32_t index, | |
| 14913 Handle<Object> value) { | |
| 14914 CALL_HEAP_FUNCTION(array->GetIsolate(), | |
| 14915 array->SetValue(index, *value), | |
| 14916 Object); | |
| 14917 } | |
| 14918 | |
| 14919 | |
| 14920 MaybeObject* ExternalUint16Array::SetValue(uint32_t index, | |
| 14921 Object* value) { | |
| 14922 return ExternalArrayIntSetter<ExternalUint16Array, uint16_t> | |
| 14923 (GetHeap(), this, index, value); | |
| 14924 } | 14886 } |
| 14925 | 14887 |
| 14926 | 14888 |
| 14927 Handle<Object> ExternalInt32Array::SetValue(Handle<ExternalInt32Array> array, | 14889 Handle<Object> ExternalInt32Array::SetValue(Handle<ExternalInt32Array> array, |
| 14928 uint32_t index, | 14890 uint32_t index, |
| 14929 Handle<Object> value) { | 14891 Handle<Object> value) { |
| 14930 CALL_HEAP_FUNCTION(array->GetIsolate(), | 14892 return ExternalArrayIntSetter<ExternalInt32Array, int32_t>( |
| 14931 array->SetValue(index, *value), | 14893 array->GetIsolate(), array, index, value); |
| 14932 Object); | |
| 14933 } | 14894 } |
| 14934 | 14895 |
| 14935 | 14896 |
| 14936 MaybeObject* ExternalInt32Array::SetValue(uint32_t index, Object* value) { | |
| 14937 return ExternalArrayIntSetter<ExternalInt32Array, int32_t> | |
| 14938 (GetHeap(), this, index, value); | |
| 14939 } | |
| 14940 | |
| 14941 | |
| 14942 Handle<Object> ExternalUint32Array::SetValue( | 14897 Handle<Object> ExternalUint32Array::SetValue( |
| 14943 Handle<ExternalUint32Array> array, | 14898 Handle<ExternalUint32Array> array, |
| 14944 uint32_t index, | 14899 uint32_t index, |
| 14945 Handle<Object> value) { | 14900 Handle<Object> value) { |
| 14946 CALL_HEAP_FUNCTION(array->GetIsolate(), | |
| 14947 array->SetValue(index, *value), | |
| 14948 Object); | |
| 14949 } | |
| 14950 | |
| 14951 | |
| 14952 MaybeObject* ExternalUint32Array::SetValue(uint32_t index, Object* value) { | |
| 14953 uint32_t cast_value = 0; | 14901 uint32_t cast_value = 0; |
| 14954 Heap* heap = GetHeap(); | 14902 if (index < static_cast<uint32_t>(array->length())) { |
| 14955 if (index < static_cast<uint32_t>(length())) { | |
| 14956 if (value->IsSmi()) { | 14903 if (value->IsSmi()) { |
| 14957 int int_value = Smi::cast(value)->value(); | 14904 int int_value = Handle<Smi>::cast(value)->value(); |
| 14958 cast_value = static_cast<uint32_t>(int_value); | 14905 cast_value = static_cast<uint32_t>(int_value); |
| 14959 } else if (value->IsHeapNumber()) { | 14906 } else if (value->IsHeapNumber()) { |
| 14960 double double_value = HeapNumber::cast(value)->value(); | 14907 double double_value = Handle<HeapNumber>::cast(value)->value(); |
| 14961 cast_value = static_cast<uint32_t>(DoubleToUint32(double_value)); | 14908 cast_value = static_cast<uint32_t>(DoubleToUint32(double_value)); |
| 14962 } else { | 14909 } else { |
| 14963 // Clamp undefined to zero (default). All other types have been | 14910 // Clamp undefined to zero (default). All other types have been |
| 14964 // converted to a number type further up in the call chain. | 14911 // converted to a number type further up in the call chain. |
| 14965 ASSERT(value->IsUndefined()); | 14912 ASSERT(value->IsUndefined()); |
| 14966 } | 14913 } |
| 14967 set(index, cast_value); | 14914 array->set(index, cast_value); |
| 14968 } | 14915 } |
| 14969 return heap->NumberFromUint32(cast_value); | 14916 return array->GetIsolate()->factory()->NewNumberFromUint(cast_value); |
| 14970 } | 14917 } |
| 14971 | 14918 |
| 14972 | 14919 |
| 14973 Handle<Object> ExternalFloat32Array::SetValue( | 14920 Handle<Object> ExternalFloat32Array::SetValue( |
| 14974 Handle<ExternalFloat32Array> array, | 14921 Handle<ExternalFloat32Array> array, |
| 14975 uint32_t index, | 14922 uint32_t index, |
| 14976 Handle<Object> value) { | 14923 Handle<Object> value) { |
| 14977 CALL_HEAP_FUNCTION(array->GetIsolate(), | |
| 14978 array->SetValue(index, *value), | |
| 14979 Object); | |
| 14980 } | |
| 14981 | |
| 14982 | |
| 14983 MaybeObject* ExternalFloat32Array::SetValue(uint32_t index, Object* value) { | |
| 14984 float cast_value = static_cast<float>(OS::nan_value()); | 14924 float cast_value = static_cast<float>(OS::nan_value()); |
| 14985 Heap* heap = GetHeap(); | 14925 if (index < static_cast<uint32_t>(array->length())) { |
| 14986 if (index < static_cast<uint32_t>(length())) { | |
| 14987 if (value->IsSmi()) { | 14926 if (value->IsSmi()) { |
| 14988 int int_value = Smi::cast(value)->value(); | 14927 int int_value = Handle<Smi>::cast(value)->value(); |
| 14989 cast_value = static_cast<float>(int_value); | 14928 cast_value = static_cast<float>(int_value); |
| 14990 } else if (value->IsHeapNumber()) { | 14929 } else if (value->IsHeapNumber()) { |
| 14991 double double_value = HeapNumber::cast(value)->value(); | 14930 double double_value = Handle<HeapNumber>::cast(value)->value(); |
| 14992 cast_value = static_cast<float>(double_value); | 14931 cast_value = static_cast<float>(double_value); |
| 14993 } else { | 14932 } else { |
| 14994 // Clamp undefined to NaN (default). All other types have been | 14933 // Clamp undefined to NaN (default). All other types have been |
| 14995 // converted to a number type further up in the call chain. | 14934 // converted to a number type further up in the call chain. |
| 14996 ASSERT(value->IsUndefined()); | 14935 ASSERT(value->IsUndefined()); |
| 14997 } | 14936 } |
| 14998 set(index, cast_value); | 14937 array->set(index, cast_value); |
| 14999 } | 14938 } |
| 15000 return heap->AllocateHeapNumber(cast_value); | 14939 return array->GetIsolate()->factory()->NewNumber(cast_value); |
| 15001 } | 14940 } |
| 15002 | 14941 |
| 15003 | 14942 |
| 15004 Handle<Object> ExternalFloat64Array::SetValue( | 14943 Handle<Object> ExternalFloat64Array::SetValue( |
| 15005 Handle<ExternalFloat64Array> array, | 14944 Handle<ExternalFloat64Array> array, |
| 15006 uint32_t index, | 14945 uint32_t index, |
| 15007 Handle<Object> value) { | 14946 Handle<Object> value) { |
| 15008 CALL_HEAP_FUNCTION(array->GetIsolate(), | |
| 15009 array->SetValue(index, *value), | |
| 15010 Object); | |
| 15011 } | |
| 15012 | |
| 15013 | |
| 15014 MaybeObject* ExternalFloat64Array::SetValue(uint32_t index, Object* value) { | |
| 15015 double double_value = OS::nan_value(); | 14947 double double_value = OS::nan_value(); |
| 15016 Heap* heap = GetHeap(); | 14948 if (index < static_cast<uint32_t>(array->length())) { |
| 15017 if (index < static_cast<uint32_t>(length())) { | 14949 if (value->IsNumber()) { |
| 15018 if (value->IsSmi()) { | 14950 double_value = value->Number(); |
| 15019 int int_value = Smi::cast(value)->value(); | |
| 15020 double_value = static_cast<double>(int_value); | |
| 15021 } else if (value->IsHeapNumber()) { | |
| 15022 double_value = HeapNumber::cast(value)->value(); | |
| 15023 } else { | 14951 } else { |
| 15024 // Clamp undefined to NaN (default). All other types have been | 14952 // Clamp undefined to NaN (default). All other types have been |
| 15025 // converted to a number type further up in the call chain. | 14953 // converted to a number type further up in the call chain. |
| 15026 ASSERT(value->IsUndefined()); | 14954 ASSERT(value->IsUndefined()); |
| 15027 } | 14955 } |
| 15028 set(index, double_value); | 14956 array->set(index, double_value); |
| 15029 } | 14957 } |
| 15030 return heap->AllocateHeapNumber(double_value); | 14958 return array->GetIsolate()->factory()->NewNumber(double_value); |
| 15031 } | 14959 } |
| 15032 | 14960 |
| 15033 | 14961 |
| 15034 PropertyCell* GlobalObject::GetPropertyCell(LookupResult* result) { | 14962 PropertyCell* GlobalObject::GetPropertyCell(LookupResult* result) { |
| 15035 ASSERT(!HasFastProperties()); | 14963 ASSERT(!HasFastProperties()); |
| 15036 Object* value = property_dictionary()->ValueAt(result->GetDictionaryEntry()); | 14964 Object* value = property_dictionary()->ValueAt(result->GetDictionaryEntry()); |
| 15037 return PropertyCell::cast(value); | 14965 return PropertyCell::cast(value); |
| 15038 } | 14966 } |
| 15039 | 14967 |
| 15040 | 14968 |
| (...skipping 1651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16692 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16620 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 16693 static const char* error_messages_[] = { | 16621 static const char* error_messages_[] = { |
| 16694 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16622 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 16695 }; | 16623 }; |
| 16696 #undef ERROR_MESSAGES_TEXTS | 16624 #undef ERROR_MESSAGES_TEXTS |
| 16697 return error_messages_[reason]; | 16625 return error_messages_[reason]; |
| 16698 } | 16626 } |
| 16699 | 16627 |
| 16700 | 16628 |
| 16701 } } // namespace v8::internal | 16629 } } // namespace v8::internal |
| OLD | NEW |