| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
| (...skipping 7248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7259 if (map->owns_descriptors()) { | 7259 if (map->owns_descriptors()) { |
| 7260 new_map->InitializeDescriptors(map->instance_descriptors()); | 7260 new_map->InitializeDescriptors(map->instance_descriptors()); |
| 7261 map->set_owns_descriptors(false); | 7261 map->set_owns_descriptors(false); |
| 7262 } | 7262 } |
| 7263 | 7263 |
| 7264 new_map->SetBackPointer(*map); | 7264 new_map->SetBackPointer(*map); |
| 7265 return new_map; | 7265 return new_map; |
| 7266 } | 7266 } |
| 7267 | 7267 |
| 7268 | 7268 |
| 7269 Handle<Map> Map::CopyAsPrototypeMap(Handle<Map> map) { |
| 7270 Handle<Map> result = Copy(map); |
| 7271 result->mark_prototype_map(); |
| 7272 return result; |
| 7273 } |
| 7274 |
| 7275 |
| 7269 Handle<Map> Map::Copy(Handle<Map> map) { | 7276 Handle<Map> Map::Copy(Handle<Map> map) { |
| 7270 Handle<DescriptorArray> descriptors(map->instance_descriptors()); | 7277 Handle<DescriptorArray> descriptors(map->instance_descriptors()); |
| 7271 int number_of_own_descriptors = map->NumberOfOwnDescriptors(); | 7278 int number_of_own_descriptors = map->NumberOfOwnDescriptors(); |
| 7272 Handle<DescriptorArray> new_descriptors = | 7279 Handle<DescriptorArray> new_descriptors = |
| 7273 DescriptorArray::CopyUpTo(descriptors, number_of_own_descriptors); | 7280 DescriptorArray::CopyUpTo(descriptors, number_of_own_descriptors); |
| 7274 return CopyReplaceDescriptors( | 7281 return CopyReplaceDescriptors( |
| 7275 map, new_descriptors, OMIT_TRANSITION, MaybeHandle<Name>()); | 7282 map, new_descriptors, OMIT_TRANSITION, MaybeHandle<Name>()); |
| 7276 } | 7283 } |
| 7277 | 7284 |
| 7278 | 7285 |
| (...skipping 2717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9996 | 10003 |
| 9997 void JSFunction::SetInstancePrototype(Handle<JSFunction> function, | 10004 void JSFunction::SetInstancePrototype(Handle<JSFunction> function, |
| 9998 Handle<Object> value) { | 10005 Handle<Object> value) { |
| 9999 Isolate* isolate = function->GetIsolate(); | 10006 Isolate* isolate = function->GetIsolate(); |
| 10000 | 10007 |
| 10001 ASSERT(value->IsJSReceiver()); | 10008 ASSERT(value->IsJSReceiver()); |
| 10002 | 10009 |
| 10003 // First some logic for the map of the prototype to make sure it is in fast | 10010 // First some logic for the map of the prototype to make sure it is in fast |
| 10004 // mode. | 10011 // mode. |
| 10005 if (value->IsJSObject()) { | 10012 if (value->IsJSObject()) { |
| 10006 JSObject::OptimizeAsPrototype(Handle<JSObject>::cast(value)); | 10013 Handle<JSObject> js_proto = Handle<JSObject>::cast(value); |
| 10014 JSObject::OptimizeAsPrototype(js_proto); |
| 10015 if (js_proto->HasFastProperties()) { |
| 10016 Handle<Map> new_map = Map::CopyAsPrototypeMap(handle(js_proto->map())); |
| 10017 JSObject::MigrateToMap(js_proto, new_map); |
| 10018 } |
| 10007 } | 10019 } |
| 10008 | 10020 |
| 10009 // Now some logic for the maps of the objects that are created by using this | 10021 // Now some logic for the maps of the objects that are created by using this |
| 10010 // function as a constructor. | 10022 // function as a constructor. |
| 10011 if (function->has_initial_map()) { | 10023 if (function->has_initial_map()) { |
| 10012 // If the function has allocated the initial map replace it with a | 10024 // If the function has allocated the initial map replace it with a |
| 10013 // copy containing the new prototype. Also complete any in-object | 10025 // copy containing the new prototype. Also complete any in-object |
| 10014 // slack tracking that is in progress at this point because it is | 10026 // slack tracking that is in progress at this point because it is |
| 10015 // still tracking the old copy. | 10027 // still tracking the old copy. |
| 10016 if (function->IsInobjectSlackTrackingInProgress()) { | 10028 if (function->IsInobjectSlackTrackingInProgress()) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10113 instance_type = JS_OBJECT_TYPE; | 10125 instance_type = JS_OBJECT_TYPE; |
| 10114 instance_size = function->shared()->CalculateInstanceSize(); | 10126 instance_size = function->shared()->CalculateInstanceSize(); |
| 10115 in_object_properties = function->shared()->CalculateInObjectProperties(); | 10127 in_object_properties = function->shared()->CalculateInObjectProperties(); |
| 10116 } | 10128 } |
| 10117 Handle<Map> map = isolate->factory()->NewMap(instance_type, instance_size); | 10129 Handle<Map> map = isolate->factory()->NewMap(instance_type, instance_size); |
| 10118 | 10130 |
| 10119 // Fetch or allocate prototype. | 10131 // Fetch or allocate prototype. |
| 10120 Handle<Object> prototype; | 10132 Handle<Object> prototype; |
| 10121 if (function->has_instance_prototype()) { | 10133 if (function->has_instance_prototype()) { |
| 10122 prototype = handle(function->instance_prototype(), isolate); | 10134 prototype = handle(function->instance_prototype(), isolate); |
| 10123 for (PrototypeIterator iter(isolate, prototype, | 10135 // TODO(verwaest): Remove once "delete" keeps objects marked as prototypes |
| 10124 PrototypeIterator::START_AT_RECEIVER); | 10136 // fast as well. |
| 10125 !iter.IsAtEnd(); iter.Advance()) { | 10137 JSObject::OptimizeAsPrototype(Handle<JSObject>::cast(prototype)); |
| 10126 if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) { | |
| 10127 break; | |
| 10128 } | |
| 10129 JSObject::OptimizeAsPrototype( | |
| 10130 Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter))); | |
| 10131 } | |
| 10132 } else { | 10138 } else { |
| 10133 prototype = isolate->factory()->NewFunctionPrototype(function); | 10139 prototype = isolate->factory()->NewFunctionPrototype(function); |
| 10134 } | 10140 } |
| 10135 map->set_inobject_properties(in_object_properties); | 10141 map->set_inobject_properties(in_object_properties); |
| 10136 map->set_unused_property_fields(in_object_properties); | 10142 map->set_unused_property_fields(in_object_properties); |
| 10137 map->set_prototype(*prototype); | 10143 map->set_prototype(*prototype); |
| 10138 ASSERT(map->has_fast_object_elements()); | 10144 ASSERT(map->has_fast_object_elements()); |
| 10139 | 10145 |
| 10140 // Finally link initial map and constructor function. | 10146 // Finally link initial map and constructor function. |
| 10141 function->set_initial_map(*map); | 10147 function->set_initial_map(*map); |
| (...skipping 6876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17018 #define ERROR_MESSAGES_TEXTS(C, T) T, | 17024 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 17019 static const char* error_messages_[] = { | 17025 static const char* error_messages_[] = { |
| 17020 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 17026 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 17021 }; | 17027 }; |
| 17022 #undef ERROR_MESSAGES_TEXTS | 17028 #undef ERROR_MESSAGES_TEXTS |
| 17023 return error_messages_[reason]; | 17029 return error_messages_[reason]; |
| 17024 } | 17030 } |
| 17025 | 17031 |
| 17026 | 17032 |
| 17027 } } // namespace v8::internal | 17033 } } // namespace v8::internal |
| OLD | NEW |