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

Side by Side Diff: src/runtime/runtime-object.cc

Issue 1481613003: [Proxies] Support constructable proxy as new.target (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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/objects.cc ('k') | test/mjsunit/es6/classes-proxy.js » ('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 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 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 } 1000 }
1001 1001
1002 1002
1003 RUNTIME_FUNCTION(Runtime_AllocateHeapNumber) { 1003 RUNTIME_FUNCTION(Runtime_AllocateHeapNumber) {
1004 HandleScope scope(isolate); 1004 HandleScope scope(isolate);
1005 DCHECK(args.length() == 0); 1005 DCHECK(args.length() == 0);
1006 return *isolate->factory()->NewHeapNumber(0); 1006 return *isolate->factory()->NewHeapNumber(0);
1007 } 1007 }
1008 1008
1009 1009
1010 static MaybeHandle<Map> GetDerivedMap(Isolate* isolate,
1011 Handle<JSFunction> constructor,
1012 Handle<JSReceiver> new_target) {
1013 JSFunction::EnsureHasInitialMap(constructor);
1014 DCHECK_NE(JS_FUNCTION_TYPE, constructor->initial_map()->instance_type());
1015
1016 if (new_target->IsJSProxy()) {
1017 Handle<JSProxy> new_target_proxy = Handle<JSProxy>::cast(new_target);
1018 Handle<Object> prototype;
1019 Handle<String> prototype_string = isolate->factory()->prototype_string();
1020 ASSIGN_RETURN_ON_EXCEPTION(
1021 isolate, prototype,
1022 JSReceiver::GetProperty(new_target_proxy, prototype_string), Map);
1023 Handle<Map> constructor_initial_map(constructor->initial_map());
1024 Handle<Map> map = Map::CopyInitialMap(constructor_initial_map);
1025
1026 if (!prototype->IsJSReceiver()) {
1027 Handle<Context> context;
1028 ASSIGN_RETURN_ON_EXCEPTION(
1029 isolate, context, JSProxy::GetFunctionRealm(new_target_proxy), Map);
1030 DCHECK(context->IsNativeContext());
1031 // TODO(verwaest): Use the intrinsicDefaultProto instead.
1032 prototype = handle(context->initial_object_prototype(), isolate);
1033 }
1034
1035 if (map->prototype() != *prototype) {
1036 Map::SetPrototype(map, prototype, FAST_PROTOTYPE);
1037 }
1038
1039 map->SetConstructor(*constructor);
1040 return map;
1041 }
1042
1043 return JSFunction::EnsureDerivedHasInitialMap(
1044 Handle<JSFunction>::cast(new_target), constructor);
1045 }
1046
1047
1010 static Object* Runtime_NewObjectHelper(Isolate* isolate, 1048 static Object* Runtime_NewObjectHelper(Isolate* isolate,
1011 Handle<JSFunction> constructor, 1049 Handle<JSFunction> constructor,
1012 Handle<JSReceiver> new_target, 1050 Handle<JSReceiver> new_target,
1013 Handle<AllocationSite> site) { 1051 Handle<AllocationSite> site) {
1014 // TODO(verwaest): new_target could be a proxy. Read new.target.prototype in 1052 // The constructor should be compiled for the optimization hints to be
1015 // that case.
1016 Handle<JSFunction> original_function = Handle<JSFunction>::cast(new_target);
1017
1018 // The function should be compiled for the optimization hints to be
1019 // available. 1053 // available.
1020 Compiler::Compile(constructor, CLEAR_EXCEPTION); 1054 Compiler::Compile(constructor, CLEAR_EXCEPTION);
1021 1055
1022 JSFunction::EnsureHasInitialMap(constructor); 1056 Handle<Map> initial_map;
1023 DCHECK_NE(JS_FUNCTION_TYPE, constructor->initial_map()->instance_type()); 1057 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1024 1058 isolate, initial_map, GetDerivedMap(isolate, constructor, new_target));
1025 // TODO(verwaest): original_function could have non-instance-prototype
1026 // (non-JSReceiver), requiring fallback to the intrinsicDefaultProto.
1027 Handle<Map> initial_map =
1028 JSFunction::EnsureDerivedHasInitialMap(original_function, constructor);
1029 1059
1030 Handle<JSObject> result = 1060 Handle<JSObject> result =
1031 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site); 1061 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site);
1032 1062
1033 isolate->counters()->constructed_objects()->Increment(); 1063 isolate->counters()->constructed_objects()->Increment();
1034 isolate->counters()->constructed_objects_runtime()->Increment(); 1064 isolate->counters()->constructed_objects_runtime()->Increment();
1035 1065
1036 return *result; 1066 return *result;
1037 } 1067 }
1038 1068
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
1582 1612
1583 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { 1613 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) {
1584 HandleScope scope(isolate); 1614 HandleScope scope(isolate);
1585 DCHECK(args.length() == 2); 1615 DCHECK(args.length() == 2);
1586 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); 1616 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0);
1587 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); 1617 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1);
1588 return JSReceiver::DefineProperties(isolate, o, properties); 1618 return JSReceiver::DefineProperties(isolate, o, properties);
1589 } 1619 }
1590 } // namespace internal 1620 } // namespace internal
1591 } // namespace v8 1621 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | test/mjsunit/es6/classes-proxy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698