Chromium Code Reviews| 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 11929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11940 #if TRACE_MAPS | 11940 #if TRACE_MAPS |
| 11941 if (FLAG_trace_maps) { | 11941 if (FLAG_trace_maps) { |
| 11942 PrintF("[TraceMaps: InitialMap map= %p SFI= %d_%s ]\n", | 11942 PrintF("[TraceMaps: InitialMap map= %p SFI= %d_%s ]\n", |
| 11943 reinterpret_cast<void*>(*map), function->shared()->unique_id(), | 11943 reinterpret_cast<void*>(*map), function->shared()->unique_id(), |
| 11944 function->shared()->DebugName()->ToCString().get()); | 11944 function->shared()->DebugName()->ToCString().get()); |
| 11945 } | 11945 } |
| 11946 #endif | 11946 #endif |
| 11947 } | 11947 } |
| 11948 | 11948 |
| 11949 | 11949 |
| 11950 namespace { | |
| 11951 | |
| 11952 bool CanSubclassHaveInobjectProperties(InstanceType instance_type) { | |
| 11953 switch (instance_type) { | |
| 11954 case JS_OBJECT_TYPE: | |
| 11955 case JS_CONTEXT_EXTENSION_OBJECT_TYPE: | |
| 11956 case JS_GENERATOR_OBJECT_TYPE: | |
| 11957 case JS_MODULE_TYPE: | |
| 11958 case JS_VALUE_TYPE: | |
| 11959 case JS_DATE_TYPE: | |
| 11960 case JS_ARRAY_TYPE: | |
| 11961 case JS_MESSAGE_OBJECT_TYPE: | |
| 11962 case JS_SET_ITERATOR_TYPE: | |
| 11963 case JS_MAP_ITERATOR_TYPE: | |
| 11964 case JS_ITERATOR_RESULT_TYPE: | |
| 11965 return true; | |
| 11966 | |
| 11967 case JS_TYPED_ARRAY_TYPE: | |
| 11968 case JS_DATA_VIEW_TYPE: | |
| 11969 case JS_REGEXP_TYPE: | |
| 11970 case JS_SET_TYPE: | |
| 11971 case JS_MAP_TYPE: | |
| 11972 case JS_PROXY_TYPE: | |
| 11973 case JS_FUNCTION_PROXY_TYPE: | |
| 11974 case JS_WEAK_MAP_TYPE: | |
| 11975 case JS_WEAK_SET_TYPE: | |
| 11976 case JS_PROMISE_TYPE: | |
|
Toon Verwaest
2015/11/20 11:52:08
JS_PROMISE_TYPE can be moved to the true part, sin
Igor Sheludko
2015/11/20 12:30:57
Done.
| |
| 11977 case JS_ARRAY_BUFFER_TYPE: | |
| 11978 case JS_FUNCTION_TYPE: | |
| 11979 return false; | |
| 11980 | |
| 11981 case JS_GLOBAL_PROXY_TYPE: | |
| 11982 case JS_GLOBAL_OBJECT_TYPE: | |
| 11983 case FIXED_ARRAY_TYPE: | |
| 11984 case FIXED_DOUBLE_ARRAY_TYPE: | |
| 11985 case ODDBALL_TYPE: | |
| 11986 case FOREIGN_TYPE: | |
| 11987 case MAP_TYPE: | |
| 11988 case CODE_TYPE: | |
| 11989 case CELL_TYPE: | |
| 11990 case PROPERTY_CELL_TYPE: | |
| 11991 case WEAK_CELL_TYPE: | |
| 11992 case SYMBOL_TYPE: | |
| 11993 case BYTECODE_ARRAY_TYPE: | |
| 11994 case HEAP_NUMBER_TYPE: | |
| 11995 case MUTABLE_HEAP_NUMBER_TYPE: | |
| 11996 case SIMD128_VALUE_TYPE: | |
| 11997 case FILLER_TYPE: | |
| 11998 case BYTE_ARRAY_TYPE: | |
| 11999 case FREE_SPACE_TYPE: | |
| 12000 case SHARED_FUNCTION_INFO_TYPE: | |
| 12001 | |
| 12002 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | |
| 12003 case FIXED_##TYPE##_ARRAY_TYPE: | |
| 12004 #undef TYPED_ARRAY_CASE | |
| 12005 | |
| 12006 #define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE: | |
| 12007 STRUCT_LIST(MAKE_STRUCT_CASE) | |
| 12008 #undef MAKE_STRUCT_CASE | |
| 12009 // We must not end up here for these instance types at all. | |
| 12010 UNREACHABLE(); | |
| 12011 // Fall through. | |
| 12012 default: | |
| 12013 return false; | |
| 12014 } | |
| 12015 } | |
| 12016 | |
| 12017 } // namespace | |
| 12018 | |
| 12019 | |
| 11950 void JSFunction::EnsureHasInitialMap(Handle<JSFunction> function) { | 12020 void JSFunction::EnsureHasInitialMap(Handle<JSFunction> function) { |
| 11951 if (function->has_initial_map()) return; | 12021 if (function->has_initial_map()) return; |
| 11952 Isolate* isolate = function->GetIsolate(); | 12022 Isolate* isolate = function->GetIsolate(); |
| 11953 | 12023 |
| 11954 // First create a new map with the size and number of in-object properties | 12024 // First create a new map with the size and number of in-object properties |
| 11955 // suggested by the function. | 12025 // suggested by the function. |
| 11956 InstanceType instance_type; | 12026 InstanceType instance_type; |
| 11957 if (function->shared()->is_generator()) { | 12027 if (function->shared()->is_generator()) { |
| 11958 instance_type = JS_GENERATOR_OBJECT_TYPE; | 12028 instance_type = JS_GENERATOR_OBJECT_TYPE; |
| 11959 } else { | 12029 } else { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12014 Handle<Object> prototype; | 12084 Handle<Object> prototype; |
| 12015 if (new_target->has_instance_prototype()) { | 12085 if (new_target->has_instance_prototype()) { |
| 12016 prototype = handle(new_target->instance_prototype(), isolate); | 12086 prototype = handle(new_target->instance_prototype(), isolate); |
| 12017 } else { | 12087 } else { |
| 12018 prototype = isolate->factory()->NewFunctionPrototype(new_target); | 12088 prototype = isolate->factory()->NewFunctionPrototype(new_target); |
| 12019 } | 12089 } |
| 12020 | 12090 |
| 12021 // Finally link initial map and constructor function if the original | 12091 // Finally link initial map and constructor function if the original |
| 12022 // constructor is actually a subclass constructor. | 12092 // constructor is actually a subclass constructor. |
| 12023 if (IsSubclassConstructor(new_target->shared()->kind())) { | 12093 if (IsSubclassConstructor(new_target->shared()->kind())) { |
| 12024 // TODO(ishell): v8:4531, allow ES6 built-ins subclasses to have | 12094 // TODO(ishell): v8:4531, allow ES6 built-ins subclasses to have |
| 12025 // in-object properties. | 12095 // in-object properties. |
| 12026 #if 0 | |
| 12027 InstanceType instance_type = constructor_initial_map->instance_type(); | 12096 InstanceType instance_type = constructor_initial_map->instance_type(); |
| 12028 int internal_fields = | 12097 Handle<Map> map; |
| 12029 JSObject::GetInternalFieldCount(*constructor_initial_map); | 12098 if (CanSubclassHaveInobjectProperties(instance_type)) { |
| 12030 int pre_allocated = constructor_initial_map->GetInObjectProperties() - | 12099 int internal_fields = |
| 12031 constructor_initial_map->unused_property_fields(); | 12100 JSObject::GetInternalFieldCount(*constructor_initial_map); |
| 12032 int instance_size; | 12101 int pre_allocated = constructor_initial_map->GetInObjectProperties() - |
| 12033 int in_object_properties; | 12102 constructor_initial_map->unused_property_fields(); |
| 12034 new_target->CalculateInstanceSizeForDerivedClass( | 12103 int instance_size; |
| 12035 instance_type, internal_fields, &instance_size, &in_object_properties); | 12104 int in_object_properties; |
| 12105 new_target->CalculateInstanceSizeForDerivedClass( | |
| 12106 instance_type, internal_fields, &instance_size, | |
| 12107 &in_object_properties); | |
| 12036 | 12108 |
| 12037 int unused_property_fields = in_object_properties - pre_allocated; | 12109 int unused_property_fields = in_object_properties - pre_allocated; |
| 12038 Handle<Map> map = | 12110 map = Map::CopyInitialMap(constructor_initial_map, instance_size, |
| 12039 Map::CopyInitialMap(constructor_initial_map, instance_size, | 12111 in_object_properties, unused_property_fields); |
| 12040 in_object_properties, unused_property_fields); | 12112 } else { |
| 12041 #endif | 12113 map = Map::CopyInitialMap(constructor_initial_map); |
| 12042 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); | 12114 } |
| 12043 | 12115 |
| 12044 JSFunction::SetInitialMap(new_target, map, prototype); | 12116 JSFunction::SetInitialMap(new_target, map, prototype); |
| 12045 map->SetConstructor(*constructor); | 12117 map->SetConstructor(*constructor); |
| 12046 new_target->StartInobjectSlackTracking(); | 12118 new_target->StartInobjectSlackTracking(); |
| 12047 return map; | 12119 return map; |
| 12048 | 12120 |
| 12049 } else { | 12121 } else { |
| 12050 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); | 12122 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); |
| 12051 DCHECK(prototype->IsJSReceiver()); | 12123 DCHECK(prototype->IsJSReceiver()); |
| 12052 if (map->prototype() != *prototype) { | 12124 if (map->prototype() != *prototype) { |
| (...skipping 6282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 18335 if (cell->value() != *new_value) { | 18407 if (cell->value() != *new_value) { |
| 18336 cell->set_value(*new_value); | 18408 cell->set_value(*new_value); |
| 18337 Isolate* isolate = cell->GetIsolate(); | 18409 Isolate* isolate = cell->GetIsolate(); |
| 18338 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18410 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 18339 isolate, DependentCode::kPropertyCellChangedGroup); | 18411 isolate, DependentCode::kPropertyCellChangedGroup); |
| 18340 } | 18412 } |
| 18341 } | 18413 } |
| 18342 | 18414 |
| 18343 } // namespace internal | 18415 } // namespace internal |
| 18344 } // namespace v8 | 18416 } // namespace v8 |
| OLD | NEW |