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/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 RUNTIME_FUNCTION(Runtime_FunctionNameShouldPrintAsAnonymous) { | 41 RUNTIME_FUNCTION(Runtime_FunctionNameShouldPrintAsAnonymous) { |
42 SealHandleScope shs(isolate); | 42 SealHandleScope shs(isolate); |
43 DCHECK(args.length() == 1); | 43 DCHECK(args.length() == 1); |
44 CONVERT_ARG_CHECKED(JSFunction, f, 0); | 44 CONVERT_ARG_CHECKED(JSFunction, f, 0); |
45 return isolate->heap()->ToBoolean( | 45 return isolate->heap()->ToBoolean( |
46 f->shared()->name_should_print_as_anonymous()); | 46 f->shared()->name_should_print_as_anonymous()); |
47 } | 47 } |
48 | 48 |
49 | 49 |
50 RUNTIME_FUNCTION(Runtime_FunctionMarkNameShouldPrintAsAnonymous) { | 50 RUNTIME_FUNCTION(Runtime_CompleteFunctionConstruction) { |
51 SealHandleScope shs(isolate); | 51 SealHandleScope shs(isolate); |
52 DCHECK(args.length() == 1); | 52 DCHECK(args.length() == 3); |
53 CONVERT_ARG_CHECKED(JSFunction, f, 0); | 53 CONVERT_ARG_HANDLE_CHECKED(JSFunction, func, 0); |
54 f->shared()->set_name_should_print_as_anonymous(true); | 54 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 1); |
55 return isolate->heap()->undefined_value(); | 55 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, 2); |
| 56 func->shared()->set_name_should_print_as_anonymous(true); |
| 57 |
| 58 // If new.target is equal to |constructor| then the function |func| created |
| 59 // is already correctly setup and nothing else should be done here. |
| 60 // But if new.target is not equal to |constructor| then we are have a |
| 61 // Function builtin subclassing case and therefore the function |func| |
| 62 // has wrong initial map. To fix that we create a new function object with |
| 63 // correct initial map. |
| 64 if (new_target->IsUndefined() || *constructor == *new_target) { |
| 65 return *func; |
| 66 } |
| 67 |
| 68 // Create a new JSFunction object with correct initial map. |
| 69 HandleScope handle_scope(isolate); |
| 70 Handle<JSFunction> original_constructor = |
| 71 Handle<JSFunction>::cast(new_target); |
| 72 |
| 73 DCHECK(constructor->has_initial_map()); |
| 74 Handle<Map> initial_map = |
| 75 JSFunction::EnsureDerivedHasInitialMap(original_constructor, constructor); |
| 76 |
| 77 Handle<SharedFunctionInfo> shared_info(func->shared(), isolate); |
| 78 Handle<Context> context(func->context(), isolate); |
| 79 Handle<JSFunction> result = |
| 80 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 81 initial_map, shared_info, context, NOT_TENURED); |
| 82 DCHECK_EQ(func->IsConstructor(), result->IsConstructor()); |
| 83 return *result; |
56 } | 84 } |
57 | 85 |
58 | 86 |
59 RUNTIME_FUNCTION(Runtime_FunctionIsArrow) { | 87 RUNTIME_FUNCTION(Runtime_FunctionIsArrow) { |
60 SealHandleScope shs(isolate); | 88 SealHandleScope shs(isolate); |
61 DCHECK(args.length() == 1); | 89 DCHECK(args.length() == 1); |
62 CONVERT_ARG_CHECKED(JSFunction, f, 0); | 90 CONVERT_ARG_CHECKED(JSFunction, f, 0); |
63 return isolate->heap()->ToBoolean(f->shared()->is_arrow()); | 91 return isolate->heap()->ToBoolean(f->shared()->is_arrow()); |
64 } | 92 } |
65 | 93 |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 626 |
599 | 627 |
600 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { | 628 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { |
601 HandleScope scope(isolate); | 629 HandleScope scope(isolate); |
602 DCHECK(args.length() == 0); | 630 DCHECK(args.length() == 0); |
603 THROW_NEW_ERROR_RETURN_FAILURE(isolate, | 631 THROW_NEW_ERROR_RETURN_FAILURE(isolate, |
604 NewTypeError(MessageTemplate::kStrongArity)); | 632 NewTypeError(MessageTemplate::kStrongArity)); |
605 } | 633 } |
606 } // namespace internal | 634 } // namespace internal |
607 } // namespace v8 | 635 } // namespace v8 |
OLD | NEW |