Index: src/builtins/x87/builtins-x87.cc |
diff --git a/src/builtins/x87/builtins-x87.cc b/src/builtins/x87/builtins-x87.cc |
index 4135c2859624a57b7d75602a09fce74fba366d6d..bb7dc8380b5a3f762e253b2a27eebf1207d7b0fe 100644 |
--- a/src/builtins/x87/builtins-x87.cc |
+++ b/src/builtins/x87/builtins-x87.cc |
@@ -1011,6 +1011,8 @@ void Builtins::Generate_InstantiateAsmJs(MacroAssembler* masm) { |
Label failed; |
{ |
FrameScope scope(masm, StackFrame::INTERNAL); |
+ // Preserve argument count for later compare. |
+ __ mov(ecx, eax); |
// Push the number of arguments to the callee. |
__ SmiTag(eax); |
__ push(eax); |
@@ -1021,16 +1023,42 @@ void Builtins::Generate_InstantiateAsmJs(MacroAssembler* masm) { |
// The function. |
__ push(edi); |
// Copy arguments from caller (stdlib, foreign, heap). |
- for (int i = 2; i >= 0; --i) { |
- __ push(Operand( |
- ebp, StandardFrameConstants::kCallerSPOffset + i * kPointerSize)); |
+ Label args_done; |
+ for (int j = 0; j < 4; ++j) { |
+ Label over; |
+ if (j < 3) { |
+ __ cmp(ecx, Immediate(j)); |
+ __ j(not_equal, &over, Label::kNear); |
+ } |
+ for (int i = j - 1; i >= 0; --i) { |
+ __ Push(Operand( |
+ ebp, 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(eax, &failed, Label::kNear); |
+ |
+ __ Drop(2); |
+ __ Pop(ecx); |
+ __ SmiUntag(ecx); |
scope.GenerateLeaveFrame(); |
- __ ret(4 * kPointerSize); |
+ |
+ __ PopReturnAddressTo(ebx); |
+ __ inc(ecx); |
+ __ lea(esp, Operand(esp, ecx, times_pointer_size, 0)); |
+ __ PushReturnAddressFrom(ebx); |
+ __ ret(0); |
__ bind(&failed); |
// Restore target function and new target. |