OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 Handle<Object> prototype = args.at(0); | 215 Handle<Object> prototype = args.at(0); |
216 if (!prototype->IsNull(isolate) && !prototype->IsJSReceiver()) { | 216 if (!prototype->IsNull(isolate) && !prototype->IsJSReceiver()) { |
217 THROW_NEW_ERROR_RETURN_FAILURE( | 217 THROW_NEW_ERROR_RETURN_FAILURE( |
218 isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, prototype)); | 218 isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, prototype)); |
219 } | 219 } |
220 | 220 |
221 // Generate the map with the specified {prototype} based on the Object | 221 // Generate the map with the specified {prototype} based on the Object |
222 // function's initial map from the current native context. | 222 // function's initial map from the current native context. |
223 // TODO(bmeurer): Use a dedicated cache for Object.create; think about | 223 // TODO(bmeurer): Use a dedicated cache for Object.create; think about |
224 // slack tracking for Object.create. | 224 // slack tracking for Object.create. |
225 Handle<Map> map(isolate->native_context()->object_function()->initial_map(), | 225 Handle<Map> map = |
226 isolate); | 226 Map::GetObjectCreateMap(Handle<HeapObject>::cast(prototype)); |
227 if (map->prototype() != *prototype) { | |
228 if (prototype->IsNull(isolate)) { | |
229 map = isolate->slow_object_with_null_prototype_map(); | |
230 } else if (prototype->IsJSObject()) { | |
231 Handle<JSObject> js_prototype = Handle<JSObject>::cast(prototype); | |
232 if (!js_prototype->map()->is_prototype_map()) { | |
233 JSObject::OptimizeAsPrototype(js_prototype, FAST_PROTOTYPE); | |
234 } | |
235 Handle<PrototypeInfo> info = | |
236 Map::GetOrCreatePrototypeInfo(js_prototype, isolate); | |
237 // TODO(verwaest): Use inobject slack tracking for this map. | |
238 if (info->HasObjectCreateMap()) { | |
239 map = handle(info->ObjectCreateMap(), isolate); | |
240 } else { | |
241 map = Map::CopyInitialMap(map); | |
242 Map::SetPrototype(map, prototype, FAST_PROTOTYPE); | |
243 PrototypeInfo::SetObjectCreateMap(info, map); | |
244 } | |
245 } else { | |
246 map = Map::TransitionToPrototype(map, prototype, REGULAR_PROTOTYPE); | |
247 } | |
248 } | |
249 | 227 |
250 bool is_dictionary_map = map->is_dictionary_map(); | 228 bool is_dictionary_map = map->is_dictionary_map(); |
251 Handle<FixedArray> object_properties; | 229 Handle<FixedArray> object_properties; |
252 if (is_dictionary_map) { | 230 if (is_dictionary_map) { |
253 // Allocate the actual properties dictionay up front to avoid invalid object | 231 // Allocate the actual properties dictionay up front to avoid invalid object |
254 // state. | 232 // state. |
255 object_properties = | 233 object_properties = |
256 NameDictionary::New(isolate, NameDictionary::kInitialCapacity); | 234 NameDictionary::New(isolate, NameDictionary::kInitialCapacity); |
257 } | 235 } |
258 // Actually allocate the object. | 236 // Actually allocate the object. |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 if (!success) return isolate->heap()->exception(); | 941 if (!success) return isolate->heap()->exception(); |
964 MAYBE_RETURN( | 942 MAYBE_RETURN( |
965 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), | 943 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), |
966 isolate->heap()->exception()); | 944 isolate->heap()->exception()); |
967 return *value; | 945 return *value; |
968 } | 946 } |
969 | 947 |
970 | 948 |
971 } // namespace internal | 949 } // namespace internal |
972 } // namespace v8 | 950 } // namespace v8 |
OLD | NEW |