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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(isolate->native_context()->object_function()->initial_map(), |
226 isolate); | 226 isolate); |
227 if (map->prototype() != *prototype) { | 227 if (map->prototype() != *prototype) { |
228 if (prototype->IsNull(isolate)) { | 228 if (prototype->IsNull(isolate)) { |
229 map = isolate->object_with_null_prototype_map(); | 229 map = isolate->slow_object_with_null_prototype_map(); |
230 } else if (prototype->IsJSObject()) { | 230 } else if (prototype->IsJSObject()) { |
231 Handle<JSObject> js_prototype = Handle<JSObject>::cast(prototype); | 231 Handle<JSObject> js_prototype = Handle<JSObject>::cast(prototype); |
232 if (!js_prototype->map()->is_prototype_map()) { | 232 if (!js_prototype->map()->is_prototype_map()) { |
233 JSObject::OptimizeAsPrototype(js_prototype, FAST_PROTOTYPE); | 233 JSObject::OptimizeAsPrototype(js_prototype, FAST_PROTOTYPE); |
234 } | 234 } |
235 Handle<PrototypeInfo> info = | 235 Handle<PrototypeInfo> info = |
236 Map::GetOrCreatePrototypeInfo(js_prototype, isolate); | 236 Map::GetOrCreatePrototypeInfo(js_prototype, isolate); |
237 // TODO(verwaest): Use inobject slack tracking for this map. | 237 // TODO(verwaest): Use inobject slack tracking for this map. |
238 if (info->HasObjectCreateMap()) { | 238 if (info->HasObjectCreateMap()) { |
239 map = handle(info->ObjectCreateMap(), isolate); | 239 map = handle(info->ObjectCreateMap(), isolate); |
240 } else { | 240 } else { |
241 map = Map::CopyInitialMap(map); | 241 map = Map::CopyInitialMap(map); |
242 Map::SetPrototype(map, prototype, FAST_PROTOTYPE); | 242 Map::SetPrototype(map, prototype, FAST_PROTOTYPE); |
243 PrototypeInfo::SetObjectCreateMap(info, map); | 243 PrototypeInfo::SetObjectCreateMap(info, map); |
244 } | 244 } |
245 } else { | 245 } else { |
246 map = Map::TransitionToPrototype(map, prototype, REGULAR_PROTOTYPE); | 246 map = Map::TransitionToPrototype(map, prototype, REGULAR_PROTOTYPE); |
247 } | 247 } |
248 } | 248 } |
249 | 249 |
250 // Actually allocate the object. | 250 // Actually allocate the object. |
251 Handle<JSObject> object = isolate->factory()->NewJSObjectFromMap(map); | 251 Handle<JSObject> object = isolate->factory()->NewJSObjectFromMap(map); |
252 | 252 |
| 253 if (map->is_dictionary_map()) { |
| 254 Handle<NameDictionary> properties = |
| 255 NameDictionary::New(isolate, NameDictionary::kInitialCapacity); |
| 256 object->set_properties(*properties); |
| 257 } |
| 258 |
253 // Define the properties if properties was specified and is not undefined. | 259 // Define the properties if properties was specified and is not undefined. |
254 Handle<Object> properties = args.at<Object>(1); | 260 Handle<Object> properties = args.at<Object>(1); |
255 if (!properties->IsUndefined(isolate)) { | 261 if (!properties->IsUndefined(isolate)) { |
256 RETURN_FAILURE_ON_EXCEPTION( | 262 RETURN_FAILURE_ON_EXCEPTION( |
257 isolate, JSReceiver::DefineProperties(isolate, object, properties)); | 263 isolate, JSReceiver::DefineProperties(isolate, object, properties)); |
258 } | 264 } |
259 | 265 |
260 return *object; | 266 return *object; |
261 } | 267 } |
262 | 268 |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 if (!success) return isolate->heap()->exception(); | 941 if (!success) return isolate->heap()->exception(); |
936 MAYBE_RETURN( | 942 MAYBE_RETURN( |
937 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), | 943 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), |
938 isolate->heap()->exception()); | 944 isolate->heap()->exception()); |
939 return *value; | 945 return *value; |
940 } | 946 } |
941 | 947 |
942 | 948 |
943 } // namespace internal | 949 } // namespace internal |
944 } // namespace v8 | 950 } // namespace v8 |
OLD | NEW |