| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <iomanip> | 5 #include <iomanip> |
| 6 #include <sstream> | 6 #include <sstream> |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
| (...skipping 14674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14685 TYPED_ARRAYS(INSTANCE_TYPE_TO_ELEMENT_SIZE) | 14685 TYPED_ARRAYS(INSTANCE_TYPE_TO_ELEMENT_SIZE) |
| 14686 #undef INSTANCE_TYPE_TO_ELEMENT_SIZE | 14686 #undef INSTANCE_TYPE_TO_ELEMENT_SIZE |
| 14687 | 14687 |
| 14688 default: | 14688 default: |
| 14689 UNREACHABLE(); | 14689 UNREACHABLE(); |
| 14690 return 0; | 14690 return 0; |
| 14691 } | 14691 } |
| 14692 } | 14692 } |
| 14693 | 14693 |
| 14694 | 14694 |
| 14695 void FixedArray::SetValue(Handle<JSObject> holder, Handle<FixedArray> array, | 14695 void FixedArray::SetValue(Handle<FixedArray> array, uint32_t index, |
| 14696 uint32_t index, Handle<Object> value) { | 14696 Handle<Object> value) { |
| 14697 array->set(index, *value); | 14697 array->set(index, *value); |
| 14698 } | 14698 } |
| 14699 | 14699 |
| 14700 | 14700 |
| 14701 void FixedDoubleArray::SetValue(Handle<JSObject> holder, | 14701 void FixedDoubleArray::SetValue(Handle<FixedDoubleArray> array, uint32_t index, |
| 14702 Handle<FixedDoubleArray> array, uint32_t index, | |
| 14703 Handle<Object> value) { | 14702 Handle<Object> value) { |
| 14704 array->set(index, value->Number()); | 14703 array->set(index, value->Number()); |
| 14705 } | 14704 } |
| 14706 | 14705 |
| 14707 | 14706 |
| 14708 void ExternalUint8ClampedArray::SetValue( | 14707 void ExternalUint8ClampedArray::SetValue( |
| 14709 Handle<JSObject> holder, Handle<ExternalUint8ClampedArray> array, | 14708 Handle<ExternalUint8ClampedArray> array, uint32_t index, |
| 14710 uint32_t index, Handle<Object> value) { | 14709 Handle<Object> value) { |
| 14711 uint8_t clamped_value = 0; | 14710 uint8_t clamped_value = 0; |
| 14712 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); | 14711 if (value->IsSmi()) { |
| 14713 if (!view->WasNeutered()) { | 14712 int int_value = Handle<Smi>::cast(value)->value(); |
| 14714 if (index < static_cast<uint32_t>(array->length())) { | 14713 if (int_value < 0) { |
| 14715 if (value->IsSmi()) { | 14714 clamped_value = 0; |
| 14716 int int_value = Handle<Smi>::cast(value)->value(); | 14715 } else if (int_value > 255) { |
| 14717 if (int_value < 0) { | 14716 clamped_value = 255; |
| 14718 clamped_value = 0; | 14717 } else { |
| 14719 } else if (int_value > 255) { | 14718 clamped_value = static_cast<uint8_t>(int_value); |
| 14720 clamped_value = 255; | |
| 14721 } else { | |
| 14722 clamped_value = static_cast<uint8_t>(int_value); | |
| 14723 } | |
| 14724 } else if (value->IsHeapNumber()) { | |
| 14725 double double_value = Handle<HeapNumber>::cast(value)->value(); | |
| 14726 if (!(double_value > 0)) { | |
| 14727 // NaN and less than zero clamp to zero. | |
| 14728 clamped_value = 0; | |
| 14729 } else if (double_value > 255) { | |
| 14730 // Greater than 255 clamp to 255. | |
| 14731 clamped_value = 255; | |
| 14732 } else { | |
| 14733 // Other doubles are rounded to the nearest integer. | |
| 14734 clamped_value = static_cast<uint8_t>(lrint(double_value)); | |
| 14735 } | |
| 14736 } else { | |
| 14737 // Clamp undefined to zero (default). All other types have been | |
| 14738 // converted to a number type further up in the call chain. | |
| 14739 DCHECK(value->IsUndefined()); | |
| 14740 } | |
| 14741 array->set(index, clamped_value); | |
| 14742 } | 14719 } |
| 14720 } else if (value->IsHeapNumber()) { |
| 14721 double double_value = Handle<HeapNumber>::cast(value)->value(); |
| 14722 if (!(double_value > 0)) { |
| 14723 // NaN and less than zero clamp to zero. |
| 14724 clamped_value = 0; |
| 14725 } else if (double_value > 255) { |
| 14726 // Greater than 255 clamp to 255. |
| 14727 clamped_value = 255; |
| 14728 } else { |
| 14729 // Other doubles are rounded to the nearest integer. |
| 14730 clamped_value = static_cast<uint8_t>(lrint(double_value)); |
| 14731 } |
| 14732 } else { |
| 14733 // Clamp undefined to zero (default). All other types have been |
| 14734 // converted to a number type further up in the call chain. |
| 14735 DCHECK(value->IsUndefined()); |
| 14743 } | 14736 } |
| 14737 array->set(index, clamped_value); |
| 14744 } | 14738 } |
| 14745 | 14739 |
| 14746 | 14740 |
| 14747 template <typename ExternalArrayClass, typename ValueType> | 14741 template <typename ExternalArrayClass, typename ValueType> |
| 14748 static void ExternalArrayIntSetter(Isolate* isolate, Handle<JSObject> holder, | 14742 static void ExternalArrayIntSetter(Handle<ExternalArrayClass> receiver, |
| 14749 Handle<ExternalArrayClass> receiver, | |
| 14750 uint32_t index, Handle<Object> value) { | 14743 uint32_t index, Handle<Object> value) { |
| 14751 ValueType cast_value = 0; | 14744 ValueType cast_value = 0; |
| 14752 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); | 14745 if (value->IsSmi()) { |
| 14753 if (!view->WasNeutered()) { | 14746 int int_value = Handle<Smi>::cast(value)->value(); |
| 14754 if (index < static_cast<uint32_t>(receiver->length())) { | 14747 cast_value = static_cast<ValueType>(int_value); |
| 14755 if (value->IsSmi()) { | 14748 } else if (value->IsHeapNumber()) { |
| 14756 int int_value = Handle<Smi>::cast(value)->value(); | 14749 double double_value = Handle<HeapNumber>::cast(value)->value(); |
| 14757 cast_value = static_cast<ValueType>(int_value); | 14750 cast_value = static_cast<ValueType>(DoubleToInt32(double_value)); |
| 14758 } else if (value->IsHeapNumber()) { | 14751 } else { |
| 14759 double double_value = Handle<HeapNumber>::cast(value)->value(); | 14752 // Clamp undefined to zero (default). All other types have been |
| 14760 cast_value = static_cast<ValueType>(DoubleToInt32(double_value)); | 14753 // converted to a number type further up in the call chain. |
| 14761 } else { | 14754 DCHECK(value->IsUndefined()); |
| 14762 // Clamp undefined to zero (default). All other types have been | |
| 14763 // converted to a number type further up in the call chain. | |
| 14764 DCHECK(value->IsUndefined()); | |
| 14765 } | |
| 14766 receiver->set(index, cast_value); | |
| 14767 } | |
| 14768 } | 14755 } |
| 14756 receiver->set(index, cast_value); |
| 14769 } | 14757 } |
| 14770 | 14758 |
| 14771 | 14759 |
| 14772 void ExternalInt8Array::SetValue(Handle<JSObject> holder, | 14760 void ExternalInt8Array::SetValue(Handle<ExternalInt8Array> array, |
| 14773 Handle<ExternalInt8Array> array, | |
| 14774 uint32_t index, Handle<Object> value) { | 14761 uint32_t index, Handle<Object> value) { |
| 14775 ExternalArrayIntSetter<ExternalInt8Array, int8_t>(array->GetIsolate(), holder, | 14762 ExternalArrayIntSetter<ExternalInt8Array, int8_t>(array, index, value); |
| 14776 array, index, value); | |
| 14777 } | 14763 } |
| 14778 | 14764 |
| 14779 | 14765 |
| 14780 void ExternalUint8Array::SetValue(Handle<JSObject> holder, | 14766 void ExternalUint8Array::SetValue(Handle<ExternalUint8Array> array, |
| 14781 Handle<ExternalUint8Array> array, | |
| 14782 uint32_t index, Handle<Object> value) { | 14767 uint32_t index, Handle<Object> value) { |
| 14783 ExternalArrayIntSetter<ExternalUint8Array, uint8_t>( | 14768 ExternalArrayIntSetter<ExternalUint8Array, uint8_t>(array, index, value); |
| 14784 array->GetIsolate(), holder, array, index, value); | |
| 14785 } | 14769 } |
| 14786 | 14770 |
| 14787 | 14771 |
| 14788 void ExternalInt16Array::SetValue(Handle<JSObject> holder, | 14772 void ExternalInt16Array::SetValue(Handle<ExternalInt16Array> array, |
| 14789 Handle<ExternalInt16Array> array, | |
| 14790 uint32_t index, Handle<Object> value) { | 14773 uint32_t index, Handle<Object> value) { |
| 14791 ExternalArrayIntSetter<ExternalInt16Array, int16_t>( | 14774 ExternalArrayIntSetter<ExternalInt16Array, int16_t>(array, index, value); |
| 14792 array->GetIsolate(), holder, array, index, value); | |
| 14793 } | 14775 } |
| 14794 | 14776 |
| 14795 | 14777 |
| 14796 void ExternalUint16Array::SetValue(Handle<JSObject> holder, | 14778 void ExternalUint16Array::SetValue(Handle<ExternalUint16Array> array, |
| 14797 Handle<ExternalUint16Array> array, | |
| 14798 uint32_t index, Handle<Object> value) { | 14779 uint32_t index, Handle<Object> value) { |
| 14799 ExternalArrayIntSetter<ExternalUint16Array, uint16_t>( | 14780 ExternalArrayIntSetter<ExternalUint16Array, uint16_t>(array, index, value); |
| 14800 array->GetIsolate(), holder, array, index, value); | |
| 14801 } | 14781 } |
| 14802 | 14782 |
| 14803 | 14783 |
| 14804 void ExternalInt32Array::SetValue(Handle<JSObject> holder, | 14784 void ExternalInt32Array::SetValue(Handle<ExternalInt32Array> array, |
| 14805 Handle<ExternalInt32Array> array, | |
| 14806 uint32_t index, Handle<Object> value) { | 14785 uint32_t index, Handle<Object> value) { |
| 14807 ExternalArrayIntSetter<ExternalInt32Array, int32_t>( | 14786 ExternalArrayIntSetter<ExternalInt32Array, int32_t>(array, index, value); |
| 14808 array->GetIsolate(), holder, array, index, value); | |
| 14809 } | 14787 } |
| 14810 | 14788 |
| 14811 | 14789 |
| 14812 void ExternalUint32Array::SetValue(Handle<JSObject> holder, | 14790 void ExternalUint32Array::SetValue(Handle<ExternalUint32Array> array, |
| 14813 Handle<ExternalUint32Array> array, | |
| 14814 uint32_t index, Handle<Object> value) { | 14791 uint32_t index, Handle<Object> value) { |
| 14815 uint32_t cast_value = 0; | 14792 uint32_t cast_value = 0; |
| 14816 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); | 14793 if (value->IsSmi()) { |
| 14817 if (!view->WasNeutered()) { | 14794 int int_value = Handle<Smi>::cast(value)->value(); |
| 14818 if (index < static_cast<uint32_t>(array->length())) { | 14795 cast_value = static_cast<uint32_t>(int_value); |
| 14819 if (value->IsSmi()) { | 14796 } else if (value->IsHeapNumber()) { |
| 14820 int int_value = Handle<Smi>::cast(value)->value(); | 14797 double double_value = Handle<HeapNumber>::cast(value)->value(); |
| 14821 cast_value = static_cast<uint32_t>(int_value); | 14798 cast_value = static_cast<uint32_t>(DoubleToUint32(double_value)); |
| 14822 } else if (value->IsHeapNumber()) { | 14799 } else { |
| 14823 double double_value = Handle<HeapNumber>::cast(value)->value(); | 14800 // Clamp undefined to zero (default). All other types have been |
| 14824 cast_value = static_cast<uint32_t>(DoubleToUint32(double_value)); | 14801 // converted to a number type further up in the call chain. |
| 14825 } else { | 14802 DCHECK(value->IsUndefined()); |
| 14826 // Clamp undefined to zero (default). All other types have been | |
| 14827 // converted to a number type further up in the call chain. | |
| 14828 DCHECK(value->IsUndefined()); | |
| 14829 } | |
| 14830 array->set(index, cast_value); | |
| 14831 } | |
| 14832 } | 14803 } |
| 14804 array->set(index, cast_value); |
| 14833 } | 14805 } |
| 14834 | 14806 |
| 14835 | 14807 |
| 14836 void ExternalFloat32Array::SetValue(Handle<JSObject> holder, | 14808 void ExternalFloat32Array::SetValue(Handle<ExternalFloat32Array> array, |
| 14837 Handle<ExternalFloat32Array> array, | |
| 14838 uint32_t index, Handle<Object> value) { | 14809 uint32_t index, Handle<Object> value) { |
| 14839 float cast_value = std::numeric_limits<float>::quiet_NaN(); | 14810 float cast_value = std::numeric_limits<float>::quiet_NaN(); |
| 14840 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); | 14811 if (value->IsSmi()) { |
| 14841 if (!view->WasNeutered()) { | 14812 int int_value = Handle<Smi>::cast(value)->value(); |
| 14842 if (index < static_cast<uint32_t>(array->length())) { | 14813 cast_value = static_cast<float>(int_value); |
| 14843 if (value->IsSmi()) { | 14814 } else if (value->IsHeapNumber()) { |
| 14844 int int_value = Handle<Smi>::cast(value)->value(); | 14815 double double_value = Handle<HeapNumber>::cast(value)->value(); |
| 14845 cast_value = static_cast<float>(int_value); | 14816 cast_value = static_cast<float>(double_value); |
| 14846 } else if (value->IsHeapNumber()) { | 14817 } else { |
| 14847 double double_value = Handle<HeapNumber>::cast(value)->value(); | 14818 // Clamp undefined to NaN (default). All other types have been |
| 14848 cast_value = static_cast<float>(double_value); | 14819 // converted to a number type further up in the call chain. |
| 14849 } else { | 14820 DCHECK(value->IsUndefined()); |
| 14850 // Clamp undefined to NaN (default). All other types have been | |
| 14851 // converted to a number type further up in the call chain. | |
| 14852 DCHECK(value->IsUndefined()); | |
| 14853 } | |
| 14854 array->set(index, cast_value); | |
| 14855 } | |
| 14856 } | 14821 } |
| 14822 array->set(index, cast_value); |
| 14857 } | 14823 } |
| 14858 | 14824 |
| 14859 | 14825 |
| 14860 void ExternalFloat64Array::SetValue(Handle<JSObject> holder, | 14826 void ExternalFloat64Array::SetValue(Handle<ExternalFloat64Array> array, |
| 14861 Handle<ExternalFloat64Array> array, | |
| 14862 uint32_t index, Handle<Object> value) { | 14827 uint32_t index, Handle<Object> value) { |
| 14863 double double_value = std::numeric_limits<double>::quiet_NaN(); | 14828 double double_value = std::numeric_limits<double>::quiet_NaN(); |
| 14864 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); | 14829 if (value->IsNumber()) { |
| 14865 if (!view->WasNeutered()) { | 14830 double_value = value->Number(); |
| 14866 if (index < static_cast<uint32_t>(array->length())) { | 14831 } else { |
| 14867 if (value->IsNumber()) { | 14832 // Clamp undefined to NaN (default). All other types have been |
| 14868 double_value = value->Number(); | 14833 // converted to a number type further up in the call chain. |
| 14869 } else { | 14834 DCHECK(value->IsUndefined()); |
| 14870 // Clamp undefined to NaN (default). All other types have been | |
| 14871 // converted to a number type further up in the call chain. | |
| 14872 DCHECK(value->IsUndefined()); | |
| 14873 } | |
| 14874 array->set(index, double_value); | |
| 14875 } | |
| 14876 } | 14835 } |
| 14836 array->set(index, double_value); |
| 14877 } | 14837 } |
| 14878 | 14838 |
| 14879 | 14839 |
| 14880 void GlobalObject::InvalidatePropertyCell(Handle<GlobalObject> global, | 14840 void GlobalObject::InvalidatePropertyCell(Handle<GlobalObject> global, |
| 14881 Handle<Name> name) { | 14841 Handle<Name> name) { |
| 14882 DCHECK(!global->HasFastProperties()); | 14842 DCHECK(!global->HasFastProperties()); |
| 14883 auto dictionary = handle(global->global_dictionary()); | 14843 auto dictionary = handle(global->global_dictionary()); |
| 14884 int entry = dictionary->FindEntry(name); | 14844 int entry = dictionary->FindEntry(name); |
| 14885 if (entry == GlobalDictionary::kNotFound) return; | 14845 if (entry == GlobalDictionary::kNotFound) return; |
| 14886 PropertyCell::InvalidateEntry(dictionary, entry); | 14846 PropertyCell::InvalidateEntry(dictionary, entry); |
| (...skipping 1804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16691 Handle<Object> new_value) { | 16651 Handle<Object> new_value) { |
| 16692 if (cell->value() != *new_value) { | 16652 if (cell->value() != *new_value) { |
| 16693 cell->set_value(*new_value); | 16653 cell->set_value(*new_value); |
| 16694 Isolate* isolate = cell->GetIsolate(); | 16654 Isolate* isolate = cell->GetIsolate(); |
| 16695 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 16655 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 16696 isolate, DependentCode::kPropertyCellChangedGroup); | 16656 isolate, DependentCode::kPropertyCellChangedGroup); |
| 16697 } | 16657 } |
| 16698 } | 16658 } |
| 16699 } // namespace internal | 16659 } // namespace internal |
| 16700 } // namespace v8 | 16660 } // namespace v8 |
| OLD | NEW |