| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 "src/objects.h" | 5 #include "src/objects.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <iomanip> | 8 #include <iomanip> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| (...skipping 9826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9837 FieldType* DescriptorArray::GetFieldType(int descriptor_number) { | 9837 FieldType* DescriptorArray::GetFieldType(int descriptor_number) { |
| 9838 DCHECK(GetDetails(descriptor_number).location() == kField); | 9838 DCHECK(GetDetails(descriptor_number).location() == kField); |
| 9839 Object* value = GetValue(descriptor_number); | 9839 Object* value = GetValue(descriptor_number); |
| 9840 if (value->IsWeakCell()) { | 9840 if (value->IsWeakCell()) { |
| 9841 if (WeakCell::cast(value)->cleared()) return FieldType::None(); | 9841 if (WeakCell::cast(value)->cleared()) return FieldType::None(); |
| 9842 value = WeakCell::cast(value)->value(); | 9842 value = WeakCell::cast(value)->value(); |
| 9843 } | 9843 } |
| 9844 return FieldType::cast(value); | 9844 return FieldType::cast(value); |
| 9845 } | 9845 } |
| 9846 | 9846 |
| 9847 bool DescriptorArray::CanHoldValue(int descriptor, Object* value) { | 9847 namespace { |
| 9848 PropertyDetails details = GetDetails(descriptor); | 9848 |
| 9849 bool CanHoldValue(DescriptorArray* descriptors, int descriptor, Object* value) { |
| 9850 PropertyDetails details = descriptors->GetDetails(descriptor); |
| 9849 switch (details.type()) { | 9851 switch (details.type()) { |
| 9850 case DATA: | 9852 case DATA: |
| 9851 return value->FitsRepresentation(details.representation()) && | 9853 return value->FitsRepresentation(details.representation()) && |
| 9852 GetFieldType(descriptor)->NowContains(value); | 9854 descriptors->GetFieldType(descriptor)->NowContains(value); |
| 9853 | 9855 |
| 9854 case DATA_CONSTANT: | 9856 case DATA_CONSTANT: |
| 9855 DCHECK(GetConstant(descriptor) != value || | 9857 DCHECK(descriptors->GetConstant(descriptor) != value || |
| 9856 value->FitsRepresentation(details.representation())); | 9858 value->FitsRepresentation(details.representation())); |
| 9857 return GetConstant(descriptor) == value; | 9859 return descriptors->GetConstant(descriptor) == value; |
| 9858 | 9860 |
| 9859 case ACCESSOR: | 9861 case ACCESSOR: |
| 9860 case ACCESSOR_CONSTANT: | 9862 case ACCESSOR_CONSTANT: |
| 9861 return false; | 9863 return false; |
| 9862 } | 9864 } |
| 9863 | 9865 |
| 9864 UNREACHABLE(); | 9866 UNREACHABLE(); |
| 9865 return false; | 9867 return false; |
| 9866 } | 9868 } |
| 9867 | 9869 |
| 9868 namespace { | |
| 9869 | |
| 9870 Handle<Map> UpdateDescriptorForValue(Handle<Map> map, int descriptor, | 9870 Handle<Map> UpdateDescriptorForValue(Handle<Map> map, int descriptor, |
| 9871 Handle<Object> value) { | 9871 Handle<Object> value) { |
| 9872 if (map->instance_descriptors()->CanHoldValue(descriptor, *value)) return map; | 9872 if (CanHoldValue(map->instance_descriptors(), descriptor, *value)) return map; |
| 9873 | 9873 |
| 9874 Isolate* isolate = map->GetIsolate(); | 9874 Isolate* isolate = map->GetIsolate(); |
| 9875 PropertyAttributes attributes = | 9875 PropertyAttributes attributes = |
| 9876 map->instance_descriptors()->GetDetails(descriptor).attributes(); | 9876 map->instance_descriptors()->GetDetails(descriptor).attributes(); |
| 9877 Representation representation = value->OptimalRepresentation(); | 9877 Representation representation = value->OptimalRepresentation(); |
| 9878 Handle<FieldType> type = value->OptimalType(isolate, representation); | 9878 Handle<FieldType> type = value->OptimalType(isolate, representation); |
| 9879 | 9879 |
| 9880 return Map::ReconfigureProperty(map, descriptor, kData, attributes, | 9880 return Map::ReconfigureProperty(map, descriptor, kData, attributes, |
| 9881 representation, type, FORCE_FIELD); | 9881 representation, type, FORCE_FIELD); |
| 9882 } | 9882 } |
| 9883 | 9883 |
| 9884 } // namespace | 9884 } // namespace |
| 9885 | 9885 |
| 9886 // static | 9886 // static |
| 9887 Handle<Map> Map::PrepareForDataProperty(Handle<Map> map, int descriptor, | 9887 Handle<Map> Map::PrepareForDataProperty(Handle<Map> map, int descriptor, |
| 9888 Handle<Object> value) { | 9888 Handle<Object> value) { |
| 9889 // Dictionaries can store any property value. | 9889 // Dictionaries can store any property value. |
| 9890 if (map->is_dictionary_map()) return map; | 9890 DCHECK(!map->is_dictionary_map()); |
| 9891 | |
| 9892 // Update to the newest map before storing the property. | 9891 // Update to the newest map before storing the property. |
| 9893 return UpdateDescriptorForValue(Update(map), descriptor, value); | 9892 return UpdateDescriptorForValue(Update(map), descriptor, value); |
| 9894 } | 9893 } |
| 9895 | 9894 |
| 9896 | 9895 |
| 9897 Handle<Map> Map::TransitionToDataProperty(Handle<Map> map, Handle<Name> name, | 9896 Handle<Map> Map::TransitionToDataProperty(Handle<Map> map, Handle<Name> name, |
| 9898 Handle<Object> value, | 9897 Handle<Object> value, |
| 9899 PropertyAttributes attributes, | 9898 PropertyAttributes attributes, |
| 9900 StoreFromKeyed store_mode) { | 9899 StoreFromKeyed store_mode) { |
| 9901 // Dictionary maps can always have additional data properties. | 9900 DCHECK(!map->is_dictionary_map()); |
| 9902 if (map->is_dictionary_map()) return map; | |
| 9903 | 9901 |
| 9904 // Migrate to the newest map before storing the property. | 9902 // Migrate to the newest map before storing the property. |
| 9905 map = Update(map); | 9903 map = Update(map); |
| 9906 | 9904 |
| 9907 Map* maybe_transition = | 9905 Map* maybe_transition = |
| 9908 TransitionArray::SearchTransition(*map, kData, *name, attributes); | 9906 TransitionArray::SearchTransition(*map, kData, *name, attributes); |
| 9909 if (maybe_transition != NULL) { | 9907 if (maybe_transition != NULL) { |
| 9910 Handle<Map> transition(maybe_transition); | 9908 Handle<Map> transition(maybe_transition); |
| 9911 int descriptor = transition->LastAdded(); | 9909 int descriptor = transition->LastAdded(); |
| 9912 | 9910 |
| (...skipping 10009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19922 if (cell->value() != *new_value) { | 19920 if (cell->value() != *new_value) { |
| 19923 cell->set_value(*new_value); | 19921 cell->set_value(*new_value); |
| 19924 Isolate* isolate = cell->GetIsolate(); | 19922 Isolate* isolate = cell->GetIsolate(); |
| 19925 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 19923 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 19926 isolate, DependentCode::kPropertyCellChangedGroup); | 19924 isolate, DependentCode::kPropertyCellChangedGroup); |
| 19927 } | 19925 } |
| 19928 } | 19926 } |
| 19929 | 19927 |
| 19930 } // namespace internal | 19928 } // namespace internal |
| 19931 } // namespace v8 | 19929 } // namespace v8 |
| OLD | NEW |