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 11922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11933 DCHECK(prototype->IsJSReceiver()); | 11933 DCHECK(prototype->IsJSReceiver()); |
11934 JSFunction::SetInitialMap(function, map, prototype); | 11934 JSFunction::SetInitialMap(function, map, prototype); |
11935 | 11935 |
11936 if (!function->shared()->is_generator()) { | 11936 if (!function->shared()->is_generator()) { |
11937 function->StartInobjectSlackTracking(); | 11937 function->StartInobjectSlackTracking(); |
11938 } | 11938 } |
11939 } | 11939 } |
11940 | 11940 |
11941 | 11941 |
11942 Handle<Map> JSFunction::EnsureDerivedHasInitialMap( | 11942 Handle<Map> JSFunction::EnsureDerivedHasInitialMap( |
11943 Handle<JSFunction> original_constructor, Handle<JSFunction> constructor) { | 11943 Handle<JSFunction> new_target, Handle<JSFunction> constructor) { |
11944 DCHECK(constructor->has_initial_map()); | 11944 DCHECK(constructor->has_initial_map()); |
11945 Isolate* isolate = constructor->GetIsolate(); | 11945 Isolate* isolate = constructor->GetIsolate(); |
11946 Handle<Map> constructor_initial_map(constructor->initial_map(), isolate); | 11946 Handle<Map> constructor_initial_map(constructor->initial_map(), isolate); |
11947 if (*original_constructor == *constructor) return constructor_initial_map; | 11947 if (*new_target == *constructor) return constructor_initial_map; |
11948 if (original_constructor->has_initial_map()) { | 11948 if (new_target->has_initial_map()) { |
11949 // Check that |original_constructor|'s initial map still in sync with | 11949 // Check that |new_target|'s initial map still in sync with |
11950 // the |constructor|, otherwise we must create a new initial map for | 11950 // the |constructor|, otherwise we must create a new initial map for |
11951 // |original_constructor|. | 11951 // |new_target|. |
11952 if (original_constructor->initial_map()->GetConstructor() == *constructor) { | 11952 if (new_target->initial_map()->GetConstructor() == *constructor) { |
11953 return handle(original_constructor->initial_map(), isolate); | 11953 return handle(new_target->initial_map(), isolate); |
11954 } | 11954 } |
11955 } | 11955 } |
11956 | 11956 |
11957 // First create a new map with the size and number of in-object properties | 11957 // First create a new map with the size and number of in-object properties |
11958 // suggested by the function. | 11958 // suggested by the function. |
11959 DCHECK(!original_constructor->shared()->is_generator()); | 11959 DCHECK(!new_target->shared()->is_generator()); |
11960 DCHECK(!constructor->shared()->is_generator()); | 11960 DCHECK(!constructor->shared()->is_generator()); |
11961 | 11961 |
11962 // Fetch or allocate prototype. | 11962 // Fetch or allocate prototype. |
11963 Handle<Object> prototype; | 11963 Handle<Object> prototype; |
11964 if (original_constructor->has_instance_prototype()) { | 11964 if (new_target->has_instance_prototype()) { |
11965 prototype = handle(original_constructor->instance_prototype(), isolate); | 11965 prototype = handle(new_target->instance_prototype(), isolate); |
11966 } else { | 11966 } else { |
11967 prototype = isolate->factory()->NewFunctionPrototype(original_constructor); | 11967 prototype = isolate->factory()->NewFunctionPrototype(new_target); |
11968 } | 11968 } |
11969 | 11969 |
11970 // Finally link initial map and constructor function if the original | 11970 // Finally link initial map and constructor function if the original |
11971 // constructor is actually a subclass constructor. | 11971 // constructor is actually a subclass constructor. |
11972 if (IsSubclassConstructor(original_constructor->shared()->kind())) { | 11972 if (IsSubclassConstructor(new_target->shared()->kind())) { |
11973 // TODO(ishell): v8:4531, allow ES6 built-ins subclasses to have | 11973 // TODO(ishell): v8:4531, allow ES6 built-ins subclasses to have |
11974 // in-object properties. | 11974 // in-object properties. |
11975 #if 0 | 11975 #if 0 |
11976 InstanceType instance_type = constructor_initial_map->instance_type(); | 11976 InstanceType instance_type = constructor_initial_map->instance_type(); |
11977 int internal_fields = | 11977 int internal_fields = |
11978 JSObject::GetInternalFieldCount(*constructor_initial_map); | 11978 JSObject::GetInternalFieldCount(*constructor_initial_map); |
11979 int pre_allocated = constructor_initial_map->GetInObjectProperties() - | 11979 int pre_allocated = constructor_initial_map->GetInObjectProperties() - |
11980 constructor_initial_map->unused_property_fields(); | 11980 constructor_initial_map->unused_property_fields(); |
11981 int instance_size; | 11981 int instance_size; |
11982 int in_object_properties; | 11982 int in_object_properties; |
11983 original_constructor->CalculateInstanceSizeForDerivedClass( | 11983 new_target->CalculateInstanceSizeForDerivedClass( |
11984 instance_type, internal_fields, &instance_size, &in_object_properties); | 11984 instance_type, internal_fields, &instance_size, &in_object_properties); |
11985 | 11985 |
11986 int unused_property_fields = in_object_properties - pre_allocated; | 11986 int unused_property_fields = in_object_properties - pre_allocated; |
11987 Handle<Map> map = | 11987 Handle<Map> map = |
11988 Map::CopyInitialMap(constructor_initial_map, instance_size, | 11988 Map::CopyInitialMap(constructor_initial_map, instance_size, |
11989 in_object_properties, unused_property_fields); | 11989 in_object_properties, unused_property_fields); |
11990 #endif | 11990 #endif |
11991 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); | 11991 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); |
11992 | 11992 |
11993 JSFunction::SetInitialMap(original_constructor, map, prototype); | 11993 JSFunction::SetInitialMap(new_target, map, prototype); |
11994 map->SetConstructor(*constructor); | 11994 map->SetConstructor(*constructor); |
11995 original_constructor->StartInobjectSlackTracking(); | 11995 new_target->StartInobjectSlackTracking(); |
11996 return map; | 11996 return map; |
11997 | 11997 |
11998 } else { | 11998 } else { |
11999 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); | 11999 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); |
12000 DCHECK(prototype->IsJSReceiver()); | 12000 DCHECK(prototype->IsJSReceiver()); |
12001 if (map->prototype() != *prototype) { | 12001 if (map->prototype() != *prototype) { |
12002 Map::SetPrototype(map, prototype, FAST_PROTOTYPE); | 12002 Map::SetPrototype(map, prototype, FAST_PROTOTYPE); |
12003 } | 12003 } |
12004 map->SetConstructor(*constructor); | 12004 map->SetConstructor(*constructor); |
12005 return map; | 12005 return map; |
(...skipping 6116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18122 if (cell->value() != *new_value) { | 18122 if (cell->value() != *new_value) { |
18123 cell->set_value(*new_value); | 18123 cell->set_value(*new_value); |
18124 Isolate* isolate = cell->GetIsolate(); | 18124 Isolate* isolate = cell->GetIsolate(); |
18125 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18125 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
18126 isolate, DependentCode::kPropertyCellChangedGroup); | 18126 isolate, DependentCode::kPropertyCellChangedGroup); |
18127 } | 18127 } |
18128 } | 18128 } |
18129 | 18129 |
18130 } // namespace internal | 18130 } // namespace internal |
18131 } // namespace v8 | 18131 } // namespace v8 |
OLD | NEW |