| 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 "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 8206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8217 Object* constructor = map->GetConstructor(); | 8217 Object* constructor = map->GetConstructor(); |
| 8218 DCHECK(constructor->IsJSFunction()); | 8218 DCHECK(constructor->IsJSFunction()); |
| 8219 DCHECK_EQ(*map, JSFunction::cast(constructor)->initial_map()); | 8219 DCHECK_EQ(*map, JSFunction::cast(constructor)->initial_map()); |
| 8220 #endif | 8220 #endif |
| 8221 Handle<Map> result = RawCopy(map, instance_size); | 8221 Handle<Map> result = RawCopy(map, instance_size); |
| 8222 | 8222 |
| 8223 // Please note instance_type and instance_size are set when allocated. | 8223 // Please note instance_type and instance_size are set when allocated. |
| 8224 result->SetInObjectProperties(in_object_properties); | 8224 result->SetInObjectProperties(in_object_properties); |
| 8225 result->set_unused_property_fields(unused_property_fields); | 8225 result->set_unused_property_fields(unused_property_fields); |
| 8226 | 8226 |
| 8227 int number_of_own_descriptors = map->NumberOfOwnDescriptors(); |
| 8228 if (number_of_own_descriptors > 0) { |
| 8229 DCHECK(map->owns_descriptors()); |
| 8230 // The copy will use the same descriptors array, but it's not the owner. |
| 8231 result->UpdateDescriptors(map->instance_descriptors(), |
| 8232 map->layout_descriptor()); |
| 8233 result->set_owns_descriptors(false); |
| 8234 result->SetNumberOfOwnDescriptors(number_of_own_descriptors); |
| 8235 |
| 8236 DCHECK_EQ(result->NumberOfFields(), |
| 8237 in_object_properties - unused_property_fields); |
| 8238 } |
| 8239 |
| 8227 return result; | 8240 return result; |
| 8228 } | 8241 } |
| 8229 | 8242 |
| 8230 | 8243 |
| 8231 Handle<Map> Map::CopyDropDescriptors(Handle<Map> map) { | 8244 Handle<Map> Map::CopyDropDescriptors(Handle<Map> map) { |
| 8232 Handle<Map> result = RawCopy(map, map->instance_size()); | 8245 Handle<Map> result = RawCopy(map, map->instance_size()); |
| 8233 | 8246 |
| 8234 // Please note instance_type and instance_size are set when allocated. | 8247 // Please note instance_type and instance_size are set when allocated. |
| 8235 result->SetInObjectProperties(map->GetInObjectProperties()); | 8248 result->SetInObjectProperties(map->GetInObjectProperties()); |
| 8236 result->set_unused_property_fields(map->unused_property_fields()); | 8249 result->set_unused_property_fields(map->unused_property_fields()); |
| (...skipping 3662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11899 Handle<Object> prototype; | 11912 Handle<Object> prototype; |
| 11900 if (original_constructor->has_instance_prototype()) { | 11913 if (original_constructor->has_instance_prototype()) { |
| 11901 prototype = handle(original_constructor->instance_prototype(), isolate); | 11914 prototype = handle(original_constructor->instance_prototype(), isolate); |
| 11902 } else { | 11915 } else { |
| 11903 prototype = isolate->factory()->NewFunctionPrototype(original_constructor); | 11916 prototype = isolate->factory()->NewFunctionPrototype(original_constructor); |
| 11904 } | 11917 } |
| 11905 | 11918 |
| 11906 // Finally link initial map and constructor function if the original | 11919 // Finally link initial map and constructor function if the original |
| 11907 // constructor is actually a subclass constructor. | 11920 // constructor is actually a subclass constructor. |
| 11908 if (IsSubclassConstructor(original_constructor->shared()->kind())) { | 11921 if (IsSubclassConstructor(original_constructor->shared()->kind())) { |
| 11922 // TODO(ishell): v8:4531, allow ES6 built-ins subclasses to have |
| 11923 // in-object properties. |
| 11924 #if 0 |
| 11909 InstanceType instance_type = constructor_initial_map->instance_type(); | 11925 InstanceType instance_type = constructor_initial_map->instance_type(); |
| 11910 int internal_fields = | 11926 int internal_fields = |
| 11911 JSObject::GetInternalFieldCount(*constructor_initial_map); | 11927 JSObject::GetInternalFieldCount(*constructor_initial_map); |
| 11928 int pre_allocated = constructor_initial_map->GetInObjectProperties() - |
| 11929 constructor_initial_map->unused_property_fields(); |
| 11912 int instance_size; | 11930 int instance_size; |
| 11913 int in_object_properties; | 11931 int in_object_properties; |
| 11914 original_constructor->CalculateInstanceSizeForDerivedClass( | 11932 original_constructor->CalculateInstanceSizeForDerivedClass( |
| 11915 instance_type, internal_fields, &instance_size, &in_object_properties); | 11933 instance_type, internal_fields, &instance_size, &in_object_properties); |
| 11916 | 11934 |
| 11935 int unused_property_fields = in_object_properties - pre_allocated; |
| 11917 Handle<Map> map = | 11936 Handle<Map> map = |
| 11918 Map::CopyInitialMap(constructor_initial_map, instance_size, | 11937 Map::CopyInitialMap(constructor_initial_map, instance_size, |
| 11919 in_object_properties, in_object_properties); | 11938 in_object_properties, unused_property_fields); |
| 11939 #endif |
| 11940 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); |
| 11920 | 11941 |
| 11921 JSFunction::SetInitialMap(original_constructor, map, prototype); | 11942 JSFunction::SetInitialMap(original_constructor, map, prototype); |
| 11922 map->SetConstructor(*constructor); | 11943 map->SetConstructor(*constructor); |
| 11923 original_constructor->StartInobjectSlackTracking(); | 11944 original_constructor->StartInobjectSlackTracking(); |
| 11924 return map; | 11945 return map; |
| 11925 | 11946 |
| 11926 } else { | 11947 } else { |
| 11927 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); | 11948 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); |
| 11928 DCHECK(prototype->IsJSReceiver()); | 11949 DCHECK(prototype->IsJSReceiver()); |
| 11929 if (map->prototype() != *prototype) { | 11950 if (map->prototype() != *prototype) { |
| (...skipping 6082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18012 if (cell->value() != *new_value) { | 18033 if (cell->value() != *new_value) { |
| 18013 cell->set_value(*new_value); | 18034 cell->set_value(*new_value); |
| 18014 Isolate* isolate = cell->GetIsolate(); | 18035 Isolate* isolate = cell->GetIsolate(); |
| 18015 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18036 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 18016 isolate, DependentCode::kPropertyCellChangedGroup); | 18037 isolate, DependentCode::kPropertyCellChangedGroup); |
| 18017 } | 18038 } |
| 18018 } | 18039 } |
| 18019 | 18040 |
| 18020 } // namespace internal | 18041 } // namespace internal |
| 18021 } // namespace v8 | 18042 } // namespace v8 |
| OLD | NEW |