Index: src/builtins/x64/builtins-x64.cc |
diff --git a/src/builtins/x64/builtins-x64.cc b/src/builtins/x64/builtins-x64.cc |
index 87a759087551cab1a62140fc31bae6d7b8035134..944c7845276155544df0b2e5d83521bc0acb5fc4 100644 |
--- a/src/builtins/x64/builtins-x64.cc |
+++ b/src/builtins/x64/builtins-x64.cc |
@@ -1062,6 +1062,8 @@ void Builtins::Generate_InstantiateAsmJs(MacroAssembler* masm) { |
Label failed; |
{ |
FrameScope scope(masm, StackFrame::INTERNAL); |
+ // Preserve argument count for later compare. |
+ __ movp(kScratchRegister, rax); |
// Push the number of arguments to the callee. |
__ Integer32ToSmi(rax, rax); |
__ Push(rax); |
@@ -1072,16 +1074,42 @@ void Builtins::Generate_InstantiateAsmJs(MacroAssembler* masm) { |
// The function. |
__ Push(rdi); |
// Copy arguments from caller (stdlib, foreign, heap). |
- for (int i = 2; i >= 0; --i) { |
- __ Push(Operand( |
- rbp, StandardFrameConstants::kCallerSPOffset + i * kPointerSize)); |
+ Label args_done; |
+ for (int j = 0; j < 4; ++j) { |
+ Label over; |
+ if (j < 3) { |
+ __ cmpp(kScratchRegister, Immediate(j)); |
+ __ j(not_equal, &over, Label::kNear); |
+ } |
+ for (int i = j - 1; i >= 0; --i) { |
+ __ Push(Operand( |
+ rbp, StandardFrameConstants::kCallerSPOffset + i * kPointerSize)); |
+ } |
+ for (int i = 0; i < 3 - j; ++i) { |
+ __ PushRoot(Heap::kUndefinedValueRootIndex); |
+ } |
+ if (j < 3) { |
+ __ jmp(&args_done, Label::kNear); |
+ __ bind(&over); |
+ } |
} |
+ __ bind(&args_done); |
+ |
// Call runtime, on success unwind frame, and parent frame. |
__ CallRuntime(Runtime::kInstantiateAsmJs, 4); |
// A smi 0 is returned on failure, an object on success. |
__ JumpIfSmi(rax, &failed, Label::kNear); |
+ |
+ __ Drop(2); |
+ __ Pop(kScratchRegister); |
+ __ SmiToInteger32(kScratchRegister, kScratchRegister); |
scope.GenerateLeaveFrame(); |
- __ ret(4 * kPointerSize); |
+ |
+ __ PopReturnAddressTo(rbx); |
+ __ incp(kScratchRegister); |
+ __ leap(rsp, Operand(rsp, kScratchRegister, times_pointer_size, 0)); |
+ __ PushReturnAddressFrom(rbx); |
+ __ ret(0); |
__ bind(&failed); |
// Restore target function and new target. |