Index: src/x64/full-codegen-x64.cc |
diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc |
index 8fe07975c225d1cf34c47d629907afc3ccb49609..33521c6f17dcb320ef955b0d3a4bf1284a9f6938 100644 |
--- a/src/x64/full-codegen-x64.cc |
+++ b/src/x64/full-codegen-x64.cc |
@@ -2962,8 +2962,7 @@ void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { |
} |
-void FullCodeGenerator::EmitLoadSuperConstructor(SuperReference* super_ref) { |
- DCHECK(super_ref != NULL); |
+void FullCodeGenerator::EmitLoadSuperConstructor() { |
__ Push(Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
__ CallRuntime(Runtime::kGetPrototype, 1); |
} |
@@ -3080,9 +3079,9 @@ void FullCodeGenerator::VisitCall(Call* expr) { |
if (FLAG_experimental_classes) { |
EmitSuperConstructorCall(expr); |
} else { |
- SuperReference* super_ref = callee->AsSuperReference(); |
- EmitLoadSuperConstructor(super_ref); |
+ EmitLoadSuperConstructor(); |
__ Push(result_register()); |
+ SuperReference* super_ref = callee->AsSuperReference(); |
VisitForStackValue(super_ref->this_var()); |
EmitCall(expr, CallICState::METHOD); |
} |
@@ -3153,10 +3152,10 @@ void FullCodeGenerator::EmitSuperConstructorCall(Call* expr) { |
GetVar(result_register(), new_target_var); |
__ Push(result_register()); |
- SuperReference* super_ref = expr->expression()->AsSuperReference(); |
- EmitLoadSuperConstructor(super_ref); |
+ EmitLoadSuperConstructor(); |
__ Push(result_register()); |
+ SuperReference* super_ref = expr->expression()->AsSuperReference(); |
Variable* this_var = super_ref->this_var()->var(); |
GetVar(rax, this_var); |
@@ -4071,6 +4070,55 @@ void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) { |
} |
+void FullCodeGenerator::EmitDefaultConstructorCallSuper(CallRuntime* expr) { |
+ Variable* new_target_var = scope()->DeclarationScope()->new_target_var(); |
+ GetVar(result_register(), new_target_var); |
+ __ Push(result_register()); |
+ |
+ EmitLoadSuperConstructor(); |
+ __ Push(result_register()); |
+ |
+ // Check if the calling frame is an arguments adaptor frame. |
+ Label adaptor_frame, args_set_up, runtime; |
+ __ movp(rdx, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
+ __ movp(rcx, Operand(rdx, StandardFrameConstants::kContextOffset)); |
+ __ Cmp(rcx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
+ __ j(equal, &adaptor_frame); |
+ // default constructor has no arguments, so no adaptor frame means no args. |
+ __ movp(rax, Immediate(0)); |
+ __ jmp(&args_set_up); |
+ |
+ // Copy arguments from adaptor frame. |
+ { |
+ __ bind(&adaptor_frame); |
+ __ movp(rcx, Operand(rdx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
+ __ SmiToInteger64(rcx, rcx); |
+ |
+ // Subtract 1 from arguments count, for new.target. |
+ __ subp(rcx, Immediate(1)); |
+ __ movp(rax, rcx); |
+ __ leap(rdx, Operand(rdx, rcx, times_pointer_size, |
+ StandardFrameConstants::kCallerSPOffset)); |
+ Label loop; |
+ __ bind(&loop); |
+ __ Push(Operand(rdx, -1 * kPointerSize)); |
+ __ subp(rdx, Immediate(kPointerSize)); |
+ __ decp(rcx); |
+ __ j(not_zero, &loop); |
+ } |
+ |
+ __ bind(&args_set_up); |
+ __ movp(rdi, Operand(rsp, rax, times_pointer_size, 0)); |
+ |
+ CallConstructStub stub(isolate(), SUPER_CONSTRUCTOR_CALL); |
+ __ call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL); |
+ |
+ __ Drop(1); |
+ |
+ context()->Plug(result_register()); |
+} |
+ |
+ |
void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) { |
RegExpConstructResultStub stub(isolate()); |
ZoneList<Expression*>* args = expr->arguments(); |