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 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | |
1048 static Object* Runtime_NewObjectHelper(Isolate* isolate, | 1010 static Object* Runtime_NewObjectHelper(Isolate* isolate, |
1049 Handle<JSFunction> constructor, | 1011 Handle<JSFunction> constructor, |
1050 Handle<JSReceiver> new_target, | 1012 Handle<JSReceiver> new_target, |
1051 Handle<AllocationSite> site) { | 1013 Handle<AllocationSite> site) { |
1052 // The constructor should be compiled for the optimization hints to be | 1014 // TODO(verwaest): new_target could be a proxy. Read new.target.prototype in |
| 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 |
1053 // available. | 1019 // available. |
1054 Compiler::Compile(constructor, CLEAR_EXCEPTION); | 1020 Compiler::Compile(constructor, CLEAR_EXCEPTION); |
1055 | 1021 |
1056 Handle<Map> initial_map; | 1022 JSFunction::EnsureHasInitialMap(constructor); |
1057 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1023 DCHECK_NE(JS_FUNCTION_TYPE, constructor->initial_map()->instance_type()); |
1058 isolate, initial_map, GetDerivedMap(isolate, constructor, new_target)); | 1024 |
| 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); |
1059 | 1029 |
1060 Handle<JSObject> result = | 1030 Handle<JSObject> result = |
1061 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site); | 1031 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site); |
1062 | 1032 |
1063 isolate->counters()->constructed_objects()->Increment(); | 1033 isolate->counters()->constructed_objects()->Increment(); |
1064 isolate->counters()->constructed_objects_runtime()->Increment(); | 1034 isolate->counters()->constructed_objects_runtime()->Increment(); |
1065 | 1035 |
1066 return *result; | 1036 return *result; |
1067 } | 1037 } |
1068 | 1038 |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1612 | 1582 |
1613 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { | 1583 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { |
1614 HandleScope scope(isolate); | 1584 HandleScope scope(isolate); |
1615 DCHECK(args.length() == 2); | 1585 DCHECK(args.length() == 2); |
1616 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); | 1586 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); |
1617 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); | 1587 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); |
1618 return JSReceiver::DefineProperties(isolate, o, properties); | 1588 return JSReceiver::DefineProperties(isolate, o, properties); |
1619 } | 1589 } |
1620 } // namespace internal | 1590 } // namespace internal |
1621 } // namespace v8 | 1591 } // namespace v8 |
OLD | NEW |