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 11878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11889 #if TRACE_MAPS | 11889 #if TRACE_MAPS |
11890 if (FLAG_trace_maps) { | 11890 if (FLAG_trace_maps) { |
11891 PrintF("[TraceMaps: InitialMap map= %p SFI= %d_%s ]\n", | 11891 PrintF("[TraceMaps: InitialMap map= %p SFI= %d_%s ]\n", |
11892 reinterpret_cast<void*>(*map), function->shared()->unique_id(), | 11892 reinterpret_cast<void*>(*map), function->shared()->unique_id(), |
11893 function->shared()->DebugName()->ToCString().get()); | 11893 function->shared()->DebugName()->ToCString().get()); |
11894 } | 11894 } |
11895 #endif | 11895 #endif |
11896 } | 11896 } |
11897 | 11897 |
11898 | 11898 |
11899 namespace { | |
11900 | |
11901 bool CanSubclassHaveInobjectProperties(InstanceType instance_type) { | |
11902 switch (instance_type) { | |
11903 case JS_OBJECT_TYPE: | |
11904 case JS_CONTEXT_EXTENSION_OBJECT_TYPE: | |
11905 case JS_GENERATOR_OBJECT_TYPE: | |
11906 case JS_MODULE_TYPE: | |
11907 case JS_VALUE_TYPE: | |
11908 case JS_DATE_TYPE: | |
11909 case JS_ARRAY_TYPE: | |
11910 case JS_MESSAGE_OBJECT_TYPE: | |
11911 case JS_SET_ITERATOR_TYPE: | |
11912 case JS_MAP_ITERATOR_TYPE: | |
11913 case JS_ITERATOR_RESULT_TYPE: | |
11914 return true; | |
11915 | |
11916 case JS_TYPED_ARRAY_TYPE: | |
11917 case JS_DATA_VIEW_TYPE: | |
11918 case JS_REGEXP_TYPE: | |
11919 case JS_SET_TYPE: | |
11920 case JS_MAP_TYPE: | |
11921 case JS_PROXY_TYPE: | |
11922 case JS_FUNCTION_PROXY_TYPE: | |
11923 case JS_WEAK_MAP_TYPE: | |
11924 case JS_WEAK_SET_TYPE: | |
11925 case JS_ARRAY_BUFFER_TYPE: | |
11926 case JS_FUNCTION_TYPE: | |
11927 return false; | |
11928 | |
11929 case JS_GLOBAL_PROXY_TYPE: | |
11930 case JS_GLOBAL_OBJECT_TYPE: | |
11931 case FIXED_ARRAY_TYPE: | |
11932 case FIXED_DOUBLE_ARRAY_TYPE: | |
11933 case ODDBALL_TYPE: | |
11934 case FOREIGN_TYPE: | |
11935 case MAP_TYPE: | |
11936 case CODE_TYPE: | |
11937 case CELL_TYPE: | |
11938 case PROPERTY_CELL_TYPE: | |
11939 case WEAK_CELL_TYPE: | |
11940 case SYMBOL_TYPE: | |
11941 case BYTECODE_ARRAY_TYPE: | |
11942 case HEAP_NUMBER_TYPE: | |
11943 case MUTABLE_HEAP_NUMBER_TYPE: | |
11944 case SIMD128_VALUE_TYPE: | |
11945 case FILLER_TYPE: | |
11946 case BYTE_ARRAY_TYPE: | |
11947 case FREE_SPACE_TYPE: | |
11948 case SHARED_FUNCTION_INFO_TYPE: | |
11949 | |
11950 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | |
11951 case FIXED_##TYPE##_ARRAY_TYPE: | |
11952 #undef TYPED_ARRAY_CASE | |
11953 | |
11954 #define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE: | |
11955 STRUCT_LIST(MAKE_STRUCT_CASE) | |
11956 #undef MAKE_STRUCT_CASE | |
11957 // We must not end up here for these instance types at all. | |
11958 UNREACHABLE(); | |
11959 // Fall through. | |
11960 default: | |
11961 return false; | |
11962 } | |
11963 } | |
11964 | |
11965 } // namespace | |
11966 | |
11967 | |
11968 void JSFunction::EnsureHasInitialMap(Handle<JSFunction> function) { | 11899 void JSFunction::EnsureHasInitialMap(Handle<JSFunction> function) { |
11969 if (function->has_initial_map()) return; | 11900 if (function->has_initial_map()) return; |
11970 Isolate* isolate = function->GetIsolate(); | 11901 Isolate* isolate = function->GetIsolate(); |
11971 | 11902 |
11972 // First create a new map with the size and number of in-object properties | 11903 // First create a new map with the size and number of in-object properties |
11973 // suggested by the function. | 11904 // suggested by the function. |
11974 InstanceType instance_type; | 11905 InstanceType instance_type; |
11975 if (function->shared()->is_generator()) { | 11906 if (function->shared()->is_generator()) { |
11976 instance_type = JS_GENERATOR_OBJECT_TYPE; | 11907 instance_type = JS_GENERATOR_OBJECT_TYPE; |
11977 } else { | 11908 } else { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12032 Handle<Object> prototype; | 11963 Handle<Object> prototype; |
12033 if (new_target->has_instance_prototype()) { | 11964 if (new_target->has_instance_prototype()) { |
12034 prototype = handle(new_target->instance_prototype(), isolate); | 11965 prototype = handle(new_target->instance_prototype(), isolate); |
12035 } else { | 11966 } else { |
12036 prototype = isolate->factory()->NewFunctionPrototype(new_target); | 11967 prototype = isolate->factory()->NewFunctionPrototype(new_target); |
12037 } | 11968 } |
12038 | 11969 |
12039 // Finally link initial map and constructor function if the original | 11970 // Finally link initial map and constructor function if the original |
12040 // constructor is actually a subclass constructor. | 11971 // constructor is actually a subclass constructor. |
12041 if (IsSubclassConstructor(new_target->shared()->kind())) { | 11972 if (IsSubclassConstructor(new_target->shared()->kind())) { |
12042 // TODO(ishell): v8:4531, allow ES6 built-ins subclasses to have | 11973 // TODO(ishell): v8:4531, allow ES6 built-ins subclasses to have |
12043 // in-object properties. | 11974 // in-object properties. |
| 11975 #if 0 |
12044 InstanceType instance_type = constructor_initial_map->instance_type(); | 11976 InstanceType instance_type = constructor_initial_map->instance_type(); |
12045 Handle<Map> map; | 11977 int internal_fields = |
12046 if (CanSubclassHaveInobjectProperties(instance_type)) { | 11978 JSObject::GetInternalFieldCount(*constructor_initial_map); |
12047 int internal_fields = | 11979 int pre_allocated = constructor_initial_map->GetInObjectProperties() - |
12048 JSObject::GetInternalFieldCount(*constructor_initial_map); | 11980 constructor_initial_map->unused_property_fields(); |
12049 int pre_allocated = constructor_initial_map->GetInObjectProperties() - | 11981 int instance_size; |
12050 constructor_initial_map->unused_property_fields(); | 11982 int in_object_properties; |
12051 int instance_size; | 11983 new_target->CalculateInstanceSizeForDerivedClass( |
12052 int in_object_properties; | 11984 instance_type, internal_fields, &instance_size, &in_object_properties); |
12053 new_target->CalculateInstanceSizeForDerivedClass( | |
12054 instance_type, internal_fields, &instance_size, | |
12055 &in_object_properties); | |
12056 | 11985 |
12057 int unused_property_fields = in_object_properties - pre_allocated; | 11986 int unused_property_fields = in_object_properties - pre_allocated; |
12058 map = Map::CopyInitialMap(constructor_initial_map, instance_size, | 11987 Handle<Map> map = |
12059 in_object_properties, unused_property_fields); | 11988 Map::CopyInitialMap(constructor_initial_map, instance_size, |
12060 } else { | 11989 in_object_properties, unused_property_fields); |
12061 map = Map::CopyInitialMap(constructor_initial_map); | 11990 #endif |
12062 } | 11991 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); |
12063 | 11992 |
12064 JSFunction::SetInitialMap(new_target, map, prototype); | 11993 JSFunction::SetInitialMap(new_target, map, prototype); |
12065 map->SetConstructor(*constructor); | 11994 map->SetConstructor(*constructor); |
12066 new_target->StartInobjectSlackTracking(); | 11995 new_target->StartInobjectSlackTracking(); |
12067 return map; | 11996 return map; |
12068 | 11997 |
12069 } else { | 11998 } else { |
12070 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); | 11999 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); |
12071 DCHECK(prototype->IsJSReceiver()); | 12000 DCHECK(prototype->IsJSReceiver()); |
12072 if (map->prototype() != *prototype) { | 12001 if (map->prototype() != *prototype) { |
(...skipping 6120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18193 if (cell->value() != *new_value) { | 18122 if (cell->value() != *new_value) { |
18194 cell->set_value(*new_value); | 18123 cell->set_value(*new_value); |
18195 Isolate* isolate = cell->GetIsolate(); | 18124 Isolate* isolate = cell->GetIsolate(); |
18196 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18125 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
18197 isolate, DependentCode::kPropertyCellChangedGroup); | 18126 isolate, DependentCode::kPropertyCellChangedGroup); |
18198 } | 18127 } |
18199 } | 18128 } |
18200 | 18129 |
18201 } // namespace internal | 18130 } // namespace internal |
18202 } // namespace v8 | 18131 } // namespace v8 |
OLD | NEW |