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 Handle<Object> FixedArray::SetValue(Handle<JSObject> holder, | 14695 void FixedArray::SetValue(Handle<JSObject> holder, Handle<FixedArray> array, |
14696 Handle<FixedArray> array, uint32_t index, | 14696 uint32_t index, Handle<Object> value) { |
14697 Handle<Object> value) { | |
14698 array->set(index, *value); | 14697 array->set(index, *value); |
14699 return value; | |
14700 } | 14698 } |
14701 | 14699 |
14702 | 14700 |
14703 Handle<Object> FixedDoubleArray::SetValue(Handle<JSObject> holder, | 14701 void FixedDoubleArray::SetValue(Handle<JSObject> holder, |
14704 Handle<FixedDoubleArray> array, | 14702 Handle<FixedDoubleArray> array, uint32_t index, |
14705 uint32_t index, | 14703 Handle<Object> value) { |
14706 Handle<Object> value) { | |
14707 array->set(index, value->Number()); | 14704 array->set(index, value->Number()); |
14708 return value; | |
14709 } | 14705 } |
14710 | 14706 |
14711 | 14707 |
14712 Handle<Object> ExternalUint8ClampedArray::SetValue( | 14708 void ExternalUint8ClampedArray::SetValue( |
14713 Handle<JSObject> holder, Handle<ExternalUint8ClampedArray> array, | 14709 Handle<JSObject> holder, Handle<ExternalUint8ClampedArray> array, |
14714 uint32_t index, Handle<Object> value) { | 14710 uint32_t index, Handle<Object> value) { |
14715 uint8_t clamped_value = 0; | 14711 uint8_t clamped_value = 0; |
14716 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); | 14712 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); |
14717 if (!view->WasNeutered()) { | 14713 if (!view->WasNeutered()) { |
14718 if (index < static_cast<uint32_t>(array->length())) { | 14714 if (index < static_cast<uint32_t>(array->length())) { |
14719 if (value->IsSmi()) { | 14715 if (value->IsSmi()) { |
14720 int int_value = Handle<Smi>::cast(value)->value(); | 14716 int int_value = Handle<Smi>::cast(value)->value(); |
14721 if (int_value < 0) { | 14717 if (int_value < 0) { |
14722 clamped_value = 0; | 14718 clamped_value = 0; |
(...skipping 15 matching lines...) Expand all Loading... |
14738 clamped_value = static_cast<uint8_t>(lrint(double_value)); | 14734 clamped_value = static_cast<uint8_t>(lrint(double_value)); |
14739 } | 14735 } |
14740 } else { | 14736 } else { |
14741 // Clamp undefined to zero (default). All other types have been | 14737 // Clamp undefined to zero (default). All other types have been |
14742 // converted to a number type further up in the call chain. | 14738 // converted to a number type further up in the call chain. |
14743 DCHECK(value->IsUndefined()); | 14739 DCHECK(value->IsUndefined()); |
14744 } | 14740 } |
14745 array->set(index, clamped_value); | 14741 array->set(index, clamped_value); |
14746 } | 14742 } |
14747 } | 14743 } |
14748 return handle(Smi::FromInt(clamped_value), array->GetIsolate()); | |
14749 } | 14744 } |
14750 | 14745 |
14751 | 14746 |
14752 template <typename ExternalArrayClass, typename ValueType> | 14747 template <typename ExternalArrayClass, typename ValueType> |
14753 static Handle<Object> ExternalArrayIntSetter( | 14748 static void ExternalArrayIntSetter(Isolate* isolate, Handle<JSObject> holder, |
14754 Isolate* isolate, Handle<JSObject> holder, | 14749 Handle<ExternalArrayClass> receiver, |
14755 Handle<ExternalArrayClass> receiver, uint32_t index, Handle<Object> value) { | 14750 uint32_t index, Handle<Object> value) { |
14756 ValueType cast_value = 0; | 14751 ValueType cast_value = 0; |
14757 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); | 14752 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); |
14758 if (!view->WasNeutered()) { | 14753 if (!view->WasNeutered()) { |
14759 if (index < static_cast<uint32_t>(receiver->length())) { | 14754 if (index < static_cast<uint32_t>(receiver->length())) { |
14760 if (value->IsSmi()) { | 14755 if (value->IsSmi()) { |
14761 int int_value = Handle<Smi>::cast(value)->value(); | 14756 int int_value = Handle<Smi>::cast(value)->value(); |
14762 cast_value = static_cast<ValueType>(int_value); | 14757 cast_value = static_cast<ValueType>(int_value); |
14763 } else if (value->IsHeapNumber()) { | 14758 } else if (value->IsHeapNumber()) { |
14764 double double_value = Handle<HeapNumber>::cast(value)->value(); | 14759 double double_value = Handle<HeapNumber>::cast(value)->value(); |
14765 cast_value = static_cast<ValueType>(DoubleToInt32(double_value)); | 14760 cast_value = static_cast<ValueType>(DoubleToInt32(double_value)); |
14766 } else { | 14761 } else { |
14767 // Clamp undefined to zero (default). All other types have been | 14762 // Clamp undefined to zero (default). All other types have been |
14768 // converted to a number type further up in the call chain. | 14763 // converted to a number type further up in the call chain. |
14769 DCHECK(value->IsUndefined()); | 14764 DCHECK(value->IsUndefined()); |
14770 } | 14765 } |
14771 receiver->set(index, cast_value); | 14766 receiver->set(index, cast_value); |
14772 } | 14767 } |
14773 } | 14768 } |
14774 return isolate->factory()->NewNumberFromInt(cast_value); | |
14775 } | 14769 } |
14776 | 14770 |
14777 | 14771 |
14778 Handle<Object> ExternalInt8Array::SetValue(Handle<JSObject> holder, | 14772 void ExternalInt8Array::SetValue(Handle<JSObject> holder, |
14779 Handle<ExternalInt8Array> array, | 14773 Handle<ExternalInt8Array> array, |
14780 uint32_t index, | 14774 uint32_t index, Handle<Object> value) { |
14781 Handle<Object> value) { | 14775 ExternalArrayIntSetter<ExternalInt8Array, int8_t>(array->GetIsolate(), holder, |
14782 return ExternalArrayIntSetter<ExternalInt8Array, int8_t>( | 14776 array, index, value); |
| 14777 } |
| 14778 |
| 14779 |
| 14780 void ExternalUint8Array::SetValue(Handle<JSObject> holder, |
| 14781 Handle<ExternalUint8Array> array, |
| 14782 uint32_t index, Handle<Object> value) { |
| 14783 ExternalArrayIntSetter<ExternalUint8Array, uint8_t>( |
14783 array->GetIsolate(), holder, array, index, value); | 14784 array->GetIsolate(), holder, array, index, value); |
14784 } | 14785 } |
14785 | 14786 |
14786 | 14787 |
14787 Handle<Object> ExternalUint8Array::SetValue(Handle<JSObject> holder, | 14788 void ExternalInt16Array::SetValue(Handle<JSObject> holder, |
14788 Handle<ExternalUint8Array> array, | 14789 Handle<ExternalInt16Array> array, |
14789 uint32_t index, | 14790 uint32_t index, Handle<Object> value) { |
14790 Handle<Object> value) { | 14791 ExternalArrayIntSetter<ExternalInt16Array, int16_t>( |
14791 return ExternalArrayIntSetter<ExternalUint8Array, uint8_t>( | |
14792 array->GetIsolate(), holder, array, index, value); | 14792 array->GetIsolate(), holder, array, index, value); |
14793 } | 14793 } |
14794 | 14794 |
14795 | 14795 |
14796 Handle<Object> ExternalInt16Array::SetValue(Handle<JSObject> holder, | 14796 void ExternalUint16Array::SetValue(Handle<JSObject> holder, |
14797 Handle<ExternalInt16Array> array, | 14797 Handle<ExternalUint16Array> array, |
14798 uint32_t index, | 14798 uint32_t index, Handle<Object> value) { |
14799 Handle<Object> value) { | 14799 ExternalArrayIntSetter<ExternalUint16Array, uint16_t>( |
14800 return ExternalArrayIntSetter<ExternalInt16Array, int16_t>( | |
14801 array->GetIsolate(), holder, array, index, value); | 14800 array->GetIsolate(), holder, array, index, value); |
14802 } | 14801 } |
14803 | 14802 |
14804 | 14803 |
14805 Handle<Object> ExternalUint16Array::SetValue(Handle<JSObject> holder, | 14804 void ExternalInt32Array::SetValue(Handle<JSObject> holder, |
14806 Handle<ExternalUint16Array> array, | 14805 Handle<ExternalInt32Array> array, |
14807 uint32_t index, | 14806 uint32_t index, Handle<Object> value) { |
14808 Handle<Object> value) { | 14807 ExternalArrayIntSetter<ExternalInt32Array, int32_t>( |
14809 return ExternalArrayIntSetter<ExternalUint16Array, uint16_t>( | |
14810 array->GetIsolate(), holder, array, index, value); | 14808 array->GetIsolate(), holder, array, index, value); |
14811 } | 14809 } |
14812 | 14810 |
14813 | 14811 |
14814 Handle<Object> ExternalInt32Array::SetValue(Handle<JSObject> holder, | 14812 void ExternalUint32Array::SetValue(Handle<JSObject> holder, |
14815 Handle<ExternalInt32Array> array, | 14813 Handle<ExternalUint32Array> array, |
14816 uint32_t index, | 14814 uint32_t index, Handle<Object> value) { |
14817 Handle<Object> value) { | |
14818 return ExternalArrayIntSetter<ExternalInt32Array, int32_t>( | |
14819 array->GetIsolate(), holder, array, index, value); | |
14820 } | |
14821 | |
14822 | |
14823 Handle<Object> ExternalUint32Array::SetValue(Handle<JSObject> holder, | |
14824 Handle<ExternalUint32Array> array, | |
14825 uint32_t index, | |
14826 Handle<Object> value) { | |
14827 uint32_t cast_value = 0; | 14815 uint32_t cast_value = 0; |
14828 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); | 14816 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); |
14829 if (!view->WasNeutered()) { | 14817 if (!view->WasNeutered()) { |
14830 if (index < static_cast<uint32_t>(array->length())) { | 14818 if (index < static_cast<uint32_t>(array->length())) { |
14831 if (value->IsSmi()) { | 14819 if (value->IsSmi()) { |
14832 int int_value = Handle<Smi>::cast(value)->value(); | 14820 int int_value = Handle<Smi>::cast(value)->value(); |
14833 cast_value = static_cast<uint32_t>(int_value); | 14821 cast_value = static_cast<uint32_t>(int_value); |
14834 } else if (value->IsHeapNumber()) { | 14822 } else if (value->IsHeapNumber()) { |
14835 double double_value = Handle<HeapNumber>::cast(value)->value(); | 14823 double double_value = Handle<HeapNumber>::cast(value)->value(); |
14836 cast_value = static_cast<uint32_t>(DoubleToUint32(double_value)); | 14824 cast_value = static_cast<uint32_t>(DoubleToUint32(double_value)); |
14837 } else { | 14825 } else { |
14838 // Clamp undefined to zero (default). All other types have been | 14826 // Clamp undefined to zero (default). All other types have been |
14839 // converted to a number type further up in the call chain. | 14827 // converted to a number type further up in the call chain. |
14840 DCHECK(value->IsUndefined()); | 14828 DCHECK(value->IsUndefined()); |
14841 } | 14829 } |
14842 array->set(index, cast_value); | 14830 array->set(index, cast_value); |
14843 } | 14831 } |
14844 } | 14832 } |
14845 return array->GetIsolate()->factory()->NewNumberFromUint(cast_value); | |
14846 } | 14833 } |
14847 | 14834 |
14848 | 14835 |
14849 Handle<Object> ExternalFloat32Array::SetValue( | 14836 void ExternalFloat32Array::SetValue(Handle<JSObject> holder, |
14850 Handle<JSObject> holder, Handle<ExternalFloat32Array> array, uint32_t index, | 14837 Handle<ExternalFloat32Array> array, |
14851 Handle<Object> value) { | 14838 uint32_t index, Handle<Object> value) { |
14852 float cast_value = std::numeric_limits<float>::quiet_NaN(); | 14839 float cast_value = std::numeric_limits<float>::quiet_NaN(); |
14853 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); | 14840 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); |
14854 if (!view->WasNeutered()) { | 14841 if (!view->WasNeutered()) { |
14855 if (index < static_cast<uint32_t>(array->length())) { | 14842 if (index < static_cast<uint32_t>(array->length())) { |
14856 if (value->IsSmi()) { | 14843 if (value->IsSmi()) { |
14857 int int_value = Handle<Smi>::cast(value)->value(); | 14844 int int_value = Handle<Smi>::cast(value)->value(); |
14858 cast_value = static_cast<float>(int_value); | 14845 cast_value = static_cast<float>(int_value); |
14859 } else if (value->IsHeapNumber()) { | 14846 } else if (value->IsHeapNumber()) { |
14860 double double_value = Handle<HeapNumber>::cast(value)->value(); | 14847 double double_value = Handle<HeapNumber>::cast(value)->value(); |
14861 cast_value = static_cast<float>(double_value); | 14848 cast_value = static_cast<float>(double_value); |
14862 } else { | 14849 } else { |
14863 // Clamp undefined to NaN (default). All other types have been | 14850 // Clamp undefined to NaN (default). All other types have been |
14864 // converted to a number type further up in the call chain. | 14851 // converted to a number type further up in the call chain. |
14865 DCHECK(value->IsUndefined()); | 14852 DCHECK(value->IsUndefined()); |
14866 } | 14853 } |
14867 array->set(index, cast_value); | 14854 array->set(index, cast_value); |
14868 } | 14855 } |
14869 } | 14856 } |
14870 return array->GetIsolate()->factory()->NewNumber(cast_value); | |
14871 } | 14857 } |
14872 | 14858 |
14873 | 14859 |
14874 Handle<Object> ExternalFloat64Array::SetValue( | 14860 void ExternalFloat64Array::SetValue(Handle<JSObject> holder, |
14875 Handle<JSObject> holder, Handle<ExternalFloat64Array> array, uint32_t index, | 14861 Handle<ExternalFloat64Array> array, |
14876 Handle<Object> value) { | 14862 uint32_t index, Handle<Object> value) { |
14877 double double_value = std::numeric_limits<double>::quiet_NaN(); | 14863 double double_value = std::numeric_limits<double>::quiet_NaN(); |
14878 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); | 14864 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); |
14879 if (!view->WasNeutered()) { | 14865 if (!view->WasNeutered()) { |
14880 if (index < static_cast<uint32_t>(array->length())) { | 14866 if (index < static_cast<uint32_t>(array->length())) { |
14881 if (value->IsNumber()) { | 14867 if (value->IsNumber()) { |
14882 double_value = value->Number(); | 14868 double_value = value->Number(); |
14883 } else { | 14869 } else { |
14884 // Clamp undefined to NaN (default). All other types have been | 14870 // Clamp undefined to NaN (default). All other types have been |
14885 // converted to a number type further up in the call chain. | 14871 // converted to a number type further up in the call chain. |
14886 DCHECK(value->IsUndefined()); | 14872 DCHECK(value->IsUndefined()); |
14887 } | 14873 } |
14888 array->set(index, double_value); | 14874 array->set(index, double_value); |
14889 } | 14875 } |
14890 } | 14876 } |
14891 return array->GetIsolate()->factory()->NewNumber(double_value); | |
14892 } | 14877 } |
14893 | 14878 |
14894 | 14879 |
14895 void GlobalObject::InvalidatePropertyCell(Handle<GlobalObject> global, | 14880 void GlobalObject::InvalidatePropertyCell(Handle<GlobalObject> global, |
14896 Handle<Name> name) { | 14881 Handle<Name> name) { |
14897 DCHECK(!global->HasFastProperties()); | 14882 DCHECK(!global->HasFastProperties()); |
14898 auto dictionary = handle(global->global_dictionary()); | 14883 auto dictionary = handle(global->global_dictionary()); |
14899 int entry = dictionary->FindEntry(name); | 14884 int entry = dictionary->FindEntry(name); |
14900 if (entry == GlobalDictionary::kNotFound) return; | 14885 if (entry == GlobalDictionary::kNotFound) return; |
14901 PropertyCell::InvalidateEntry(dictionary, entry); | 14886 PropertyCell::InvalidateEntry(dictionary, entry); |
(...skipping 1804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16706 Handle<Object> new_value) { | 16691 Handle<Object> new_value) { |
16707 if (cell->value() != *new_value) { | 16692 if (cell->value() != *new_value) { |
16708 cell->set_value(*new_value); | 16693 cell->set_value(*new_value); |
16709 Isolate* isolate = cell->GetIsolate(); | 16694 Isolate* isolate = cell->GetIsolate(); |
16710 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 16695 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
16711 isolate, DependentCode::kPropertyCellChangedGroup); | 16696 isolate, DependentCode::kPropertyCellChangedGroup); |
16712 } | 16697 } |
16713 } | 16698 } |
16714 } // namespace internal | 16699 } // namespace internal |
16715 } // namespace v8 | 16700 } // namespace v8 |
OLD | NEW |