Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: src/builtins.cc

Issue 2083353002: Cache Object.create maps on the passed prototype's PrototypeInfo (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: properly set prototype Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/bootstrapper.cc ('k') | src/contexts.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/builtins.h" 5 #include "src/builtins.h"
6 6
7 #include "src/api-arguments.h" 7 #include "src/api-arguments.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/base/ieee754.h" 10 #include "src/base/ieee754.h"
(...skipping 1600 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 prop_value, STRICT)); 1611 prop_value, STRICT));
1612 } 1612 }
1613 } 1613 }
1614 } 1614 }
1615 // 5. Return to. 1615 // 5. Return to.
1616 return *to; 1616 return *to;
1617 } 1617 }
1618 1618
1619 1619
1620 // ES6 section 19.1.2.2 Object.create ( O [ , Properties ] ) 1620 // ES6 section 19.1.2.2 Object.create ( O [ , Properties ] )
1621 // TODO(verwaest): Support the common cases with precached map directly in
1622 // an Object.create stub.
1621 BUILTIN(ObjectCreate) { 1623 BUILTIN(ObjectCreate) {
1622 HandleScope scope(isolate); 1624 HandleScope scope(isolate);
1623 Handle<Object> prototype = args.atOrUndefined(isolate, 1); 1625 Handle<Object> prototype = args.atOrUndefined(isolate, 1);
1624 if (!prototype->IsNull(isolate) && !prototype->IsJSReceiver()) { 1626 if (!prototype->IsNull(isolate) && !prototype->IsJSReceiver()) {
1625 THROW_NEW_ERROR_RETURN_FAILURE( 1627 THROW_NEW_ERROR_RETURN_FAILURE(
1626 isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, prototype)); 1628 isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, prototype));
1627 } 1629 }
1628 1630
1629 // Generate the map with the specified {prototype} based on the Object 1631 // Generate the map with the specified {prototype} based on the Object
1630 // function's initial map from the current native context. 1632 // function's initial map from the current native context.
1631 // TODO(bmeurer): Use a dedicated cache for Object.create; think about 1633 // TODO(bmeurer): Use a dedicated cache for Object.create; think about
1632 // slack tracking for Object.create. 1634 // slack tracking for Object.create.
1633 Handle<Map> map(isolate->native_context()->object_function()->initial_map(), 1635 Handle<Map> map(isolate->native_context()->object_function()->initial_map(),
1634 isolate); 1636 isolate);
1635 if (map->prototype() != *prototype) { 1637 if (map->prototype() != *prototype) {
1636 map = Map::TransitionToPrototype(map, prototype, FAST_PROTOTYPE); 1638 if (prototype->IsNull(isolate)) {
1639 map = isolate->object_with_null_prototype_map();
1640 } else if (prototype->IsJSObject()) {
1641 Handle<JSObject> js_prototype = Handle<JSObject>::cast(prototype);
1642 if (!js_prototype->map()->is_prototype_map()) {
1643 JSObject::OptimizeAsPrototype(js_prototype, FAST_PROTOTYPE);
1644 }
1645 Handle<PrototypeInfo> info =
1646 Map::GetOrCreatePrototypeInfo(js_prototype, isolate);
1647 // TODO(verwaest): Use inobject slack tracking for this map.
1648 if (info->HasObjectCreateMap()) {
1649 map = handle(info->ObjectCreateMap(), isolate);
1650 } else {
1651 map = Map::CopyInitialMap(map);
1652 Map::SetPrototype(map, prototype, FAST_PROTOTYPE);
1653 PrototypeInfo::SetObjectCreateMap(info, map);
1654 }
1655 } else {
1656 map = Map::TransitionToPrototype(map, prototype, REGULAR_PROTOTYPE);
1657 }
1637 } 1658 }
1638 1659
1639 // Actually allocate the object. 1660 // Actually allocate the object.
1640 Handle<JSObject> object = isolate->factory()->NewJSObjectFromMap(map); 1661 Handle<JSObject> object = isolate->factory()->NewJSObjectFromMap(map);
1641 1662
1642 // Define the properties if properties was specified and is not undefined. 1663 // Define the properties if properties was specified and is not undefined.
1643 Handle<Object> properties = args.atOrUndefined(isolate, 2); 1664 Handle<Object> properties = args.atOrUndefined(isolate, 2);
1644 if (!properties->IsUndefined(isolate)) { 1665 if (!properties->IsUndefined(isolate)) {
1645 RETURN_FAILURE_ON_EXCEPTION( 1666 RETURN_FAILURE_ON_EXCEPTION(
1646 isolate, JSReceiver::DefineProperties(isolate, object, properties)); 1667 isolate, JSReceiver::DefineProperties(isolate, object, properties));
(...skipping 4461 matching lines...) Expand 10 before | Expand all | Expand 10 after
6108 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 6129 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
6109 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 6130 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
6110 #undef DEFINE_BUILTIN_ACCESSOR_C 6131 #undef DEFINE_BUILTIN_ACCESSOR_C
6111 #undef DEFINE_BUILTIN_ACCESSOR_A 6132 #undef DEFINE_BUILTIN_ACCESSOR_A
6112 #undef DEFINE_BUILTIN_ACCESSOR_T 6133 #undef DEFINE_BUILTIN_ACCESSOR_T
6113 #undef DEFINE_BUILTIN_ACCESSOR_S 6134 #undef DEFINE_BUILTIN_ACCESSOR_S
6114 #undef DEFINE_BUILTIN_ACCESSOR_H 6135 #undef DEFINE_BUILTIN_ACCESSOR_H
6115 6136
6116 } // namespace internal 6137 } // namespace internal
6117 } // namespace v8 6138 } // namespace v8
OLDNEW
« no previous file with comments | « src/bootstrapper.cc ('k') | src/contexts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698