| 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 12027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12038 #if TRACE_MAPS | 12038 #if TRACE_MAPS |
| 12039 if (FLAG_trace_maps) { | 12039 if (FLAG_trace_maps) { |
| 12040 PrintF("[TraceMaps: InitialMap map= %p SFI= %d_%s ]\n", | 12040 PrintF("[TraceMaps: InitialMap map= %p SFI= %d_%s ]\n", |
| 12041 reinterpret_cast<void*>(*map), function->shared()->unique_id(), | 12041 reinterpret_cast<void*>(*map), function->shared()->unique_id(), |
| 12042 function->shared()->DebugName()->ToCString().get()); | 12042 function->shared()->DebugName()->ToCString().get()); |
| 12043 } | 12043 } |
| 12044 #endif | 12044 #endif |
| 12045 } | 12045 } |
| 12046 | 12046 |
| 12047 | 12047 |
| 12048 #ifdef DEBUG |
| 12048 namespace { | 12049 namespace { |
| 12049 | 12050 |
| 12050 bool CanSubclassHaveInobjectProperties(InstanceType instance_type) { | 12051 bool CanSubclassHaveInobjectProperties(InstanceType instance_type) { |
| 12051 switch (instance_type) { | 12052 switch (instance_type) { |
| 12052 case JS_OBJECT_TYPE: | 12053 case JS_OBJECT_TYPE: |
| 12053 case JS_CONTEXT_EXTENSION_OBJECT_TYPE: | 12054 case JS_CONTEXT_EXTENSION_OBJECT_TYPE: |
| 12054 case JS_GENERATOR_OBJECT_TYPE: | 12055 case JS_GENERATOR_OBJECT_TYPE: |
| 12055 case JS_MODULE_TYPE: | 12056 case JS_MODULE_TYPE: |
| 12056 case JS_VALUE_TYPE: | 12057 case JS_VALUE_TYPE: |
| 12057 case JS_DATE_TYPE: | 12058 case JS_DATE_TYPE: |
| 12058 case JS_ARRAY_TYPE: | 12059 case JS_ARRAY_TYPE: |
| 12059 case JS_MESSAGE_OBJECT_TYPE: | 12060 case JS_MESSAGE_OBJECT_TYPE: |
| 12061 case JS_ARRAY_BUFFER_TYPE: |
| 12060 case JS_TYPED_ARRAY_TYPE: | 12062 case JS_TYPED_ARRAY_TYPE: |
| 12061 case JS_DATA_VIEW_TYPE: | 12063 case JS_DATA_VIEW_TYPE: |
| 12062 case JS_SET_TYPE: | 12064 case JS_SET_TYPE: |
| 12063 case JS_MAP_TYPE: | 12065 case JS_MAP_TYPE: |
| 12064 case JS_SET_ITERATOR_TYPE: | 12066 case JS_SET_ITERATOR_TYPE: |
| 12065 case JS_MAP_ITERATOR_TYPE: | 12067 case JS_MAP_ITERATOR_TYPE: |
| 12066 case JS_ITERATOR_RESULT_TYPE: | 12068 case JS_ITERATOR_RESULT_TYPE: |
| 12067 case JS_WEAK_MAP_TYPE: | 12069 case JS_WEAK_MAP_TYPE: |
| 12068 case JS_WEAK_SET_TYPE: | 12070 case JS_WEAK_SET_TYPE: |
| 12069 case JS_PROMISE_TYPE: | 12071 case JS_PROMISE_TYPE: |
| 12070 case JS_REGEXP_TYPE: | 12072 case JS_REGEXP_TYPE: |
| 12071 case JS_FUNCTION_TYPE: | 12073 case JS_FUNCTION_TYPE: |
| 12072 return true; | 12074 return true; |
| 12073 | 12075 |
| 12076 case JS_FUNCTION_PROXY_TYPE: |
| 12074 case JS_PROXY_TYPE: | 12077 case JS_PROXY_TYPE: |
| 12075 case JS_FUNCTION_PROXY_TYPE: | |
| 12076 case JS_ARRAY_BUFFER_TYPE: | |
| 12077 return false; | |
| 12078 | |
| 12079 case JS_GLOBAL_PROXY_TYPE: | 12078 case JS_GLOBAL_PROXY_TYPE: |
| 12080 case JS_GLOBAL_OBJECT_TYPE: | 12079 case JS_GLOBAL_OBJECT_TYPE: |
| 12081 case FIXED_ARRAY_TYPE: | 12080 case FIXED_ARRAY_TYPE: |
| 12082 case FIXED_DOUBLE_ARRAY_TYPE: | 12081 case FIXED_DOUBLE_ARRAY_TYPE: |
| 12083 case ODDBALL_TYPE: | 12082 case ODDBALL_TYPE: |
| 12084 case FOREIGN_TYPE: | 12083 case FOREIGN_TYPE: |
| 12085 case MAP_TYPE: | 12084 case MAP_TYPE: |
| 12086 case CODE_TYPE: | 12085 case CODE_TYPE: |
| 12087 case CELL_TYPE: | 12086 case CELL_TYPE: |
| 12088 case PROPERTY_CELL_TYPE: | 12087 case PROPERTY_CELL_TYPE: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 12106 #undef MAKE_STRUCT_CASE | 12105 #undef MAKE_STRUCT_CASE |
| 12107 // We must not end up here for these instance types at all. | 12106 // We must not end up here for these instance types at all. |
| 12108 UNREACHABLE(); | 12107 UNREACHABLE(); |
| 12109 // Fall through. | 12108 // Fall through. |
| 12110 default: | 12109 default: |
| 12111 return false; | 12110 return false; |
| 12112 } | 12111 } |
| 12113 } | 12112 } |
| 12114 | 12113 |
| 12115 } // namespace | 12114 } // namespace |
| 12115 #endif |
| 12116 | 12116 |
| 12117 | 12117 |
| 12118 void JSFunction::EnsureHasInitialMap(Handle<JSFunction> function) { | 12118 void JSFunction::EnsureHasInitialMap(Handle<JSFunction> function) { |
| 12119 if (function->has_initial_map()) return; | 12119 if (function->has_initial_map()) return; |
| 12120 Isolate* isolate = function->GetIsolate(); | 12120 Isolate* isolate = function->GetIsolate(); |
| 12121 | 12121 |
| 12122 // First create a new map with the size and number of in-object properties | 12122 // First create a new map with the size and number of in-object properties |
| 12123 // suggested by the function. | 12123 // suggested by the function. |
| 12124 InstanceType instance_type; | 12124 InstanceType instance_type; |
| 12125 if (function->shared()->is_generator()) { | 12125 if (function->shared()->is_generator()) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12182 Handle<Object> prototype; | 12182 Handle<Object> prototype; |
| 12183 if (new_target->has_instance_prototype()) { | 12183 if (new_target->has_instance_prototype()) { |
| 12184 prototype = handle(new_target->instance_prototype(), isolate); | 12184 prototype = handle(new_target->instance_prototype(), isolate); |
| 12185 } else { | 12185 } else { |
| 12186 prototype = isolate->factory()->NewFunctionPrototype(new_target); | 12186 prototype = isolate->factory()->NewFunctionPrototype(new_target); |
| 12187 } | 12187 } |
| 12188 | 12188 |
| 12189 // Finally link initial map and constructor function if the original | 12189 // Finally link initial map and constructor function if the original |
| 12190 // constructor is actually a subclass constructor. | 12190 // constructor is actually a subclass constructor. |
| 12191 if (IsSubclassConstructor(new_target->shared()->kind())) { | 12191 if (IsSubclassConstructor(new_target->shared()->kind())) { |
| 12192 // TODO(ishell): v8:4531, allow ES6 built-ins subclasses to have | |
| 12193 // in-object properties. | |
| 12194 InstanceType instance_type = constructor_initial_map->instance_type(); | 12192 InstanceType instance_type = constructor_initial_map->instance_type(); |
| 12195 Handle<Map> map; | 12193 DCHECK(CanSubclassHaveInobjectProperties(instance_type)); |
| 12196 if (CanSubclassHaveInobjectProperties(instance_type)) { | 12194 int internal_fields = |
| 12197 int internal_fields = | 12195 JSObject::GetInternalFieldCount(*constructor_initial_map); |
| 12198 JSObject::GetInternalFieldCount(*constructor_initial_map); | 12196 int pre_allocated = constructor_initial_map->GetInObjectProperties() - |
| 12199 int pre_allocated = constructor_initial_map->GetInObjectProperties() - | 12197 constructor_initial_map->unused_property_fields(); |
| 12200 constructor_initial_map->unused_property_fields(); | 12198 int instance_size; |
| 12201 int instance_size; | 12199 int in_object_properties; |
| 12202 int in_object_properties; | 12200 new_target->CalculateInstanceSizeForDerivedClass( |
| 12203 new_target->CalculateInstanceSizeForDerivedClass( | 12201 instance_type, internal_fields, &instance_size, &in_object_properties); |
| 12204 instance_type, internal_fields, &instance_size, | |
| 12205 &in_object_properties); | |
| 12206 | 12202 |
| 12207 int unused_property_fields = in_object_properties - pre_allocated; | 12203 int unused_property_fields = in_object_properties - pre_allocated; |
| 12208 map = Map::CopyInitialMap(constructor_initial_map, instance_size, | 12204 Handle<Map> map = |
| 12209 in_object_properties, unused_property_fields); | 12205 Map::CopyInitialMap(constructor_initial_map, instance_size, |
| 12210 } else { | 12206 in_object_properties, unused_property_fields); |
| 12211 map = Map::CopyInitialMap(constructor_initial_map); | |
| 12212 } | |
| 12213 | 12207 |
| 12214 JSFunction::SetInitialMap(new_target, map, prototype); | 12208 JSFunction::SetInitialMap(new_target, map, prototype); |
| 12215 map->SetConstructor(*constructor); | 12209 map->SetConstructor(*constructor); |
| 12216 new_target->StartInobjectSlackTracking(); | 12210 new_target->StartInobjectSlackTracking(); |
| 12217 return map; | 12211 return map; |
| 12218 | 12212 |
| 12219 } else { | 12213 } else { |
| 12220 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); | 12214 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map); |
| 12221 DCHECK(prototype->IsJSReceiver()); | 12215 DCHECK(prototype->IsJSReceiver()); |
| 12222 if (map->prototype() != *prototype) { | 12216 if (map->prototype() != *prototype) { |
| (...skipping 6325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 18548 if (cell->value() != *new_value) { | 18542 if (cell->value() != *new_value) { |
| 18549 cell->set_value(*new_value); | 18543 cell->set_value(*new_value); |
| 18550 Isolate* isolate = cell->GetIsolate(); | 18544 Isolate* isolate = cell->GetIsolate(); |
| 18551 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18545 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 18552 isolate, DependentCode::kPropertyCellChangedGroup); | 18546 isolate, DependentCode::kPropertyCellChangedGroup); |
| 18553 } | 18547 } |
| 18554 } | 18548 } |
| 18555 | 18549 |
| 18556 } // namespace internal | 18550 } // namespace internal |
| 18557 } // namespace v8 | 18551 } // namespace v8 |
| OLD | NEW |