Index: src/builtins/x87/builtins-x87.cc |
diff --git a/src/builtins/x87/builtins-x87.cc b/src/builtins/x87/builtins-x87.cc |
index b73bb2be28729cdccdb0ca0a66258e2367906136..9651e7ba2f05a571f5ea016895ac24dbb8e56922 100644 |
--- a/src/builtins/x87/builtins-x87.cc |
+++ b/src/builtins/x87/builtins-x87.cc |
@@ -730,8 +730,10 @@ void Builtins::Generate_InterpreterPushArgsAndCallImpl( |
__ Jump(masm->isolate()->builtins()->CallFunction(ConvertReceiverMode::kAny, |
tail_call_mode), |
RelocInfo::CODE_TARGET); |
+ } else if (mode == InterpreterPushArgsMode::kWithFinalSpread) { |
+ __ Jump(masm->isolate()->builtins()->CallWithSpread(), |
+ RelocInfo::CODE_TARGET); |
} else { |
- DCHECK_EQ(mode, InterpreterPushArgsMode::kOther); |
__ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny, |
tail_call_mode), |
RelocInfo::CODE_TARGET); |
@@ -2701,137 +2703,7 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode, |
} |
} |
-// static |
-void Builtins::Generate_ConstructFunction(MacroAssembler* masm) { |
- // ----------- S t a t e ------------- |
- // -- eax : the number of arguments (not including the receiver) |
- // -- edx : the new target (checked to be a constructor) |
- // -- edi : the constructor to call (checked to be a JSFunction) |
- // ----------------------------------- |
- __ AssertFunction(edi); |
- |
- // Calling convention for function specific ConstructStubs require |
- // ebx to contain either an AllocationSite or undefined. |
- __ LoadRoot(ebx, Heap::kUndefinedValueRootIndex); |
- |
- // Tail call to the function-specific construct stub (still in the caller |
- // context at this point). |
- __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
- __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset)); |
- __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize)); |
- __ jmp(ecx); |
-} |
- |
-// static |
-void Builtins::Generate_ConstructBoundFunction(MacroAssembler* masm) { |
- // ----------- S t a t e ------------- |
- // -- eax : the number of arguments (not including the receiver) |
- // -- edx : the new target (checked to be a constructor) |
- // -- edi : the constructor to call (checked to be a JSBoundFunction) |
- // ----------------------------------- |
- __ AssertBoundFunction(edi); |
- |
- // Push the [[BoundArguments]] onto the stack. |
- Generate_PushBoundArguments(masm); |
- |
- // Patch new.target to [[BoundTargetFunction]] if new.target equals target. |
- { |
- Label done; |
- __ cmp(edi, edx); |
- __ j(not_equal, &done, Label::kNear); |
- __ mov(edx, FieldOperand(edi, JSBoundFunction::kBoundTargetFunctionOffset)); |
- __ bind(&done); |
- } |
- |
- // Construct the [[BoundTargetFunction]] via the Construct builtin. |
- __ mov(edi, FieldOperand(edi, JSBoundFunction::kBoundTargetFunctionOffset)); |
- __ mov(ecx, Operand::StaticVariable( |
- ExternalReference(Builtins::kConstruct, masm->isolate()))); |
- __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize)); |
- __ jmp(ecx); |
-} |
- |
-// static |
-void Builtins::Generate_ConstructProxy(MacroAssembler* masm) { |
- // ----------- S t a t e ------------- |
- // -- eax : the number of arguments (not including the receiver) |
- // -- edi : the constructor to call (checked to be a JSProxy) |
- // -- edx : the new target (either the same as the constructor or |
- // the JSFunction on which new was invoked initially) |
- // ----------------------------------- |
- |
- // Call into the Runtime for Proxy [[Construct]]. |
- __ PopReturnAddressTo(ecx); |
- __ Push(edi); |
- __ Push(edx); |
- __ PushReturnAddressFrom(ecx); |
- // Include the pushed new_target, constructor and the receiver. |
- __ add(eax, Immediate(3)); |
- // Tail-call to the runtime. |
- __ JumpToExternalReference( |
- ExternalReference(Runtime::kJSProxyConstruct, masm->isolate())); |
-} |
- |
-// static |
-void Builtins::Generate_Construct(MacroAssembler* masm) { |
- // ----------- S t a t e ------------- |
- // -- eax : the number of arguments (not including the receiver) |
- // -- edx : the new target (either the same as the constructor or |
- // the JSFunction on which new was invoked initially) |
- // -- edi : the constructor to call (can be any Object) |
- // ----------------------------------- |
- |
- // Check if target is a Smi. |
- Label non_constructor; |
- __ JumpIfSmi(edi, &non_constructor, Label::kNear); |
- |
- // Dispatch based on instance type. |
- __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
- __ j(equal, masm->isolate()->builtins()->ConstructFunction(), |
- RelocInfo::CODE_TARGET); |
- |
- // Check if target has a [[Construct]] internal method. |
- __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
- Immediate(1 << Map::kIsConstructor)); |
- __ j(zero, &non_constructor, Label::kNear); |
- |
- // Only dispatch to bound functions after checking whether they are |
- // constructors. |
- __ CmpInstanceType(ecx, JS_BOUND_FUNCTION_TYPE); |
- __ j(equal, masm->isolate()->builtins()->ConstructBoundFunction(), |
- RelocInfo::CODE_TARGET); |
- |
- // Only dispatch to proxies after checking whether they are constructors. |
- __ CmpInstanceType(ecx, JS_PROXY_TYPE); |
- __ j(equal, masm->isolate()->builtins()->ConstructProxy(), |
- RelocInfo::CODE_TARGET); |
- |
- // Called Construct on an exotic Object with a [[Construct]] internal method. |
- { |
- // Overwrite the original receiver with the (original) target. |
- __ mov(Operand(esp, eax, times_pointer_size, kPointerSize), edi); |
- // Let the "call_as_constructor_delegate" take care of the rest. |
- __ LoadGlobalFunction(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, edi); |
- __ Jump(masm->isolate()->builtins()->CallFunction(), |
- RelocInfo::CODE_TARGET); |
- } |
- |
- // Called Construct on an Object that doesn't have a [[Construct]] internal |
- // method. |
- __ bind(&non_constructor); |
- __ Jump(masm->isolate()->builtins()->ConstructedNonConstructable(), |
- RelocInfo::CODE_TARGET); |
-} |
- |
-// static |
-void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) { |
- // ----------- S t a t e ------------- |
- // -- eax : the number of arguments (not including the receiver) |
- // -- edx : the new target (either the same as the constructor or |
- // the JSFunction on which new was invoked initially) |
- // -- edi : the constructor to call (can be any Object) |
- // ----------------------------------- |
- |
+static void CheckSpreadAndPushToStack(MacroAssembler* masm) { |
// Free up some registers. |
// Save edx/edi to stX0/stX1. |
__ push(edx); |
@@ -2848,6 +2720,8 @@ void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) { |
Register spread = ebx; |
Register spread_map = edx; |
+ Register spread_len = edx; |
+ |
__ mov(spread, Operand(esp, kPointerSize)); |
__ mov(spread_map, FieldOperand(spread, HeapObject::kMapOffset)); |
@@ -2900,9 +2774,10 @@ void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) { |
__ j(not_equal, &runtime_call); |
__ bind(&no_protector_check); |
- // Load the FixedArray backing store. |
+ // Load the FixedArray backing store, but use the length from the array. |
+ __ mov(spread_len, FieldOperand(spread, JSArray::kLengthOffset)); |
+ __ SmiUntag(spread_len); |
__ mov(spread, FieldOperand(spread, JSArray::kElementsOffset)); |
- // Free up some registers. |
__ jmp(&push_args); |
__ bind(&runtime_call); |
@@ -2937,19 +2812,19 @@ void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) { |
__ lea(esp, Operand(esp, 2 * kFloatSize)); |
} |
- Register spread_len = edx; |
Register return_address = edi; |
- __ bind(&push_args); |
{ |
- // Pop the return address and spread argument. |
- __ PopReturnAddressTo(return_address); |
- __ Pop(scratch); |
- |
// Calculate the new nargs including the result of the spread. |
__ mov(spread_len, FieldOperand(spread, FixedArray::kLengthOffset)); |
__ SmiUntag(spread_len); |
+ |
+ __ bind(&push_args); |
// argc += spread_len - 1. Subtract 1 for the spread itself. |
__ lea(argc, Operand(argc, spread_len, times_1, -1)); |
+ |
+ // Pop the return address and spread argument. |
+ __ PopReturnAddressTo(return_address); |
+ __ Pop(scratch); |
} |
// Check for stack overflow. |
@@ -2973,7 +2848,6 @@ void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) { |
// Put the evaluated spread onto the stack as additional arguments. |
{ |
Register scratch2 = esi; |
- // __ movd(xmm2, esi); |
// Save esi to stX0, edx/edi in stX1/stX2 now. |
__ push(esi); |
__ fld_s(MemOperand(esp, 0)); |
@@ -3001,8 +2875,155 @@ void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) { |
__ pop(edx); |
__ pop(edi); |
} |
+} |
+ |
+// static |
+void Builtins::Generate_CallWithSpread(MacroAssembler* masm) { |
+ // ----------- S t a t e ------------- |
+ // -- eax : the number of arguments (not including the receiver) |
+ // -- edi : the target to call (can be any Object) |
+ // ----------------------------------- |
+ |
+ // CheckSpreadAndPushToStack will push edx to save it. |
+ __ LoadRoot(edx, Heap::kUndefinedValueRootIndex); |
+ CheckSpreadAndPushToStack(masm); |
+ __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny, |
+ TailCallMode::kDisallow), |
+ RelocInfo::CODE_TARGET); |
+} |
+ |
+// static |
+void Builtins::Generate_ConstructFunction(MacroAssembler* masm) { |
+ // ----------- S t a t e ------------- |
+ // -- eax : the number of arguments (not including the receiver) |
+ // -- edx : the new target (checked to be a constructor) |
+ // -- edi : the constructor to call (checked to be a JSFunction) |
+ // ----------------------------------- |
+ __ AssertFunction(edi); |
+ |
+ // Calling convention for function specific ConstructStubs require |
+ // ebx to contain either an AllocationSite or undefined. |
+ __ LoadRoot(ebx, Heap::kUndefinedValueRootIndex); |
+ |
+ // Tail call to the function-specific construct stub (still in the caller |
+ // context at this point). |
+ __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
+ __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset)); |
+ __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize)); |
+ __ jmp(ecx); |
+} |
+ |
+// static |
+void Builtins::Generate_ConstructBoundFunction(MacroAssembler* masm) { |
+ // ----------- S t a t e ------------- |
+ // -- eax : the number of arguments (not including the receiver) |
+ // -- edx : the new target (checked to be a constructor) |
+ // -- edi : the constructor to call (checked to be a JSBoundFunction) |
+ // ----------------------------------- |
+ __ AssertBoundFunction(edi); |
+ |
+ // Push the [[BoundArguments]] onto the stack. |
+ Generate_PushBoundArguments(masm); |
+ |
+ // Patch new.target to [[BoundTargetFunction]] if new.target equals target. |
+ { |
+ Label done; |
+ __ cmp(edi, edx); |
+ __ j(not_equal, &done, Label::kNear); |
+ __ mov(edx, FieldOperand(edi, JSBoundFunction::kBoundTargetFunctionOffset)); |
+ __ bind(&done); |
+ } |
+ |
+ // Construct the [[BoundTargetFunction]] via the Construct builtin. |
+ __ mov(edi, FieldOperand(edi, JSBoundFunction::kBoundTargetFunctionOffset)); |
+ __ mov(ecx, Operand::StaticVariable( |
+ ExternalReference(Builtins::kConstruct, masm->isolate()))); |
+ __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize)); |
+ __ jmp(ecx); |
+} |
+ |
+// static |
+void Builtins::Generate_ConstructProxy(MacroAssembler* masm) { |
+ // ----------- S t a t e ------------- |
+ // -- eax : the number of arguments (not including the receiver) |
+ // -- edi : the constructor to call (checked to be a JSProxy) |
+ // -- edx : the new target (either the same as the constructor or |
+ // the JSFunction on which new was invoked initially) |
+ // ----------------------------------- |
+ |
+ // Call into the Runtime for Proxy [[Construct]]. |
+ __ PopReturnAddressTo(ecx); |
+ __ Push(edi); |
+ __ Push(edx); |
+ __ PushReturnAddressFrom(ecx); |
+ // Include the pushed new_target, constructor and the receiver. |
+ __ add(eax, Immediate(3)); |
+ // Tail-call to the runtime. |
+ __ JumpToExternalReference( |
+ ExternalReference(Runtime::kJSProxyConstruct, masm->isolate())); |
+} |
+ |
+// static |
+void Builtins::Generate_Construct(MacroAssembler* masm) { |
+ // ----------- S t a t e ------------- |
+ // -- eax : the number of arguments (not including the receiver) |
+ // -- edx : the new target (either the same as the constructor or |
+ // the JSFunction on which new was invoked initially) |
+ // -- edi : the constructor to call (can be any Object) |
+ // ----------------------------------- |
+ |
+ // Check if target is a Smi. |
+ Label non_constructor; |
+ __ JumpIfSmi(edi, &non_constructor, Label::kNear); |
+ |
+ // Dispatch based on instance type. |
+ __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
+ __ j(equal, masm->isolate()->builtins()->ConstructFunction(), |
+ RelocInfo::CODE_TARGET); |
+ |
+ // Check if target has a [[Construct]] internal method. |
+ __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
+ Immediate(1 << Map::kIsConstructor)); |
+ __ j(zero, &non_constructor, Label::kNear); |
+ |
+ // Only dispatch to bound functions after checking whether they are |
+ // constructors. |
+ __ CmpInstanceType(ecx, JS_BOUND_FUNCTION_TYPE); |
+ __ j(equal, masm->isolate()->builtins()->ConstructBoundFunction(), |
+ RelocInfo::CODE_TARGET); |
+ |
+ // Only dispatch to proxies after checking whether they are constructors. |
+ __ CmpInstanceType(ecx, JS_PROXY_TYPE); |
+ __ j(equal, masm->isolate()->builtins()->ConstructProxy(), |
+ RelocInfo::CODE_TARGET); |
+ |
+ // Called Construct on an exotic Object with a [[Construct]] internal method. |
+ { |
+ // Overwrite the original receiver with the (original) target. |
+ __ mov(Operand(esp, eax, times_pointer_size, kPointerSize), edi); |
+ // Let the "call_as_constructor_delegate" take care of the rest. |
+ __ LoadGlobalFunction(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, edi); |
+ __ Jump(masm->isolate()->builtins()->CallFunction(), |
+ RelocInfo::CODE_TARGET); |
+ } |
+ |
+ // Called Construct on an Object that doesn't have a [[Construct]] internal |
+ // method. |
+ __ bind(&non_constructor); |
+ __ Jump(masm->isolate()->builtins()->ConstructedNonConstructable(), |
+ RelocInfo::CODE_TARGET); |
+} |
+ |
+// static |
+void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) { |
+ // ----------- S t a t e ------------- |
+ // -- eax : the number of arguments (not including the receiver) |
+ // -- edx : the new target (either the same as the constructor or |
+ // the JSFunction on which new was invoked initially) |
+ // -- edi : the constructor to call (can be any Object) |
+ // ----------------------------------- |
- // Dispatch. |
+ CheckSpreadAndPushToStack(masm); |
__ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); |
} |