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 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 | 990 |
991 Debug* debug = isolate->debug(); | 991 Debug* debug = isolate->debug(); |
992 // Handle stepping into constructors if step into is active. | 992 // Handle stepping into constructors if step into is active. |
993 if (debug->StepInActive()) debug->HandleStepIn(function, true); | 993 if (debug->StepInActive()) debug->HandleStepIn(function, true); |
994 | 994 |
995 // The function should be compiled for the optimization hints to be | 995 // The function should be compiled for the optimization hints to be |
996 // available. | 996 // available. |
997 Compiler::Compile(function, CLEAR_EXCEPTION); | 997 Compiler::Compile(function, CLEAR_EXCEPTION); |
998 | 998 |
999 JSFunction::EnsureHasInitialMap(function); | 999 JSFunction::EnsureHasInitialMap(function); |
| 1000 if (function->initial_map()->instance_type() == JS_FUNCTION_TYPE) { |
| 1001 // The 'Function' function ignores the receiver object when |
| 1002 // called using 'new' and creates a new JSFunction object that |
| 1003 // is returned. |
| 1004 return isolate->heap()->undefined_value(); |
| 1005 } |
| 1006 |
1000 Handle<Map> initial_map = | 1007 Handle<Map> initial_map = |
1001 JSFunction::EnsureDerivedHasInitialMap(original_function, function); | 1008 JSFunction::EnsureDerivedHasInitialMap(original_function, function); |
1002 | 1009 |
1003 if (initial_map->instance_type() == JS_FUNCTION_TYPE) { | |
1004 // The 'Function' function ignores the receiver object when | |
1005 // called using 'new' and creates a new JSFunction object that | |
1006 // is returned. The receiver object is only used for error | |
1007 // reporting if an error occurs when constructing the new | |
1008 // JSFunction. Factory::NewJSObject() should not be used to | |
1009 // allocate JSFunctions since it does not properly initialize | |
1010 // the shared part of the function. Since the receiver is | |
1011 // ignored anyway, we use the global object as the receiver | |
1012 // instead of a new JSFunction object. This way, errors are | |
1013 // reported the same way whether or not 'Function' is called | |
1014 // using 'new'. | |
1015 return isolate->global_proxy(); | |
1016 } | |
1017 | |
1018 Handle<JSObject> result = | 1010 Handle<JSObject> result = |
1019 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site); | 1011 isolate->factory()->NewJSObjectFromMap(initial_map, NOT_TENURED, site); |
1020 | 1012 |
1021 isolate->counters()->constructed_objects()->Increment(); | 1013 isolate->counters()->constructed_objects()->Increment(); |
1022 isolate->counters()->constructed_objects_runtime()->Increment(); | 1014 isolate->counters()->constructed_objects_runtime()->Increment(); |
1023 | 1015 |
1024 return *result; | 1016 return *result; |
1025 } | 1017 } |
1026 | 1018 |
1027 | 1019 |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1559 | 1551 |
1560 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { | 1552 RUNTIME_FUNCTION(Runtime_ObjectDefineProperties) { |
1561 HandleScope scope(isolate); | 1553 HandleScope scope(isolate); |
1562 DCHECK(args.length() == 2); | 1554 DCHECK(args.length() == 2); |
1563 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); | 1555 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); |
1564 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); | 1556 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); |
1565 return JSReceiver::DefineProperties(isolate, o, properties); | 1557 return JSReceiver::DefineProperties(isolate, o, properties); |
1566 } | 1558 } |
1567 } // namespace internal | 1559 } // namespace internal |
1568 } // namespace v8 | 1560 } // namespace v8 |
OLD | NEW |