Index: src/x64/builtins-x64.cc |
diff --git a/src/x64/builtins-x64.cc b/src/x64/builtins-x64.cc |
index 45dea848b50a2bc6d0db6db8c1901da6739ece34..d32f14447870813e3eb894da294bfe2def449d84 100644 |
--- a/src/x64/builtins-x64.cc |
+++ b/src/x64/builtins-x64.cc |
@@ -92,7 +92,6 @@ static void GenerateTailCallToReturnedCode(MacroAssembler* masm, |
__ jmp(rbx); |
} |
- |
void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) { |
// Checking whether the queued function is ready for install is optional, |
// since we come across interrupts and stack checks elsewhere. However, |
@@ -1073,6 +1072,46 @@ void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) { |
GenerateTailCallToReturnedCode(masm, Runtime::kCompileOptimized_Concurrent); |
} |
+void Builtins::Generate_InstantiateAsmJs(MacroAssembler* masm) { |
+ // ----------- S t a t e ------------- |
+ // -- rax : argument count (preserved for callee) |
+ // -- rdx : new target (preserved for callee) |
+ // -- rdi : target function (preserved for callee) |
+ // ----------------------------------- |
+ Label failed; |
+ { |
+ FrameScope scope(masm, StackFrame::INTERNAL); |
+ // Push the number of arguments to the callee. |
+ __ Integer32ToSmi(rax, rax); |
+ __ Push(rax); |
+ // Push a copy of the target function and the new target. |
+ __ Push(rdi); |
+ __ Push(rdx); |
+ |
+ // 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)); |
+ } |
+ // 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); |
+ scope.GenerateLeaveFrame(); |
+ __ ret(4 * kPointerSize); |
+ |
+ __ bind(&failed); |
+ // Restore target function and new target. |
+ __ Pop(rdx); |
+ __ Pop(rdi); |
+ __ Pop(rax); |
+ __ SmiToInteger32(rax, rax); |
+ } |
+ // On failure, tail call back to regular js. |
+ GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy); |
+} |
static void GenerateMakeCodeYoungAgainCommon(MacroAssembler* masm) { |
// For now, we are relying on the fact that make_code_young doesn't do any |