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

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

Issue 1442643009: Rename original constructor to new target (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase 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-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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_CompleteFunctionConstruction) { 50 RUNTIME_FUNCTION(Runtime_CompleteFunctionConstruction) {
51 SealHandleScope shs(isolate); 51 SealHandleScope shs(isolate);
52 DCHECK(args.length() == 3); 52 DCHECK(args.length() == 3);
53 CONVERT_ARG_HANDLE_CHECKED(JSFunction, func, 0); 53 CONVERT_ARG_HANDLE_CHECKED(JSFunction, func, 0);
54 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 1); 54 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 1);
55 CONVERT_ARG_HANDLE_CHECKED(Object, new_target, 2); 55 CONVERT_ARG_HANDLE_CHECKED(Object, unchecked_new_target, 2);
56 func->shared()->set_name_should_print_as_anonymous(true); 56 func->shared()->set_name_should_print_as_anonymous(true);
57 57
58 // If new.target is equal to |constructor| then the function |func| created 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. 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 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| 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 62 // has wrong initial map. To fix that we create a new function object with
63 // correct initial map. 63 // correct initial map.
64 if (new_target->IsUndefined() || *constructor == *new_target) { 64 if (unchecked_new_target->IsUndefined() ||
65 *constructor == *unchecked_new_target) {
65 return *func; 66 return *func;
66 } 67 }
67 68
68 // Create a new JSFunction object with correct initial map. 69 // Create a new JSFunction object with correct initial map.
69 HandleScope handle_scope(isolate); 70 HandleScope handle_scope(isolate);
70 Handle<JSFunction> original_constructor = 71 Handle<JSFunction> new_target =
71 Handle<JSFunction>::cast(new_target); 72 Handle<JSFunction>::cast(unchecked_new_target);
72 73
73 DCHECK(constructor->has_initial_map()); 74 DCHECK(constructor->has_initial_map());
74 Handle<Map> initial_map = 75 Handle<Map> initial_map =
75 JSFunction::EnsureDerivedHasInitialMap(original_constructor, constructor); 76 JSFunction::EnsureDerivedHasInitialMap(new_target, constructor);
76 77
77 Handle<SharedFunctionInfo> shared_info(func->shared(), isolate); 78 Handle<SharedFunctionInfo> shared_info(func->shared(), isolate);
78 Handle<Context> context(func->context(), isolate); 79 Handle<Context> context(func->context(), isolate);
79 Handle<JSFunction> result = 80 Handle<JSFunction> result =
80 isolate->factory()->NewFunctionFromSharedFunctionInfo( 81 isolate->factory()->NewFunctionFromSharedFunctionInfo(
81 initial_map, shared_info, context, NOT_TENURED); 82 initial_map, shared_info, context, NOT_TENURED);
82 DCHECK_EQ(func->IsConstructor(), result->IsConstructor()); 83 DCHECK_EQ(func->IsConstructor(), result->IsConstructor());
83 return *result; 84 return *result;
84 } 85 }
85 86
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 637
637 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { 638 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) {
638 HandleScope scope(isolate); 639 HandleScope scope(isolate);
639 DCHECK(args.length() == 0); 640 DCHECK(args.length() == 0);
640 THROW_NEW_ERROR_RETURN_FAILURE(isolate, 641 THROW_NEW_ERROR_RETURN_FAILURE(isolate,
641 NewTypeError(MessageTemplate::kStrongArity)); 642 NewTypeError(MessageTemplate::kStrongArity));
642 } 643 }
643 644
644 } // namespace internal 645 } // namespace internal
645 } // namespace v8 646 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-classes.cc ('k') | src/runtime/runtime-object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698