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

Unified Diff: src/x64/full-codegen-x64.cc

Issue 1191973004: Work In Progress: support new.target (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 months 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 side-by-side diff with in-line comments
Download patch
Index: src/x64/full-codegen-x64.cc
diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc
index 7560117c7307465442b101a125598b10255221dc..b2cd7215ecdb4950f0a5498e0952461ef6bf76f9 100644
--- a/src/x64/full-codegen-x64.cc
+++ b/src/x64/full-codegen-x64.cc
@@ -240,16 +240,39 @@ void FullCodeGenerator::Generate() {
Variable* new_target_var = scope()->new_target_var();
if (new_target_var != nullptr) {
+ // If this is a [[Construct]] then the new.target is passed as the -2
+ // argument. If it is a [[Call]] this is always undefined.
Comment cmnt(masm_, "[ new.target");
+ Label assign, construct, check_frame_marker;
+ __ movp(rax, Operand(rbp, StandardFrameConstants::kCallerFPOffset));
+ __ Cmp(Operand(rax, StandardFrameConstants::kContextOffset),
+ Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
+ __ j(not_equal, &check_frame_marker);
+ __ movp(rax, Operand(rax, StandardFrameConstants::kCallerFPOffset));
+ __ bind(&check_frame_marker);
+ __ Cmp(Operand(rax, StandardFrameConstants::kMarkerOffset),
+ Smi::FromInt(StackFrame::CONSTRUCT));
+ __ j(equal, &construct);
+
+ // [[Call]]
+ __ LoadRoot(rax, Heap::kUndefinedValueRootIndex);
+ __ jmp(&assign);
+
+ // [[Construct]]
+ __ bind(&construct);
+
// new.target is parameter -2.
int offset = 2 * kPointerSize + kFPOnStackSize + kPCOnStackSize +
(info_->scope()->num_parameters() - 1) * kPointerSize;
__ movp(rax, Operand(rbp, offset));
+
+ __ bind(&assign);
SetVar(new_target_var, rax, rbx, rdx);
}
ArgumentsAccessStub::HasNewTarget has_new_target =
- IsSubclassConstructor(info->function()->kind())
+ (info->scope()->new_target_var() != nullptr ||
+ IsSubclassConstructor(info->function()->kind()))
? ArgumentsAccessStub::HAS_NEW_TARGET
: ArgumentsAccessStub::NO_NEW_TARGET;
@@ -465,7 +488,8 @@ void FullCodeGenerator::EmitReturnSequence() {
int no_frame_start = masm_->pc_offset();
int arg_count = info_->scope()->num_parameters() + 1;
- if (IsSubclassConstructor(info_->function()->kind())) {
+ if (info_->scope()->new_target_var() != nullptr ||
+ IsSubclassConstructor(info_->function()->kind())) {
arg_count++;
}
int arguments_bytes = arg_count * kPointerSize;

Powered by Google App Engine
This is Rietveld 408576698