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 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1026 // Check that function is a constructor. | 1026 // Check that function is a constructor. |
1027 if (!function->IsConstructor()) { | 1027 if (!function->IsConstructor()) { |
1028 THROW_NEW_ERROR_RETURN_FAILURE( | 1028 THROW_NEW_ERROR_RETURN_FAILURE( |
1029 isolate, NewTypeError(MessageTemplate::kNotConstructor, constructor)); | 1029 isolate, NewTypeError(MessageTemplate::kNotConstructor, constructor)); |
1030 } | 1030 } |
1031 | 1031 |
1032 Debug* debug = isolate->debug(); | 1032 Debug* debug = isolate->debug(); |
1033 // Handle stepping into constructors if step into is active. | 1033 // Handle stepping into constructors if step into is active. |
1034 if (debug->StepInActive()) debug->HandleStepIn(function, true); | 1034 if (debug->StepInActive()) debug->HandleStepIn(function, true); |
1035 | 1035 |
1036 if (function->has_initial_map()) { | 1036 if (original_function->has_initial_map()) { |
1037 if (function->initial_map()->instance_type() == JS_FUNCTION_TYPE) { | 1037 if (original_function->initial_map()->instance_type() == JS_FUNCTION_TYPE) { |
1038 // The 'Function' function ignores the receiver object when | 1038 // The 'Function' function ignores the receiver object when |
1039 // called using 'new' and creates a new JSFunction object that | 1039 // called using 'new' and creates a new JSFunction object that |
1040 // is returned. The receiver object is only used for error | 1040 // is returned. The receiver object is only used for error |
1041 // reporting if an error occurs when constructing the new | 1041 // reporting if an error occurs when constructing the new |
1042 // JSFunction. Factory::NewJSObject() should not be used to | 1042 // JSFunction. Factory::NewJSObject() should not be used to |
1043 // allocate JSFunctions since it does not properly initialize | 1043 // allocate JSFunctions since it does not properly initialize |
1044 // the shared part of the function. Since the receiver is | 1044 // the shared part of the function. Since the receiver is |
1045 // ignored anyway, we use the global object as the receiver | 1045 // ignored anyway, we use the global object as the receiver |
1046 // instead of a new JSFunction object. This way, errors are | 1046 // instead of a new JSFunction object. This way, errors are |
1047 // reported the same way whether or not 'Function' is called | 1047 // reported the same way whether or not 'Function' is called |
1048 // using 'new'. | 1048 // using 'new'. |
1049 return isolate->global_proxy(); | 1049 return isolate->global_proxy(); |
Toon Verwaest
2015/10/26 15:10:57
The comment above seems out-of-date. We can probab
Igor Sheludko
2015/10/27 12:56:12
I'll address function subclassing in a separate CL
| |
1050 } | 1050 } |
1051 } | 1051 } |
1052 | 1052 |
1053 // The function should be compiled for the optimization hints to be | 1053 // The function should be compiled for the optimization hints to be |
1054 // available. | 1054 // available. |
1055 Compiler::Compile(function, CLEAR_EXCEPTION); | 1055 Compiler::Compile(function, CLEAR_EXCEPTION); |
1056 | 1056 |
1057 Handle<JSObject> result; | 1057 JSFunction::EnsureHasInitialMap(function); |
1058 if (site.is_null()) { | 1058 Handle<Map> initial_map = |
1059 result = isolate->factory()->NewJSObject(function); | 1059 JSFunction::EnsureDerivedHasInitialMap(original_function, function); |
1060 } else { | |
1061 result = isolate->factory()->NewJSObjectWithMemento(function, site); | |
1062 } | |
1063 | 1060 |
1064 // Set up the prototoype using original function. | 1061 Handle<JSObject> result = |
1065 // TODO(dslomov): instead of setting the __proto__, | 1062 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site); |
1066 // use and cache the correct map. | |
1067 if (*original_function != *function) { | |
1068 if (original_function->has_instance_prototype()) { | |
1069 Handle<Object> prototype = | |
1070 handle(original_function->instance_prototype(), isolate); | |
1071 RETURN_FAILURE_ON_EXCEPTION( | |
1072 isolate, JSObject::SetPrototype(result, prototype, false)); | |
1073 } | |
1074 } | |
1075 | 1063 |
1076 isolate->counters()->constructed_objects()->Increment(); | 1064 isolate->counters()->constructed_objects()->Increment(); |
1077 isolate->counters()->constructed_objects_runtime()->Increment(); | 1065 isolate->counters()->constructed_objects_runtime()->Increment(); |
1078 | 1066 |
1079 return *result; | 1067 return *result; |
1080 } | 1068 } |
1081 | 1069 |
1082 | 1070 |
1083 RUNTIME_FUNCTION(Runtime_NewObject) { | 1071 RUNTIME_FUNCTION(Runtime_NewObject) { |
1084 HandleScope scope(isolate); | 1072 HandleScope scope(isolate); |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1614 | 1602 |
1615 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { | 1603 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { |
1616 HandleScope scope(isolate); | 1604 HandleScope scope(isolate); |
1617 DCHECK(args.length() == 2); | 1605 DCHECK(args.length() == 2); |
1618 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); | 1606 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); |
1619 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); | 1607 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); |
1620 return JSReceiver::DefineProperties(isolate, o, properties); | 1608 return JSReceiver::DefineProperties(isolate, o, properties); |
1621 } | 1609 } |
1622 } // namespace internal | 1610 } // namespace internal |
1623 } // namespace v8 | 1611 } // namespace v8 |
OLD | NEW |