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

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

Issue 1448933002: Introduce a BuiltinsConstructStub that sets up new.target and does a [[call]] per ES6 9.3.2 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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/runtime/runtime-classes.cc ('k') | src/runtime/runtime-proxy.cc » ('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 RUNTIME_FUNCTION(Runtime_AllocateHeapNumber) { 1002 RUNTIME_FUNCTION(Runtime_AllocateHeapNumber) {
1003 HandleScope scope(isolate); 1003 HandleScope scope(isolate);
1004 DCHECK(args.length() == 0); 1004 DCHECK(args.length() == 0);
1005 return *isolate->factory()->NewHeapNumber(0); 1005 return *isolate->factory()->NewHeapNumber(0);
1006 } 1006 }
1007 1007
1008 1008
1009 static Object* Runtime_NewObjectHelper(Isolate* isolate, 1009 static Object* Runtime_NewObjectHelper(Isolate* isolate,
1010 Handle<Object> constructor, 1010 Handle<JSFunction> constructor,
1011 Handle<Object> new_target, 1011 Handle<JSReceiver> new_target,
1012 Handle<AllocationSite> site) { 1012 Handle<AllocationSite> site) {
1013 // If the constructor isn't a proper function we throw a type error. 1013 // TODO(verwaest): new_target could be a proxy. Read new.target.prototype in
1014 if (!constructor->IsJSFunction()) { 1014 // that case.
1015 THROW_NEW_ERROR_RETURN_FAILURE(
1016 isolate, NewTypeError(MessageTemplate::kNotConstructor, constructor));
1017 }
1018
1019 Handle<JSFunction> function = Handle<JSFunction>::cast(constructor);
1020
1021 CHECK(new_target->IsJSFunction());
1022 Handle<JSFunction> original_function = Handle<JSFunction>::cast(new_target); 1015 Handle<JSFunction> original_function = Handle<JSFunction>::cast(new_target);
1023 1016
1024
1025 // Check that function is a constructor.
1026 if (!function->IsConstructor()) {
1027 THROW_NEW_ERROR_RETURN_FAILURE(
1028 isolate, NewTypeError(MessageTemplate::kNotConstructor, constructor));
1029 }
1030
1031 // The function should be compiled for the optimization hints to be 1017 // The function should be compiled for the optimization hints to be
1032 // available. 1018 // available.
1033 Compiler::Compile(function, CLEAR_EXCEPTION); 1019 Compiler::Compile(constructor, CLEAR_EXCEPTION);
1034 1020
1035 JSFunction::EnsureHasInitialMap(function); 1021 JSFunction::EnsureHasInitialMap(constructor);
1036 if (function->initial_map()->instance_type() == JS_FUNCTION_TYPE) { 1022 DCHECK_NE(JS_FUNCTION_TYPE, constructor->initial_map()->instance_type());
1037 // The 'Function' function ignores the receiver object when
1038 // called using 'new' and creates a new JSFunction object that
1039 // is returned.
1040 return isolate->heap()->undefined_value();
1041 }
1042 1023
1024 // TODO(verwaest): original_function could have non-instance-prototype
1025 // (non-JSReceiver), requiring fallback to the intrinsicDefaultProto.
1043 Handle<Map> initial_map = 1026 Handle<Map> initial_map =
1044 JSFunction::EnsureDerivedHasInitialMap(original_function, function); 1027 JSFunction::EnsureDerivedHasInitialMap(original_function, constructor);
1045 1028
1046 Handle<JSObject> result = 1029 Handle<JSObject> result =
1047 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site); 1030 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site);
1048 1031
1049 isolate->counters()->constructed_objects()->Increment(); 1032 isolate->counters()->constructed_objects()->Increment();
1050 isolate->counters()->constructed_objects_runtime()->Increment(); 1033 isolate->counters()->constructed_objects_runtime()->Increment();
1051 1034
1052 return *result; 1035 return *result;
1053 } 1036 }
1054 1037
1055 1038
1056 RUNTIME_FUNCTION(Runtime_NewObject) { 1039 RUNTIME_FUNCTION(Runtime_NewObject) {
1057 HandleScope scope(isolate); 1040 HandleScope scope(isolate);
1058 DCHECK(args.length() == 2); 1041 DCHECK(args.length() == 2);
1059 CONVERT_ARG_HANDLE_CHECKED(Object, constructor, 0); 1042 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0);
1060 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, 1); 1043 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, new_target, 1);
1044
1045 // TODO(verwaest): Make sure |constructor| is guaranteed to be a constructor.
1046 if (!constructor->IsConstructor()) {
1047 THROW_NEW_ERROR_RETURN_FAILURE(
1048 isolate, NewTypeError(MessageTemplate::kNotConstructor, constructor));
1049 }
1050
1051 // If called through new, new.target can be:
1052 // - a subclass of constructor,
1053 // - a proxy wrapper around constructor, or
1054 // - the constructor itself.
1055 // If called through Reflect.construct, it's guaranteed to be a constructor by
1056 // REFLECT_CONSTRUCT_PREPARE.
1057 DCHECK(new_target->IsConstructor());
1058
1061 return Runtime_NewObjectHelper(isolate, constructor, new_target, 1059 return Runtime_NewObjectHelper(isolate, constructor, new_target,
1062 Handle<AllocationSite>::null()); 1060 Handle<AllocationSite>::null());
1063 } 1061 }
1064 1062
1065 1063
1066 RUNTIME_FUNCTION(Runtime_FinalizeInstanceSize) { 1064 RUNTIME_FUNCTION(Runtime_FinalizeInstanceSize) {
1067 HandleScope scope(isolate); 1065 HandleScope scope(isolate);
1068 DCHECK(args.length() == 1); 1066 DCHECK(args.length() == 1);
1069 1067
1070 CONVERT_ARG_HANDLE_CHECKED(Map, initial_map, 0); 1068 CONVERT_ARG_HANDLE_CHECKED(Map, initial_map, 0);
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 1585
1588 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { 1586 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) {
1589 HandleScope scope(isolate); 1587 HandleScope scope(isolate);
1590 DCHECK(args.length() == 2); 1588 DCHECK(args.length() == 2);
1591 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); 1589 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0);
1592 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); 1590 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1);
1593 return JSReceiver::DefineProperties(isolate, o, properties); 1591 return JSReceiver::DefineProperties(isolate, o, properties);
1594 } 1592 }
1595 } // namespace internal 1593 } // namespace internal
1596 } // namespace v8 1594 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-classes.cc ('k') | src/runtime/runtime-proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698