Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: src/arm/builtins-arm.cc

Issue 1542963002: [runtime] Introduce dedicated JSBoundFunction to represent bound functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@FunctionConstructor
Patch Set: arm port. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/arm/builtins-arm.cc
diff --git a/src/arm/builtins-arm.cc b/src/arm/builtins-arm.cc
index 60ad24e7879b30ec64f542fbad790b7b3024eaa4..c24b6fb036adf29cff8f38905e6ae2045ab6a4eb 100644
--- a/src/arm/builtins-arm.cc
+++ b/src/arm/builtins-arm.cc
@@ -1894,6 +1894,90 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
// static
+void Builtins::Generate_CallBoundFunction(MacroAssembler* masm) {
+ // ----------- S t a t e -------------
+ // -- r0 : the number of arguments (not including the receiver)
+ // -- r1 : the function to call (checked to be a JSBoundFunction)
+ // -----------------------------------
+ __ AssertBoundFunction(r1);
+
+ // Patch the receiver to [[BoundThis]].
+ {
+ __ ldr(ip, FieldMemOperand(r1, JSBoundFunction::kBoundThisOffset));
+ __ str(ip, MemOperand(sp, r0, LSL, kPointerSizeLog2));
+ }
+
+ // Load [[BoundArguments]] into r2 and length of that into r4.
+ __ ldr(r2, FieldMemOperand(r1, JSBoundFunction::kBoundArgumentsOffset));
+ __ ldr(r4, FieldMemOperand(r2, FixedArray::kLengthOffset));
+ __ SmiUntag(r4);
+
+ // ----------- S t a t e -------------
+ // -- r0 : the number of arguments (not including the receiver)
+ // -- r1 : the function to call (checked to be a JSBoundFunction)
+ // -- r2 : the [[BoundArguments]] (implemented as FixedArray)
+ // -- r4 : the number of [[BoundArguments]]
+ // -----------------------------------
+
+ // Reserve stack space for the [[BoundArguments]].
+ {
+ Label done;
+ __ sub(sp, sp, Operand(r4, LSL, kPointerSizeLog2));
+ // Check the stack for overflow. We are not trying to catch interruptions
+ // (i.e. debug break and preemption) here, so check the "real stack limit".
+ __ CompareRoot(sp, Heap::kRealStackLimitRootIndex);
+ __ b(gt, &done); // Signed comparison.
+ // Restore the stack pointer.
+ __ add(sp, sp, Operand(r4, LSL, kPointerSizeLog2));
+ {
+ FrameScope scope(masm, StackFrame::MANUAL);
+ __ EnterFrame(StackFrame::INTERNAL);
+ __ CallRuntime(Runtime::kThrowStackOverflow, 0);
+ }
+ __ bind(&done);
+ }
+
+ // Relocate arguments down the stack.
+ {
+ Label loop, done_loop;
+ __ mov(r5, Operand(0));
+ __ bind(&loop);
+ __ cmp(r5, r0);
+ __ b(gt, &done_loop);
+ __ ldr(ip, MemOperand(sp, r4, LSL, kPointerSizeLog2));
+ __ str(ip, MemOperand(sp, r5, LSL, kPointerSizeLog2));
+ __ add(r4, r4, Operand(1));
+ __ add(r5, r5, Operand(1));
+ __ b(&loop);
+ __ bind(&done_loop);
+ }
+
+ // Copy [[BoundArguments]] to the stack (below the arguments).
+ {
+ Label loop, done_loop;
+ __ ldr(r4, FieldMemOperand(r2, FixedArray::kLengthOffset));
+ __ SmiUntag(r4);
+ __ add(r2, r2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
+ __ bind(&loop);
+ __ sub(r4, r4, Operand(1), SetCC);
+ __ b(lt, &done_loop);
+ __ ldr(ip, MemOperand(r2, r4, LSL, kPointerSizeLog2));
+ __ str(ip, MemOperand(sp, r0, LSL, kPointerSizeLog2));
+ __ add(r0, r0, Operand(1));
+ __ b(&loop);
+ __ bind(&done_loop);
+ }
+
+ // Call the [[BoundTargetFunction]] via the Call builtin.
+ __ ldr(r1, FieldMemOperand(r1, JSBoundFunction::kBoundTargetFunctionOffset));
+ __ mov(ip, Operand(ExternalReference(Builtins::kCall_ReceiverIsAny,
+ masm->isolate())));
+ __ ldr(ip, MemOperand(ip));
+ __ add(pc, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
+}
+
+
+// static
void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
// ----------- S t a t e -------------
// -- r0 : the number of arguments (not including the receiver)
@@ -1906,6 +1990,9 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
__ CompareObjectType(r1, r4, r5, JS_FUNCTION_TYPE);
__ Jump(masm->isolate()->builtins()->CallFunction(mode),
RelocInfo::CODE_TARGET, eq);
+ __ cmp(r5, Operand(JS_BOUND_FUNCTION_TYPE));
+ __ Jump(masm->isolate()->builtins()->CallBoundFunction(),
+ RelocInfo::CODE_TARGET, eq);
__ cmp(r5, Operand(JS_PROXY_TYPE));
__ b(ne, &non_function);
@@ -1965,6 +2052,92 @@ void Builtins::Generate_ConstructFunction(MacroAssembler* masm) {
// static
+void Builtins::Generate_ConstructBoundFunction(MacroAssembler* masm) {
+ // ----------- S t a t e -------------
+ // -- r0 : the number of arguments (not including the receiver)
+ // -- r1 : the function to call (checked to be a JSBoundFunction)
+ // -- r3 : the new target (checked to be a constructor)
+ // -----------------------------------
+ __ AssertBoundFunction(r1);
+
+ // Load [[BoundArguments]] into r2 and length of that into r4.
+ __ ldr(r2, FieldMemOperand(r1, JSBoundFunction::kBoundArgumentsOffset));
+ __ ldr(r4, FieldMemOperand(r2, FixedArray::kLengthOffset));
+ __ SmiUntag(r4);
+
+ // ----------- S t a t e -------------
+ // -- r0 : the number of arguments (not including the receiver)
+ // -- r1 : the function to call (checked to be a JSBoundFunction)
+ // -- r2 : the [[BoundArguments]] (implemented as FixedArray)
+ // -- r3 : the new target (checked to be a constructor)
+ // -- r4 : the number of [[BoundArguments]]
+ // -----------------------------------
+
+ // Reserve stack space for the [[BoundArguments]].
+ {
+ Label done;
+ __ sub(sp, sp, Operand(r4, LSL, kPointerSizeLog2));
+ // Check the stack for overflow. We are not trying to catch interruptions
+ // (i.e. debug break and preemption) here, so check the "real stack limit".
+ __ CompareRoot(sp, Heap::kRealStackLimitRootIndex);
+ __ b(gt, &done); // Signed comparison.
+ // Restore the stack pointer.
+ __ add(sp, sp, Operand(r4, LSL, kPointerSizeLog2));
+ {
+ FrameScope scope(masm, StackFrame::MANUAL);
+ __ EnterFrame(StackFrame::INTERNAL);
+ __ CallRuntime(Runtime::kThrowStackOverflow, 0);
+ }
+ __ bind(&done);
+ }
+
+ // Relocate arguments down the stack.
+ {
+ Label loop, done_loop;
+ __ mov(r5, Operand(0));
+ __ bind(&loop);
+ __ cmp(r5, r0);
+ __ b(ge, &done_loop);
+ __ ldr(ip, MemOperand(sp, r4, LSL, kPointerSizeLog2));
+ __ str(ip, MemOperand(sp, r5, LSL, kPointerSizeLog2));
+ __ add(r4, r4, Operand(1));
+ __ add(r5, r5, Operand(1));
+ __ b(&loop);
+ __ bind(&done_loop);
+ }
+
+ // Copy [[BoundArguments]] to the stack (below the arguments).
+ {
+ Label loop, done_loop;
+ __ ldr(r4, FieldMemOperand(r2, FixedArray::kLengthOffset));
+ __ SmiUntag(r4);
+ __ add(r2, r2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
+ __ bind(&loop);
+ __ sub(r4, r4, Operand(1), SetCC);
+ __ b(lt, &done_loop);
+ __ ldr(ip, MemOperand(r2, r4, LSL, kPointerSizeLog2));
+ __ str(ip, MemOperand(sp, r0, LSL, kPointerSizeLog2));
+ __ add(r0, r0, Operand(1));
+ __ b(&loop);
+ __ bind(&done_loop);
+ }
+
+ // Patch new.target to [[BoundTargetFunction]] if new.target equals target.
+ {
+ __ cmp(r1, r3);
+ __ ldr(r3, FieldMemOperand(r1, JSBoundFunction::kBoundTargetFunctionOffset),
+ eq);
+ }
+
+ // Construct the [[BoundTargetFunction]] via the Construct builtin.
+ __ ldr(r1, FieldMemOperand(r1, JSBoundFunction::kBoundTargetFunctionOffset));
+ __ mov(ip, Operand(ExternalReference(Builtins::kConstruct, masm->isolate())));
+ __ ldr(ip, MemOperand(ip));
+ __ add(pc, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
+}
+
+
+// static
void Builtins::Generate_ConstructProxy(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- r0 : the number of arguments (not including the receiver)
@@ -2007,6 +2180,12 @@ void Builtins::Generate_Construct(MacroAssembler* masm) {
__ tst(r2, Operand(1 << Map::kIsConstructor));
__ b(eq, &non_constructor);
+ // Only dispatch to bound functions after checking whether they are
+ // constructors.
+ __ cmp(r5, Operand(JS_BOUND_FUNCTION_TYPE));
+ __ Jump(masm->isolate()->builtins()->ConstructBoundFunction(),
+ RelocInfo::CODE_TARGET, eq);
+
// Only dispatch to proxies after checking whether they are constructors.
__ cmp(r5, Operand(JS_PROXY_TYPE));
__ Jump(masm->isolate()->builtins()->ConstructProxy(), RelocInfo::CODE_TARGET,
« no previous file with comments | « src/api-natives.cc ('k') | src/arm/code-stubs-arm.cc » ('j') | src/objects-debug.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698