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

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

Issue 1415683007: Reland "[es6] Fix Function and GeneratorFunction built-ins subclassing." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@fix-subclass
Patch Set: Improved test 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.h ('k') | src/runtime/runtime-object.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/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
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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 638
611 639
612 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { 640 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) {
613 HandleScope scope(isolate); 641 HandleScope scope(isolate);
614 DCHECK(args.length() == 0); 642 DCHECK(args.length() == 0);
615 THROW_NEW_ERROR_RETURN_FAILURE(isolate, 643 THROW_NEW_ERROR_RETURN_FAILURE(isolate,
616 NewTypeError(MessageTemplate::kStrongArity)); 644 NewTypeError(MessageTemplate::kStrongArity));
617 } 645 }
618 } // namespace internal 646 } // namespace internal
619 } // namespace v8 647 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/runtime/runtime-object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698