| 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 <memory> | 9 #include <memory> |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 3309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3320 } else { | 3320 } else { |
| 3321 // Functions have null as a constructor, | 3321 // Functions have null as a constructor, |
| 3322 // but any JSFunction knows its context immediately. | 3322 // but any JSFunction knows its context immediately. |
| 3323 CHECK(receiver->IsJSFunction()); | 3323 CHECK(receiver->IsJSFunction()); |
| 3324 function = JSFunction::cast(receiver); | 3324 function = JSFunction::cast(receiver); |
| 3325 } | 3325 } |
| 3326 | 3326 |
| 3327 return function->context()->native_context(); | 3327 return function->context()->native_context(); |
| 3328 } | 3328 } |
| 3329 | 3329 |
| 3330 Handle<Object> Map::WrapType(Handle<FieldType> type) { | 3330 Handle<Object> Map::WrapFieldType(Handle<FieldType> type) { |
| 3331 if (type->IsClass()) return Map::WeakCellForMap(type->AsClass()); | 3331 if (type->IsClass()) return Map::WeakCellForMap(type->AsClass()); |
| 3332 return type; | 3332 return type; |
| 3333 } | 3333 } |
| 3334 | 3334 |
| 3335 FieldType* Map::UnwrapFieldType(Object* wrapped_type) { |
| 3336 Object* value = wrapped_type; |
| 3337 if (value->IsWeakCell()) { |
| 3338 if (WeakCell::cast(value)->cleared()) return FieldType::None(); |
| 3339 value = WeakCell::cast(value)->value(); |
| 3340 } |
| 3341 return FieldType::cast(value); |
| 3342 } |
| 3343 |
| 3335 MaybeHandle<Map> Map::CopyWithField(Handle<Map> map, Handle<Name> name, | 3344 MaybeHandle<Map> Map::CopyWithField(Handle<Map> map, Handle<Name> name, |
| 3336 Handle<FieldType> type, | 3345 Handle<FieldType> type, |
| 3337 PropertyAttributes attributes, | 3346 PropertyAttributes attributes, |
| 3338 Representation representation, | 3347 Representation representation, |
| 3339 TransitionFlag flag) { | 3348 TransitionFlag flag) { |
| 3340 DCHECK(DescriptorArray::kNotFound == | 3349 DCHECK(DescriptorArray::kNotFound == |
| 3341 map->instance_descriptors()->Search( | 3350 map->instance_descriptors()->Search( |
| 3342 *name, map->NumberOfOwnDescriptors())); | 3351 *name, map->NumberOfOwnDescriptors())); |
| 3343 | 3352 |
| 3344 // Ensure the descriptor array does not get too big. | 3353 // Ensure the descriptor array does not get too big. |
| 3345 if (map->NumberOfOwnDescriptors() >= kMaxNumberOfDescriptors) { | 3354 if (map->NumberOfOwnDescriptors() >= kMaxNumberOfDescriptors) { |
| 3346 return MaybeHandle<Map>(); | 3355 return MaybeHandle<Map>(); |
| 3347 } | 3356 } |
| 3348 | 3357 |
| 3349 Isolate* isolate = map->GetIsolate(); | 3358 Isolate* isolate = map->GetIsolate(); |
| 3350 | 3359 |
| 3351 // Compute the new index for new field. | 3360 // Compute the new index for new field. |
| 3352 int index = map->NextFreePropertyIndex(); | 3361 int index = map->NextFreePropertyIndex(); |
| 3353 | 3362 |
| 3354 if (map->instance_type() == JS_CONTEXT_EXTENSION_OBJECT_TYPE) { | 3363 if (map->instance_type() == JS_CONTEXT_EXTENSION_OBJECT_TYPE) { |
| 3355 representation = Representation::Tagged(); | 3364 representation = Representation::Tagged(); |
| 3356 type = FieldType::Any(isolate); | 3365 type = FieldType::Any(isolate); |
| 3357 } | 3366 } |
| 3358 | 3367 |
| 3359 Handle<Object> wrapped_type(WrapType(type)); | 3368 Handle<Object> wrapped_type(WrapFieldType(type)); |
| 3360 | 3369 |
| 3361 Descriptor d = Descriptor::DataField(name, index, wrapped_type, attributes, | 3370 Descriptor d = Descriptor::DataField(name, index, wrapped_type, attributes, |
| 3362 representation); | 3371 representation); |
| 3363 Handle<Map> new_map = Map::CopyAddDescriptor(map, &d, flag); | 3372 Handle<Map> new_map = Map::CopyAddDescriptor(map, &d, flag); |
| 3364 int unused_property_fields = new_map->unused_property_fields() - 1; | 3373 int unused_property_fields = new_map->unused_property_fields() - 1; |
| 3365 if (unused_property_fields < 0) { | 3374 if (unused_property_fields < 0) { |
| 3366 unused_property_fields += JSObject::kFieldsAdded; | 3375 unused_property_fields += JSObject::kFieldsAdded; |
| 3367 } | 3376 } |
| 3368 new_map->set_unused_property_fields(unused_property_fields); | 3377 new_map->set_unused_property_fields(unused_property_fields); |
| 3369 return new_map; | 3378 return new_map; |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4132 field_owner->instance_descriptors(), isolate); | 4141 field_owner->instance_descriptors(), isolate); |
| 4133 DCHECK_EQ(*old_field_type, descriptors->GetFieldType(modify_index)); | 4142 DCHECK_EQ(*old_field_type, descriptors->GetFieldType(modify_index)); |
| 4134 | 4143 |
| 4135 new_field_type = | 4144 new_field_type = |
| 4136 Map::GeneralizeFieldType(old_representation, old_field_type, | 4145 Map::GeneralizeFieldType(old_representation, old_field_type, |
| 4137 new_representation, new_field_type, isolate); | 4146 new_representation, new_field_type, isolate); |
| 4138 | 4147 |
| 4139 PropertyDetails details = descriptors->GetDetails(modify_index); | 4148 PropertyDetails details = descriptors->GetDetails(modify_index); |
| 4140 Handle<Name> name(descriptors->GetKey(modify_index)); | 4149 Handle<Name> name(descriptors->GetKey(modify_index)); |
| 4141 | 4150 |
| 4142 Handle<Object> wrapped_type(WrapType(new_field_type)); | 4151 Handle<Object> wrapped_type(WrapFieldType(new_field_type)); |
| 4143 field_owner->UpdateFieldType(modify_index, name, new_representation, | 4152 field_owner->UpdateFieldType(modify_index, name, new_representation, |
| 4144 wrapped_type); | 4153 wrapped_type); |
| 4145 field_owner->dependent_code()->DeoptimizeDependentCodeGroup( | 4154 field_owner->dependent_code()->DeoptimizeDependentCodeGroup( |
| 4146 isolate, DependentCode::kFieldOwnerGroup); | 4155 isolate, DependentCode::kFieldOwnerGroup); |
| 4147 | 4156 |
| 4148 if (FLAG_trace_generalization) { | 4157 if (FLAG_trace_generalization) { |
| 4149 map->PrintGeneralization( | 4158 map->PrintGeneralization( |
| 4150 stdout, "field type generalization", modify_index, | 4159 stdout, "field type generalization", modify_index, |
| 4151 map->NumberOfOwnDescriptors(), map->NumberOfOwnDescriptors(), false, | 4160 map->NumberOfOwnDescriptors(), map->NumberOfOwnDescriptors(), false, |
| 4152 details.representation(), details.representation(), old_field_type, | 4161 details.representation(), details.representation(), old_field_type, |
| (...skipping 4949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9102 new_map->set_is_extensible(false); | 9111 new_map->set_is_extensible(false); |
| 9103 if (!IsFixedTypedArrayElementsKind(map->elements_kind())) { | 9112 if (!IsFixedTypedArrayElementsKind(map->elements_kind())) { |
| 9104 ElementsKind new_kind = IsStringWrapperElementsKind(map->elements_kind()) | 9113 ElementsKind new_kind = IsStringWrapperElementsKind(map->elements_kind()) |
| 9105 ? SLOW_STRING_WRAPPER_ELEMENTS | 9114 ? SLOW_STRING_WRAPPER_ELEMENTS |
| 9106 : DICTIONARY_ELEMENTS; | 9115 : DICTIONARY_ELEMENTS; |
| 9107 new_map->set_elements_kind(new_kind); | 9116 new_map->set_elements_kind(new_kind); |
| 9108 } | 9117 } |
| 9109 return new_map; | 9118 return new_map; |
| 9110 } | 9119 } |
| 9111 | 9120 |
| 9112 FieldType* DescriptorArray::GetFieldType(int descriptor_number) { | |
| 9113 DCHECK(GetDetails(descriptor_number).location() == kField); | |
| 9114 Object* value = GetValue(descriptor_number); | |
| 9115 if (value->IsWeakCell()) { | |
| 9116 if (WeakCell::cast(value)->cleared()) return FieldType::None(); | |
| 9117 value = WeakCell::cast(value)->value(); | |
| 9118 } | |
| 9119 return FieldType::cast(value); | |
| 9120 } | |
| 9121 | |
| 9122 namespace { | 9121 namespace { |
| 9123 | 9122 |
| 9124 bool CanHoldValue(DescriptorArray* descriptors, int descriptor, Object* value) { | 9123 bool CanHoldValue(DescriptorArray* descriptors, int descriptor, Object* value) { |
| 9125 PropertyDetails details = descriptors->GetDetails(descriptor); | 9124 PropertyDetails details = descriptors->GetDetails(descriptor); |
| 9126 if (details.location() == kField) { | 9125 if (details.location() == kField) { |
| 9127 if (details.kind() == kData) { | 9126 if (details.kind() == kData) { |
| 9128 return value->FitsRepresentation(details.representation()) && | 9127 return value->FitsRepresentation(details.representation()) && |
| 9129 descriptors->GetFieldType(descriptor)->NowContains(value); | 9128 descriptors->GetFieldType(descriptor)->NowContains(value); |
| 9130 } else { | 9129 } else { |
| 9131 DCHECK_EQ(kAccessor, details.kind()); | 9130 DCHECK_EQ(kAccessor, details.kind()); |
| (...skipping 6651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15783 int capacity = this->Capacity(); | 15782 int capacity = this->Capacity(); |
| 15784 for (int i = 0; i < capacity; i++) { | 15783 for (int i = 0; i < capacity; i++) { |
| 15785 Object* k = this->KeyAt(i); | 15784 Object* k = this->KeyAt(i); |
| 15786 if (this->IsKey(isolate, k)) { | 15785 if (this->IsKey(isolate, k)) { |
| 15787 os << "\n "; | 15786 os << "\n "; |
| 15788 if (k->IsString()) { | 15787 if (k->IsString()) { |
| 15789 String::cast(k)->StringPrint(os); | 15788 String::cast(k)->StringPrint(os); |
| 15790 } else { | 15789 } else { |
| 15791 os << Brief(k); | 15790 os << Brief(k); |
| 15792 } | 15791 } |
| 15793 os << ": " << Brief(this->ValueAt(i)) << " " << this->DetailsAt(i); | 15792 os << ": " << Brief(this->ValueAt(i)) << " "; |
| 15793 this->DetailsAt(i).PrintAsSlowTo(os); |
| 15794 } | 15794 } |
| 15795 } | 15795 } |
| 15796 } | 15796 } |
| 15797 template <typename Derived, typename Shape, typename Key> | 15797 template <typename Derived, typename Shape, typename Key> |
| 15798 void Dictionary<Derived, Shape, Key>::Print() { | 15798 void Dictionary<Derived, Shape, Key>::Print() { |
| 15799 OFStream os(stdout); | 15799 OFStream os(stdout); |
| 15800 Print(os); | 15800 Print(os); |
| 15801 } | 15801 } |
| 15802 #endif | 15802 #endif |
| 15803 | 15803 |
| (...skipping 4175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 19979 // depend on this. | 19979 // depend on this. |
| 19980 return DICTIONARY_ELEMENTS; | 19980 return DICTIONARY_ELEMENTS; |
| 19981 } | 19981 } |
| 19982 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 19982 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
| 19983 return kind; | 19983 return kind; |
| 19984 } | 19984 } |
| 19985 } | 19985 } |
| 19986 | 19986 |
| 19987 } // namespace internal | 19987 } // namespace internal |
| 19988 } // namespace v8 | 19988 } // namespace v8 |
| OLD | NEW |