Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: src/objects.cc

Issue 1180753005: Cleanup typed array setters, the property is guaranteed to be there. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14675 matching lines...) Expand 10 before | Expand all | Expand 10 after
14686 TYPED_ARRAYS(INSTANCE_TYPE_TO_ELEMENT_SIZE) 14686 TYPED_ARRAYS(INSTANCE_TYPE_TO_ELEMENT_SIZE)
14687 #undef INSTANCE_TYPE_TO_ELEMENT_SIZE 14687 #undef INSTANCE_TYPE_TO_ELEMENT_SIZE
14688 14688
14689 default: 14689 default:
14690 UNREACHABLE(); 14690 UNREACHABLE();
14691 return 0; 14691 return 0;
14692 } 14692 }
14693 } 14693 }
14694 14694
14695 14695
14696 void FixedArray::SetValue(Handle<JSObject> holder, Handle<FixedArray> array, 14696 void FixedArray::SetValue(Handle<FixedArray> array, uint32_t index,
14697 uint32_t index, Handle<Object> value) { 14697 Handle<Object> value) {
14698 array->set(index, *value); 14698 array->set(index, *value);
14699 } 14699 }
14700 14700
14701 14701
14702 void FixedDoubleArray::SetValue(Handle<JSObject> holder, 14702 void FixedDoubleArray::SetValue(Handle<FixedDoubleArray> array, uint32_t index,
14703 Handle<FixedDoubleArray> array, uint32_t index,
14704 Handle<Object> value) { 14703 Handle<Object> value) {
14705 array->set(index, value->Number()); 14704 array->set(index, value->Number());
14706 } 14705 }
14707 14706
14708 14707
14709 void ExternalUint8ClampedArray::SetValue( 14708 void ExternalUint8ClampedArray::SetValue(
14710 Handle<JSObject> holder, Handle<ExternalUint8ClampedArray> array, 14709 Handle<ExternalUint8ClampedArray> array, uint32_t index,
14711 uint32_t index, Handle<Object> value) { 14710 Handle<Object> value) {
14712 uint8_t clamped_value = 0; 14711 uint8_t clamped_value = 0;
14713 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); 14712 if (value->IsSmi()) {
14714 if (!view->WasNeutered()) { 14713 int int_value = Handle<Smi>::cast(value)->value();
14715 if (index < static_cast<uint32_t>(array->length())) { 14714 if (int_value < 0) {
14716 if (value->IsSmi()) { 14715 clamped_value = 0;
14717 int int_value = Handle<Smi>::cast(value)->value(); 14716 } else if (int_value > 255) {
14718 if (int_value < 0) { 14717 clamped_value = 255;
14719 clamped_value = 0; 14718 } else {
14720 } else if (int_value > 255) { 14719 clamped_value = static_cast<uint8_t>(int_value);
14721 clamped_value = 255;
14722 } else {
14723 clamped_value = static_cast<uint8_t>(int_value);
14724 }
14725 } else if (value->IsHeapNumber()) {
14726 double double_value = Handle<HeapNumber>::cast(value)->value();
14727 if (!(double_value > 0)) {
14728 // NaN and less than zero clamp to zero.
14729 clamped_value = 0;
14730 } else if (double_value > 255) {
14731 // Greater than 255 clamp to 255.
14732 clamped_value = 255;
14733 } else {
14734 // Other doubles are rounded to the nearest integer.
14735 clamped_value = static_cast<uint8_t>(lrint(double_value));
14736 }
14737 } else {
14738 // Clamp undefined to zero (default). All other types have been
14739 // converted to a number type further up in the call chain.
14740 DCHECK(value->IsUndefined());
14741 }
14742 array->set(index, clamped_value);
14743 } 14720 }
14721 } else if (value->IsHeapNumber()) {
14722 double double_value = Handle<HeapNumber>::cast(value)->value();
14723 if (!(double_value > 0)) {
14724 // NaN and less than zero clamp to zero.
14725 clamped_value = 0;
14726 } else if (double_value > 255) {
14727 // Greater than 255 clamp to 255.
14728 clamped_value = 255;
14729 } else {
14730 // Other doubles are rounded to the nearest integer.
14731 clamped_value = static_cast<uint8_t>(lrint(double_value));
14732 }
14733 } else {
14734 // Clamp undefined to zero (default). All other types have been
14735 // converted to a number type further up in the call chain.
14736 DCHECK(value->IsUndefined());
14744 } 14737 }
14738 array->set(index, clamped_value);
14745 } 14739 }
14746 14740
14747 14741
14748 template <typename ExternalArrayClass, typename ValueType> 14742 template <typename ExternalArrayClass, typename ValueType>
14749 static void ExternalArrayIntSetter(Isolate* isolate, Handle<JSObject> holder, 14743 static void ExternalArrayIntSetter(Handle<ExternalArrayClass> receiver,
14750 Handle<ExternalArrayClass> receiver,
14751 uint32_t index, Handle<Object> value) { 14744 uint32_t index, Handle<Object> value) {
14752 ValueType cast_value = 0; 14745 ValueType cast_value = 0;
14753 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); 14746 if (value->IsSmi()) {
14754 if (!view->WasNeutered()) { 14747 int int_value = Handle<Smi>::cast(value)->value();
14755 if (index < static_cast<uint32_t>(receiver->length())) { 14748 cast_value = static_cast<ValueType>(int_value);
14756 if (value->IsSmi()) { 14749 } else if (value->IsHeapNumber()) {
14757 int int_value = Handle<Smi>::cast(value)->value(); 14750 double double_value = Handle<HeapNumber>::cast(value)->value();
14758 cast_value = static_cast<ValueType>(int_value); 14751 cast_value = static_cast<ValueType>(DoubleToInt32(double_value));
14759 } else if (value->IsHeapNumber()) { 14752 } else {
14760 double double_value = Handle<HeapNumber>::cast(value)->value(); 14753 // Clamp undefined to zero (default). All other types have been
14761 cast_value = static_cast<ValueType>(DoubleToInt32(double_value)); 14754 // converted to a number type further up in the call chain.
14762 } else { 14755 DCHECK(value->IsUndefined());
14763 // Clamp undefined to zero (default). All other types have been
14764 // converted to a number type further up in the call chain.
14765 DCHECK(value->IsUndefined());
14766 }
14767 receiver->set(index, cast_value);
14768 }
14769 } 14756 }
14757 receiver->set(index, cast_value);
14770 } 14758 }
14771 14759
14772 14760
14773 void ExternalInt8Array::SetValue(Handle<JSObject> holder, 14761 void ExternalInt8Array::SetValue(Handle<ExternalInt8Array> array,
14774 Handle<ExternalInt8Array> array,
14775 uint32_t index, Handle<Object> value) { 14762 uint32_t index, Handle<Object> value) {
14776 ExternalArrayIntSetter<ExternalInt8Array, int8_t>(array->GetIsolate(), holder, 14763 ExternalArrayIntSetter<ExternalInt8Array, int8_t>(array, index, value);
14777 array, index, value);
14778 } 14764 }
14779 14765
14780 14766
14781 void ExternalUint8Array::SetValue(Handle<JSObject> holder, 14767 void ExternalUint8Array::SetValue(Handle<ExternalUint8Array> array,
14782 Handle<ExternalUint8Array> array,
14783 uint32_t index, Handle<Object> value) { 14768 uint32_t index, Handle<Object> value) {
14784 ExternalArrayIntSetter<ExternalUint8Array, uint8_t>( 14769 ExternalArrayIntSetter<ExternalUint8Array, uint8_t>(array, index, value);
14785 array->GetIsolate(), holder, array, index, value);
14786 } 14770 }
14787 14771
14788 14772
14789 void ExternalInt16Array::SetValue(Handle<JSObject> holder, 14773 void ExternalInt16Array::SetValue(Handle<ExternalInt16Array> array,
14790 Handle<ExternalInt16Array> array,
14791 uint32_t index, Handle<Object> value) { 14774 uint32_t index, Handle<Object> value) {
14792 ExternalArrayIntSetter<ExternalInt16Array, int16_t>( 14775 ExternalArrayIntSetter<ExternalInt16Array, int16_t>(array, index, value);
14793 array->GetIsolate(), holder, array, index, value);
14794 } 14776 }
14795 14777
14796 14778
14797 void ExternalUint16Array::SetValue(Handle<JSObject> holder, 14779 void ExternalUint16Array::SetValue(Handle<ExternalUint16Array> array,
14798 Handle<ExternalUint16Array> array,
14799 uint32_t index, Handle<Object> value) { 14780 uint32_t index, Handle<Object> value) {
14800 ExternalArrayIntSetter<ExternalUint16Array, uint16_t>( 14781 ExternalArrayIntSetter<ExternalUint16Array, uint16_t>(array, index, value);
14801 array->GetIsolate(), holder, array, index, value);
14802 } 14782 }
14803 14783
14804 14784
14805 void ExternalInt32Array::SetValue(Handle<JSObject> holder, 14785 void ExternalInt32Array::SetValue(Handle<ExternalInt32Array> array,
14806 Handle<ExternalInt32Array> array,
14807 uint32_t index, Handle<Object> value) { 14786 uint32_t index, Handle<Object> value) {
14808 ExternalArrayIntSetter<ExternalInt32Array, int32_t>( 14787 ExternalArrayIntSetter<ExternalInt32Array, int32_t>(array, index, value);
14809 array->GetIsolate(), holder, array, index, value);
14810 } 14788 }
14811 14789
14812 14790
14813 void ExternalUint32Array::SetValue(Handle<JSObject> holder, 14791 void ExternalUint32Array::SetValue(Handle<ExternalUint32Array> array,
14814 Handle<ExternalUint32Array> array,
14815 uint32_t index, Handle<Object> value) { 14792 uint32_t index, Handle<Object> value) {
14816 uint32_t cast_value = 0; 14793 uint32_t cast_value = 0;
14817 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); 14794 if (value->IsSmi()) {
14818 if (!view->WasNeutered()) { 14795 int int_value = Handle<Smi>::cast(value)->value();
14819 if (index < static_cast<uint32_t>(array->length())) { 14796 cast_value = static_cast<uint32_t>(int_value);
14820 if (value->IsSmi()) { 14797 } else if (value->IsHeapNumber()) {
14821 int int_value = Handle<Smi>::cast(value)->value(); 14798 double double_value = Handle<HeapNumber>::cast(value)->value();
14822 cast_value = static_cast<uint32_t>(int_value); 14799 cast_value = static_cast<uint32_t>(DoubleToUint32(double_value));
14823 } else if (value->IsHeapNumber()) { 14800 } else {
14824 double double_value = Handle<HeapNumber>::cast(value)->value(); 14801 // Clamp undefined to zero (default). All other types have been
14825 cast_value = static_cast<uint32_t>(DoubleToUint32(double_value)); 14802 // converted to a number type further up in the call chain.
14826 } else { 14803 DCHECK(value->IsUndefined());
14827 // Clamp undefined to zero (default). All other types have been
14828 // converted to a number type further up in the call chain.
14829 DCHECK(value->IsUndefined());
14830 }
14831 array->set(index, cast_value);
14832 }
14833 } 14804 }
14805 array->set(index, cast_value);
14834 } 14806 }
14835 14807
14836 14808
14837 void ExternalFloat32Array::SetValue(Handle<JSObject> holder, 14809 void ExternalFloat32Array::SetValue(Handle<ExternalFloat32Array> array,
14838 Handle<ExternalFloat32Array> array,
14839 uint32_t index, Handle<Object> value) { 14810 uint32_t index, Handle<Object> value) {
14840 float cast_value = std::numeric_limits<float>::quiet_NaN(); 14811 float cast_value = std::numeric_limits<float>::quiet_NaN();
14841 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); 14812 if (value->IsSmi()) {
14842 if (!view->WasNeutered()) { 14813 int int_value = Handle<Smi>::cast(value)->value();
14843 if (index < static_cast<uint32_t>(array->length())) { 14814 cast_value = static_cast<float>(int_value);
14844 if (value->IsSmi()) { 14815 } else if (value->IsHeapNumber()) {
14845 int int_value = Handle<Smi>::cast(value)->value(); 14816 double double_value = Handle<HeapNumber>::cast(value)->value();
14846 cast_value = static_cast<float>(int_value); 14817 cast_value = static_cast<float>(double_value);
14847 } else if (value->IsHeapNumber()) { 14818 } else {
14848 double double_value = Handle<HeapNumber>::cast(value)->value(); 14819 // Clamp undefined to NaN (default). All other types have been
14849 cast_value = static_cast<float>(double_value); 14820 // converted to a number type further up in the call chain.
14850 } else { 14821 DCHECK(value->IsUndefined());
14851 // Clamp undefined to NaN (default). All other types have been
14852 // converted to a number type further up in the call chain.
14853 DCHECK(value->IsUndefined());
14854 }
14855 array->set(index, cast_value);
14856 }
14857 } 14822 }
14823 array->set(index, cast_value);
14858 } 14824 }
14859 14825
14860 14826
14861 void ExternalFloat64Array::SetValue(Handle<JSObject> holder, 14827 void ExternalFloat64Array::SetValue(Handle<ExternalFloat64Array> array,
14862 Handle<ExternalFloat64Array> array,
14863 uint32_t index, Handle<Object> value) { 14828 uint32_t index, Handle<Object> value) {
14864 double double_value = std::numeric_limits<double>::quiet_NaN(); 14829 double double_value = std::numeric_limits<double>::quiet_NaN();
14865 Handle<JSArrayBufferView> view = Handle<JSArrayBufferView>::cast(holder); 14830 if (value->IsNumber()) {
14866 if (!view->WasNeutered()) { 14831 double_value = value->Number();
14867 if (index < static_cast<uint32_t>(array->length())) { 14832 } else {
14868 if (value->IsNumber()) { 14833 // Clamp undefined to NaN (default). All other types have been
14869 double_value = value->Number(); 14834 // converted to a number type further up in the call chain.
14870 } else { 14835 DCHECK(value->IsUndefined());
14871 // Clamp undefined to NaN (default). All other types have been
14872 // converted to a number type further up in the call chain.
14873 DCHECK(value->IsUndefined());
14874 }
14875 array->set(index, double_value);
14876 }
14877 } 14836 }
14837 array->set(index, double_value);
14878 } 14838 }
14879 14839
14880 14840
14881 void GlobalObject::InvalidatePropertyCell(Handle<GlobalObject> global, 14841 void GlobalObject::InvalidatePropertyCell(Handle<GlobalObject> global,
14882 Handle<Name> name) { 14842 Handle<Name> name) {
14883 DCHECK(!global->HasFastProperties()); 14843 DCHECK(!global->HasFastProperties());
14884 auto dictionary = handle(global->global_dictionary()); 14844 auto dictionary = handle(global->global_dictionary());
14885 int entry = dictionary->FindEntry(name); 14845 int entry = dictionary->FindEntry(name);
14886 if (entry == GlobalDictionary::kNotFound) return; 14846 if (entry == GlobalDictionary::kNotFound) return;
14887 PropertyCell::InvalidateEntry(dictionary, entry); 14847 PropertyCell::InvalidateEntry(dictionary, entry);
(...skipping 1804 matching lines...) Expand 10 before | Expand all | Expand 10 after
16692 Handle<Object> new_value) { 16652 Handle<Object> new_value) {
16693 if (cell->value() != *new_value) { 16653 if (cell->value() != *new_value) {
16694 cell->set_value(*new_value); 16654 cell->set_value(*new_value);
16695 Isolate* isolate = cell->GetIsolate(); 16655 Isolate* isolate = cell->GetIsolate();
16696 cell->dependent_code()->DeoptimizeDependentCodeGroup( 16656 cell->dependent_code()->DeoptimizeDependentCodeGroup(
16697 isolate, DependentCode::kPropertyCellChangedGroup); 16657 isolate, DependentCode::kPropertyCellChangedGroup);
16698 } 16658 }
16699 } 16659 }
16700 } // namespace internal 16660 } // namespace internal
16701 } // namespace v8 16661 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698