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

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

Issue 1484473002: Fix Reflect.construct wrt proxy, generator, and non-subclass new.target (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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-array.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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, unchecked_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 (unchecked_new_target->IsUndefined()) return *func;
59
60 Handle<JSReceiver> new_target =
61 Handle<JSReceiver>::cast(unchecked_new_target);
58 // If new.target is equal to |constructor| then the function |func| created 62 // If new.target is equal to |constructor| then the function |func| created
59 // is already correctly setup and nothing else should be done here. 63 // 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 64 // But if new.target is not equal to |constructor| then we are have a
61 // Function builtin subclassing case and therefore the function |func| 65 // Function builtin subclassing case and therefore the function |func|
62 // has wrong initial map. To fix that we create a new function object with 66 // has wrong initial map. To fix that we create a new function object with
63 // correct initial map. 67 // correct initial map.
64 if (unchecked_new_target->IsUndefined() || 68 if (*constructor == *new_target) return *func;
65 *constructor == *unchecked_new_target) {
66 return *func;
67 }
68 69
69 // Create a new JSFunction object with correct initial map. 70 // Create a new JSFunction object with correct initial map.
70 HandleScope handle_scope(isolate); 71 HandleScope handle_scope(isolate);
71 Handle<JSFunction> new_target =
72 Handle<JSFunction>::cast(unchecked_new_target);
73 72
74 DCHECK(constructor->has_initial_map()); 73 DCHECK(constructor->has_initial_map());
75 Handle<Map> initial_map = 74 Handle<Map> initial_map;
76 JSFunction::EnsureDerivedHasInitialMap(new_target, constructor); 75 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
76 isolate, initial_map,
77 JSFunction::GetDerivedMap(isolate, constructor, new_target));
77 78
78 Handle<SharedFunctionInfo> shared_info(func->shared(), isolate); 79 Handle<SharedFunctionInfo> shared_info(func->shared(), isolate);
79 Handle<Context> context(func->context(), isolate); 80 Handle<Context> context(func->context(), isolate);
80 Handle<JSFunction> result = 81 Handle<JSFunction> result =
81 isolate->factory()->NewFunctionFromSharedFunctionInfo( 82 isolate->factory()->NewFunctionFromSharedFunctionInfo(
82 initial_map, shared_info, context, NOT_TENURED); 83 initial_map, shared_info, context, NOT_TENURED);
83 DCHECK_EQ(func->IsConstructor(), result->IsConstructor()); 84 DCHECK_EQ(func->IsConstructor(), result->IsConstructor());
84 return *result; 85 return *result;
85 } 86 }
86 87
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 623
623 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { 624 RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) {
624 HandleScope scope(isolate); 625 HandleScope scope(isolate);
625 DCHECK(args.length() == 0); 626 DCHECK(args.length() == 0);
626 THROW_NEW_ERROR_RETURN_FAILURE(isolate, 627 THROW_NEW_ERROR_RETURN_FAILURE(isolate,
627 NewTypeError(MessageTemplate::kStrongArity)); 628 NewTypeError(MessageTemplate::kStrongArity));
628 } 629 }
629 630
630 } // namespace internal 631 } // namespace internal
631 } // namespace v8 632 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-array.cc ('k') | src/runtime/runtime-object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698