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 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Object* Runtime_NewObjectHelper(Isolate* isolate, | 1010 static Object* Runtime_NewObjectHelper(Isolate* isolate, |
1011 Handle<JSFunction> constructor, | 1011 Handle<JSFunction> constructor, |
1012 Handle<JSReceiver> new_target, | 1012 Handle<JSReceiver> new_target, |
1013 Handle<AllocationSite> site) { | 1013 Handle<AllocationSite> site) { |
| 1014 DCHECK(constructor->IsConstructor()); |
| 1015 |
| 1016 // If called through new, new.target can be: |
| 1017 // - a subclass of constructor, |
| 1018 // - a proxy wrapper around constructor, or |
| 1019 // - the constructor itself. |
| 1020 // If called through Reflect.construct, it's guaranteed to be a constructor by |
| 1021 // REFLECT_CONSTRUCT_PREPARE. |
| 1022 DCHECK(new_target->IsConstructor()); |
| 1023 |
1014 DCHECK(!constructor->has_initial_map() || | 1024 DCHECK(!constructor->has_initial_map() || |
1015 constructor->initial_map()->instance_type() != JS_FUNCTION_TYPE); | 1025 constructor->initial_map()->instance_type() != JS_FUNCTION_TYPE); |
1016 | 1026 |
1017 Handle<Map> initial_map; | 1027 Handle<Map> initial_map; |
1018 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1028 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1019 isolate, initial_map, | 1029 isolate, initial_map, |
1020 JSFunction::GetDerivedMap(isolate, constructor, new_target)); | 1030 JSFunction::GetDerivedMap(isolate, constructor, new_target)); |
1021 | 1031 |
1022 Handle<JSObject> result = | 1032 Handle<JSObject> result = |
1023 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site); | 1033 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site); |
1024 | 1034 |
1025 isolate->counters()->constructed_objects()->Increment(); | 1035 isolate->counters()->constructed_objects()->Increment(); |
1026 isolate->counters()->constructed_objects_runtime()->Increment(); | 1036 isolate->counters()->constructed_objects_runtime()->Increment(); |
1027 | 1037 |
1028 return *result; | 1038 return *result; |
1029 } | 1039 } |
1030 | 1040 |
1031 | 1041 |
1032 RUNTIME_FUNCTION(Runtime_NewObject) { | 1042 RUNTIME_FUNCTION(Runtime_NewObject) { |
1033 HandleScope scope(isolate); | 1043 HandleScope scope(isolate); |
1034 DCHECK(args.length() == 2); | 1044 DCHECK(args.length() == 2); |
1035 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0); | 1045 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0); |
1036 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, new_target, 1); | 1046 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, new_target, 1); |
1037 | 1047 |
1038 DCHECK(constructor->IsConstructor()); | |
1039 | |
1040 // If called through new, new.target can be: | |
1041 // - a subclass of constructor, | |
1042 // - a proxy wrapper around constructor, or | |
1043 // - the constructor itself. | |
1044 // If called through Reflect.construct, it's guaranteed to be a constructor by | |
1045 // REFLECT_CONSTRUCT_PREPARE. | |
1046 DCHECK(new_target->IsConstructor()); | |
1047 | |
1048 return Runtime_NewObjectHelper(isolate, constructor, new_target, | 1048 return Runtime_NewObjectHelper(isolate, constructor, new_target, |
1049 Handle<AllocationSite>::null()); | 1049 Handle<AllocationSite>::null()); |
1050 } | 1050 } |
1051 | 1051 |
1052 | 1052 |
1053 RUNTIME_FUNCTION(Runtime_FinalizeInstanceSize) { | 1053 RUNTIME_FUNCTION(Runtime_FinalizeInstanceSize) { |
1054 HandleScope scope(isolate); | 1054 HandleScope scope(isolate); |
1055 DCHECK(args.length() == 1); | 1055 DCHECK(args.length() == 1); |
1056 | 1056 |
1057 CONVERT_ARG_HANDLE_CHECKED(Map, initial_map, 0); | 1057 CONVERT_ARG_HANDLE_CHECKED(Map, initial_map, 0); |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1574 | 1574 |
1575 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { | 1575 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { |
1576 HandleScope scope(isolate); | 1576 HandleScope scope(isolate); |
1577 DCHECK(args.length() == 2); | 1577 DCHECK(args.length() == 2); |
1578 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); | 1578 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); |
1579 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); | 1579 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); |
1580 return JSReceiver::DefineProperties(isolate, o, properties); | 1580 return JSReceiver::DefineProperties(isolate, o, properties); |
1581 } | 1581 } |
1582 } // namespace internal | 1582 } // namespace internal |
1583 } // namespace v8 | 1583 } // namespace v8 |
OLD | NEW |