From a1c2e40276ea7f27408d563b91ffcfdb1ca81a6f Mon Sep 17 00:00:00 2001 From: "zhengxing.li" Date: Tue, 22 Dec 2015 21:05:35 -0800 Subject: [PATCH] X87: [runtime] Rewrite Function.prototype.toString in C++. port 4acca53e62cdfe6f3c495c87ca7d3c8fe1059f01(r32996) original commit message: There's actually no point trying to do Function.prototype.toString in JavaScript, as it always calls into C++ at least once, so it only complicates things (esp. once we start optimizing bound functions). Drive-by-fix: Rename FunctionApply and FunctionCall builtins to also reflect the fact that these are builtins in the Function.prototype and not on Function itself. BUG= Review URL: https://codereview.chromium.org/1548483003 Cr-Commit-Position: refs/heads/master@{#33017} --- src/x87/builtins-x87.cc | 95 +++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 47 deletions(-) mode change 100644 => 100755 src/x87/builtins-x87.cc diff --git a/src/x87/builtins-x87.cc b/src/x87/builtins-x87.cc old mode 100644 new mode 100755 index f23110c67c..d5d5274aa1 --- a/src/x87/builtins-x87.cc +++ b/src/x87/builtins-x87.cc @@ -995,53 +995,7 @@ void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) { // static -void Builtins::Generate_FunctionCall(MacroAssembler* masm) { - // Stack Layout: - // esp[0] : Return address - // esp[8] : Argument n - // esp[16] : Argument n-1 - // ... - // esp[8 * n] : Argument 1 - // esp[8 * (n + 1)] : Receiver (callable to call) - // - // eax contains the number of arguments, n, not counting the receiver. - // - // 1. Make sure we have at least one argument. - { - Label done; - __ test(eax, eax); - __ j(not_zero, &done, Label::kNear); - __ PopReturnAddressTo(ebx); - __ PushRoot(Heap::kUndefinedValueRootIndex); - __ PushReturnAddressFrom(ebx); - __ inc(eax); - __ bind(&done); - } - - // 2. Get the callable to call (passed as receiver) from the stack. - __ mov(edi, Operand(esp, eax, times_pointer_size, kPointerSize)); - - // 3. Shift arguments and return address one slot down on the stack - // (overwriting the original receiver). Adjust argument count to make - // the original first argument the new receiver. - { - Label loop; - __ mov(ecx, eax); - __ bind(&loop); - __ mov(ebx, Operand(esp, ecx, times_pointer_size, 0)); - __ mov(Operand(esp, ecx, times_pointer_size, kPointerSize), ebx); - __ dec(ecx); - __ j(not_sign, &loop); // While non-negative (to copy return address). - __ pop(ebx); // Discard copy of return address. - __ dec(eax); // One fewer argument (first argument is new receiver). - } - - // 4. Call the callable. - __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); -} - - -void Builtins::Generate_FunctionApply(MacroAssembler* masm) { +void Builtins::Generate_FunctionPrototypeApply(MacroAssembler* masm) { // ----------- S t a t e ------------- // -- eax : argc // -- esp[0] : return address @@ -1117,6 +1071,53 @@ void Builtins::Generate_FunctionApply(MacroAssembler* masm) { } +// static +void Builtins::Generate_FunctionPrototypeCall(MacroAssembler* masm) { + // Stack Layout: + // esp[0] : Return address + // esp[8] : Argument n + // esp[16] : Argument n-1 + // ... + // esp[8 * n] : Argument 1 + // esp[8 * (n + 1)] : Receiver (callable to call) + // + // eax contains the number of arguments, n, not counting the receiver. + // + // 1. Make sure we have at least one argument. + { + Label done; + __ test(eax, eax); + __ j(not_zero, &done, Label::kNear); + __ PopReturnAddressTo(ebx); + __ PushRoot(Heap::kUndefinedValueRootIndex); + __ PushReturnAddressFrom(ebx); + __ inc(eax); + __ bind(&done); + } + + // 2. Get the callable to call (passed as receiver) from the stack. + __ mov(edi, Operand(esp, eax, times_pointer_size, kPointerSize)); + + // 3. Shift arguments and return address one slot down on the stack + // (overwriting the original receiver). Adjust argument count to make + // the original first argument the new receiver. + { + Label loop; + __ mov(ecx, eax); + __ bind(&loop); + __ mov(ebx, Operand(esp, ecx, times_pointer_size, 0)); + __ mov(Operand(esp, ecx, times_pointer_size, kPointerSize), ebx); + __ dec(ecx); + __ j(not_sign, &loop); // While non-negative (to copy return address). + __ pop(ebx); // Discard copy of return address. + __ dec(eax); // One fewer argument (first argument is new receiver). + } + + // 4. Call the callable. + __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET); +} + + void Builtins::Generate_ReflectApply(MacroAssembler* masm) { // ----------- S t a t e ------------- // -- eax : argc