Index: src/builtins/builtins-array-gen.cc |
diff --git a/src/builtins/builtins-array-gen.cc b/src/builtins/builtins-array-gen.cc |
index 21269fdc65bae7854fa2604358c63ee423207902..32dd9b5b85cf7bbecea29d88e4c388f97fdedae4 100644 |
--- a/src/builtins/builtins-array-gen.cc |
+++ b/src/builtins/builtins-array-gen.cc |
@@ -46,7 +46,7 @@ class ArrayBuiltinCodeStubAssembler : public CodeStubAssembler { |
Label false_continue(this), return_true(this); |
BranchIfToBooleanIsTrue(value, &return_true, &false_continue); |
BIND(&return_true); |
- Return(TrueConstant()); |
+ ReturnFromBuiltin(TrueConstant()); |
BIND(&false_continue); |
return a(); |
} |
@@ -59,44 +59,12 @@ class ArrayBuiltinCodeStubAssembler : public CodeStubAssembler { |
Label true_continue(this), return_false(this); |
BranchIfToBooleanIsTrue(value, &true_continue, &return_false); |
BIND(&return_false); |
- Return(FalseConstant()); |
+ ReturnFromBuiltin(FalseConstant()); |
BIND(&true_continue); |
return a(); |
} |
- Node* ReduceResultGenerator() { |
- VARIABLE(a, MachineRepresentation::kTagged, UndefinedConstant()); |
- Label no_initial_value(this), has_initial_value(this), done(this, {&a}); |
- |
- // 8. If initialValue is present, then |
- Node* parent_frame_ptr = LoadParentFramePointer(); |
- Node* marker_or_function = LoadBufferObject( |
- parent_frame_ptr, CommonFrameConstants::kContextOrFrameTypeOffset); |
- GotoIf( |
- MarkerIsNotFrameType(marker_or_function, StackFrame::ARGUMENTS_ADAPTOR), |
- &has_initial_value); |
- |
- // Has arguments adapter, check count. |
- Node* adapted_parameter_count = LoadBufferObject( |
- parent_frame_ptr, ArgumentsAdaptorFrameConstants::kLengthOffset); |
- Branch(SmiLessThan(adapted_parameter_count, |
- SmiConstant(IteratingArrayBuiltinDescriptor::kThisArg)), |
- &no_initial_value, &has_initial_value); |
- |
- // a. Set accumulator to initialValue. |
- BIND(&has_initial_value); |
- a.Bind(this_arg()); |
- Goto(&done); |
- |
- // 9. Else initialValue is not present, |
- BIND(&no_initial_value); |
- |
- // a. Let kPresent be false. |
- a.Bind(TheHoleConstant()); |
- Goto(&done); |
- BIND(&done); |
- return a.value(); |
- } |
+ Node* ReduceResultGenerator() { return this_arg(); } |
Node* ReduceProcessor(Node* k_value, Node* k) { |
VARIABLE(result, MachineRepresentation::kTagged); |
@@ -266,6 +234,7 @@ class ArrayBuiltinCodeStubAssembler : public CodeStubAssembler { |
Node* context() { return context_; } |
Node* receiver() { return receiver_; } |
Node* new_target() { return new_target_; } |
+ Node* argc() { return argc_; } |
Node* o() { return o_; } |
Node* len() { return len_; } |
Node* callbackfn() { return callbackfn_; } |
@@ -273,14 +242,25 @@ class ArrayBuiltinCodeStubAssembler : public CodeStubAssembler { |
Node* k() { return k_.value(); } |
Node* a() { return a_.value(); } |
+ void ReturnFromBuiltin(Node* value) { |
+ if (argc_ == nullptr) { |
+ Return(value); |
+ } else { |
+ // argc_ doesn't include the receiver, so it has to be added back in |
+ // manually. |
+ PopAndReturn(IntPtrAdd(argc_, IntPtrConstant(1)), value); |
+ } |
+ } |
+ |
void InitIteratingArrayBuiltinBody(Node* context, Node* receiver, |
Node* callbackfn, Node* this_arg, |
- Node* new_target) { |
+ Node* new_target, Node* argc) { |
context_ = context; |
receiver_ = receiver; |
new_target_ = new_target; |
callbackfn_ = callbackfn; |
this_arg_ = this_arg; |
+ argc_ = argc; |
} |
void GenerateIteratingArrayBuiltinBody( |
@@ -362,13 +342,10 @@ class ArrayBuiltinCodeStubAssembler : public CodeStubAssembler { |
BIND(&slow); |
- Node* target = LoadFromFrame(StandardFrameConstants::kFunctionOffset, |
- MachineType::TaggedPointer()); |
- TailCallStub( |
- slow_case_continuation, context(), target, new_target(), |
- Int32Constant(IteratingArrayBuiltinLoopContinuationDescriptor::kArity), |
- receiver(), callbackfn(), this_arg(), a_.value(), o(), k_.value(), |
- len(), to_.value()); |
+ Node* result = |
+ CallStub(slow_case_continuation, context(), receiver(), callbackfn(), |
+ this_arg(), a_.value(), o(), k_.value(), len(), to_.value()); |
+ ReturnFromBuiltin(result); |
} |
void InitIteratingArrayBuiltinLoopContinuation(Node* context, Node* receiver, |
@@ -379,6 +356,7 @@ class ArrayBuiltinCodeStubAssembler : public CodeStubAssembler { |
context_ = context; |
this_arg_ = this_arg; |
callbackfn_ = callbackfn; |
+ argc_ = nullptr; |
a_.Bind(a); |
k_.Bind(initial_k); |
o_ = o; |
@@ -480,7 +458,7 @@ class ArrayBuiltinCodeStubAssembler : public CodeStubAssembler { |
// No exception, return success |
BIND(&done); |
action(this); |
- Return(a_.value()); |
+ ReturnFromBuiltin(a_.value()); |
} |
} |
@@ -682,7 +660,7 @@ class ArrayBuiltinCodeStubAssembler : public CodeStubAssembler { |
action(this); |
// No exception, return success |
- Return(a_.value()); |
+ ReturnFromBuiltin(a_.value()); |
} |
BIND(&maybe_double_elements); |
@@ -697,7 +675,7 @@ class ArrayBuiltinCodeStubAssembler : public CodeStubAssembler { |
action(this); |
// No exception, return success |
- Return(a_.value()); |
+ ReturnFromBuiltin(a_.value()); |
} |
} |
@@ -708,6 +686,7 @@ class ArrayBuiltinCodeStubAssembler : public CodeStubAssembler { |
Node* context_ = nullptr; |
Node* receiver_ = nullptr; |
Node* new_target_ = nullptr; |
+ Node* argc_ = nullptr; |
Variable k_; |
Variable a_; |
Variable to_; |
@@ -863,21 +842,25 @@ TF_BUILTIN(ArrayForEachLoopContinuation, ArrayBuiltinCodeStubAssembler) { |
} |
TF_BUILTIN(ArrayForEach, ArrayBuiltinCodeStubAssembler) { |
- Node* context = Parameter(Descriptor::kContext); |
- Node* receiver = Parameter(Descriptor::kReceiver); |
- Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
- Node* this_arg = Parameter(Descriptor::kThisArg); |
- Node* new_target = Parameter(Descriptor::kNewTarget); |
+ Node* argc = |
+ ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)); |
+ CodeStubArguments args(this, argc); |
+ Node* context = Parameter(BuiltinDescriptor::kContext); |
+ Node* new_target = Parameter(BuiltinDescriptor::kNewTarget); |
+ Node* receiver = args.GetReceiver(); |
+ Node* callbackfn = args.GetOptionalArgumentValue(0, UndefinedConstant()); |
+ Node* this_arg = args.GetOptionalArgumentValue(1, UndefinedConstant()); |
InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg, |
- new_target); |
+ new_target, argc); |
GenerateIteratingArrayBuiltinBody( |
"Array.prototype.forEach", |
&ArrayBuiltinCodeStubAssembler::ForEachResultGenerator, |
&ArrayBuiltinCodeStubAssembler::ForEachProcessor, |
&ArrayBuiltinCodeStubAssembler::NullPostLoopAction, |
- CodeFactory::ArrayForEachLoopContinuation(isolate())); |
+ Builtins::CallableFor(isolate(), |
+ Builtins::kArrayForEachLoopContinuation)); |
} |
TF_BUILTIN(ArraySomeLoopContinuation, ArrayBuiltinCodeStubAssembler) { |
@@ -901,32 +884,38 @@ TF_BUILTIN(ArraySomeLoopContinuation, ArrayBuiltinCodeStubAssembler) { |
} |
TF_BUILTIN(ArraySome, ArrayBuiltinCodeStubAssembler) { |
- Node* context = Parameter(Descriptor::kContext); |
- Node* receiver = Parameter(Descriptor::kReceiver); |
- Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
- Node* this_arg = Parameter(Descriptor::kThisArg); |
- Node* new_target = Parameter(Descriptor::kNewTarget); |
+ Node* argc = |
+ ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)); |
+ CodeStubArguments args(this, argc); |
+ Node* context = Parameter(BuiltinDescriptor::kContext); |
+ Node* new_target = Parameter(BuiltinDescriptor::kNewTarget); |
+ Node* receiver = args.GetReceiver(); |
+ Node* callbackfn = args.GetOptionalArgumentValue(0, UndefinedConstant()); |
+ Node* this_arg = args.GetOptionalArgumentValue(1, UndefinedConstant()); |
InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg, |
- new_target); |
+ new_target, argc); |
GenerateIteratingArrayBuiltinBody( |
"Array.prototype.some", |
&ArrayBuiltinCodeStubAssembler::SomeResultGenerator, |
&ArrayBuiltinCodeStubAssembler::SomeProcessor, |
&ArrayBuiltinCodeStubAssembler::NullPostLoopAction, |
- CodeFactory::ArraySomeLoopContinuation(isolate())); |
+ Builtins::CallableFor(isolate(), Builtins::kArraySomeLoopContinuation)); |
} |
TF_BUILTIN(TypedArrayPrototypeSome, ArrayBuiltinCodeStubAssembler) { |
- Node* context = Parameter(Descriptor::kContext); |
- Node* receiver = Parameter(Descriptor::kReceiver); |
- Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
- Node* this_arg = Parameter(Descriptor::kThisArg); |
- Node* new_target = Parameter(Descriptor::kNewTarget); |
+ Node* argc = |
+ ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)); |
+ CodeStubArguments args(this, argc); |
+ Node* context = Parameter(BuiltinDescriptor::kContext); |
+ Node* new_target = Parameter(BuiltinDescriptor::kNewTarget); |
+ Node* receiver = args.GetReceiver(); |
+ Node* callbackfn = args.GetOptionalArgumentValue(0, UndefinedConstant()); |
+ Node* this_arg = args.GetOptionalArgumentValue(1, UndefinedConstant()); |
InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg, |
- new_target); |
+ new_target, argc); |
GenerateIteratingTypedArrayBuiltinBody( |
"%TypedArray%.prototype.some", |
@@ -956,32 +945,38 @@ TF_BUILTIN(ArrayEveryLoopContinuation, ArrayBuiltinCodeStubAssembler) { |
} |
TF_BUILTIN(ArrayEvery, ArrayBuiltinCodeStubAssembler) { |
- Node* context = Parameter(Descriptor::kContext); |
- Node* receiver = Parameter(Descriptor::kReceiver); |
- Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
- Node* this_arg = Parameter(Descriptor::kThisArg); |
- Node* new_target = Parameter(Descriptor::kNewTarget); |
+ Node* argc = |
+ ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)); |
+ CodeStubArguments args(this, argc); |
+ Node* context = Parameter(BuiltinDescriptor::kContext); |
+ Node* new_target = Parameter(BuiltinDescriptor::kNewTarget); |
+ Node* receiver = args.GetReceiver(); |
+ Node* callbackfn = args.GetOptionalArgumentValue(0, UndefinedConstant()); |
+ Node* this_arg = args.GetOptionalArgumentValue(1, UndefinedConstant()); |
InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg, |
- new_target); |
+ new_target, argc); |
GenerateIteratingArrayBuiltinBody( |
"Array.prototype.every", |
&ArrayBuiltinCodeStubAssembler::EveryResultGenerator, |
&ArrayBuiltinCodeStubAssembler::EveryProcessor, |
&ArrayBuiltinCodeStubAssembler::NullPostLoopAction, |
- CodeFactory::ArrayEveryLoopContinuation(isolate())); |
+ Builtins::CallableFor(isolate(), Builtins::kArrayEveryLoopContinuation)); |
} |
TF_BUILTIN(TypedArrayPrototypeEvery, ArrayBuiltinCodeStubAssembler) { |
- Node* context = Parameter(Descriptor::kContext); |
- Node* receiver = Parameter(Descriptor::kReceiver); |
- Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
- Node* this_arg = Parameter(Descriptor::kThisArg); |
- Node* new_target = Parameter(Descriptor::kNewTarget); |
+ Node* argc = |
+ ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)); |
+ CodeStubArguments args(this, argc); |
+ Node* context = Parameter(BuiltinDescriptor::kContext); |
+ Node* new_target = Parameter(BuiltinDescriptor::kNewTarget); |
+ Node* receiver = args.GetReceiver(); |
+ Node* callbackfn = args.GetOptionalArgumentValue(0, UndefinedConstant()); |
+ Node* this_arg = args.GetOptionalArgumentValue(1, UndefinedConstant()); |
InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg, |
- new_target); |
+ new_target, argc); |
GenerateIteratingTypedArrayBuiltinBody( |
"%TypedArray%.prototype.every", |
@@ -1011,32 +1006,38 @@ TF_BUILTIN(ArrayReduceLoopContinuation, ArrayBuiltinCodeStubAssembler) { |
} |
TF_BUILTIN(ArrayReduce, ArrayBuiltinCodeStubAssembler) { |
- Node* context = Parameter(Descriptor::kContext); |
- Node* receiver = Parameter(Descriptor::kReceiver); |
- Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
- Node* initial_value = Parameter(Descriptor::kInitialValue); |
- Node* new_target = Parameter(Descriptor::kNewTarget); |
+ Node* argc = |
+ ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)); |
+ CodeStubArguments args(this, argc); |
+ Node* context = Parameter(BuiltinDescriptor::kContext); |
+ Node* new_target = Parameter(BuiltinDescriptor::kNewTarget); |
+ Node* receiver = args.GetReceiver(); |
+ Node* callbackfn = args.GetOptionalArgumentValue(0, UndefinedConstant()); |
+ Node* initial_value = args.GetOptionalArgumentValue(1, TheHoleConstant()); |
InitIteratingArrayBuiltinBody(context, receiver, callbackfn, initial_value, |
- new_target); |
+ new_target, argc); |
GenerateIteratingArrayBuiltinBody( |
"Array.prototype.reduce", |
&ArrayBuiltinCodeStubAssembler::ReduceResultGenerator, |
&ArrayBuiltinCodeStubAssembler::ReduceProcessor, |
&ArrayBuiltinCodeStubAssembler::ReducePostLoopAction, |
- CodeFactory::ArrayReduceLoopContinuation(isolate())); |
+ Builtins::CallableFor(isolate(), Builtins::kArrayReduceLoopContinuation)); |
} |
TF_BUILTIN(TypedArrayPrototypeReduce, ArrayBuiltinCodeStubAssembler) { |
- Node* context = Parameter(Descriptor::kContext); |
- Node* receiver = Parameter(Descriptor::kReceiver); |
- Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
- Node* initial_value = Parameter(Descriptor::kInitialValue); |
- Node* new_target = Parameter(Descriptor::kNewTarget); |
+ Node* argc = |
+ ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)); |
+ CodeStubArguments args(this, argc); |
+ Node* context = Parameter(BuiltinDescriptor::kContext); |
+ Node* new_target = Parameter(BuiltinDescriptor::kNewTarget); |
+ Node* receiver = args.GetReceiver(); |
+ Node* callbackfn = args.GetOptionalArgumentValue(0, UndefinedConstant()); |
+ Node* initial_value = args.GetOptionalArgumentValue(1, TheHoleConstant()); |
InitIteratingArrayBuiltinBody(context, receiver, callbackfn, initial_value, |
- new_target); |
+ new_target, argc); |
GenerateIteratingTypedArrayBuiltinBody( |
"%TypedArray%.prototype.reduce", |
@@ -1067,33 +1068,40 @@ TF_BUILTIN(ArrayReduceRightLoopContinuation, ArrayBuiltinCodeStubAssembler) { |
} |
TF_BUILTIN(ArrayReduceRight, ArrayBuiltinCodeStubAssembler) { |
- Node* context = Parameter(Descriptor::kContext); |
- Node* receiver = Parameter(Descriptor::kReceiver); |
- Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
- Node* initial_value = Parameter(Descriptor::kInitialValue); |
- Node* new_target = Parameter(Descriptor::kNewTarget); |
+ Node* argc = |
+ ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)); |
+ CodeStubArguments args(this, argc); |
+ Node* context = Parameter(BuiltinDescriptor::kContext); |
+ Node* new_target = Parameter(BuiltinDescriptor::kNewTarget); |
+ Node* receiver = args.GetReceiver(); |
+ Node* callbackfn = args.GetOptionalArgumentValue(0, UndefinedConstant()); |
+ Node* initial_value = args.GetOptionalArgumentValue(1, TheHoleConstant()); |
InitIteratingArrayBuiltinBody(context, receiver, callbackfn, initial_value, |
- new_target); |
+ new_target, argc); |
GenerateIteratingArrayBuiltinBody( |
"Array.prototype.reduceRight", |
&ArrayBuiltinCodeStubAssembler::ReduceResultGenerator, |
&ArrayBuiltinCodeStubAssembler::ReduceProcessor, |
&ArrayBuiltinCodeStubAssembler::ReducePostLoopAction, |
- CodeFactory::ArrayReduceRightLoopContinuation(isolate()), |
+ Builtins::CallableFor(isolate(), |
+ Builtins::kArrayReduceRightLoopContinuation), |
ForEachDirection::kReverse); |
} |
TF_BUILTIN(TypedArrayPrototypeReduceRight, ArrayBuiltinCodeStubAssembler) { |
- Node* context = Parameter(Descriptor::kContext); |
- Node* receiver = Parameter(Descriptor::kReceiver); |
- Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
- Node* initial_value = Parameter(Descriptor::kInitialValue); |
- Node* new_target = Parameter(Descriptor::kNewTarget); |
+ Node* argc = |
+ ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)); |
+ CodeStubArguments args(this, argc); |
+ Node* context = Parameter(BuiltinDescriptor::kContext); |
+ Node* new_target = Parameter(BuiltinDescriptor::kNewTarget); |
+ Node* receiver = args.GetReceiver(); |
+ Node* callbackfn = args.GetOptionalArgumentValue(0, UndefinedConstant()); |
+ Node* initial_value = args.GetOptionalArgumentValue(1, TheHoleConstant()); |
InitIteratingArrayBuiltinBody(context, receiver, callbackfn, initial_value, |
- new_target); |
+ new_target, argc); |
GenerateIteratingTypedArrayBuiltinBody( |
"%TypedArray%.prototype.reduceRight", |
@@ -1124,21 +1132,24 @@ TF_BUILTIN(ArrayFilterLoopContinuation, ArrayBuiltinCodeStubAssembler) { |
} |
TF_BUILTIN(ArrayFilter, ArrayBuiltinCodeStubAssembler) { |
- Node* context = Parameter(Descriptor::kContext); |
- Node* receiver = Parameter(Descriptor::kReceiver); |
- Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
- Node* this_arg = Parameter(Descriptor::kThisArg); |
- Node* new_target = Parameter(Descriptor::kNewTarget); |
+ Node* argc = |
+ ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)); |
+ CodeStubArguments args(this, argc); |
+ Node* context = Parameter(BuiltinDescriptor::kContext); |
+ Node* new_target = Parameter(BuiltinDescriptor::kNewTarget); |
+ Node* receiver = args.GetReceiver(); |
+ Node* callbackfn = args.GetOptionalArgumentValue(0, UndefinedConstant()); |
+ Node* this_arg = args.GetOptionalArgumentValue(1, UndefinedConstant()); |
InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg, |
- new_target); |
+ new_target, argc); |
GenerateIteratingArrayBuiltinBody( |
"Array.prototype.filter", |
&ArrayBuiltinCodeStubAssembler::FilterResultGenerator, |
&ArrayBuiltinCodeStubAssembler::FilterProcessor, |
&ArrayBuiltinCodeStubAssembler::NullPostLoopAction, |
- CodeFactory::ArrayFilterLoopContinuation(isolate())); |
+ Builtins::CallableFor(isolate(), Builtins::kArrayFilterLoopContinuation)); |
} |
TF_BUILTIN(ArrayMapLoopContinuation, ArrayBuiltinCodeStubAssembler) { |
@@ -1162,20 +1173,23 @@ TF_BUILTIN(ArrayMapLoopContinuation, ArrayBuiltinCodeStubAssembler) { |
} |
TF_BUILTIN(ArrayMap, ArrayBuiltinCodeStubAssembler) { |
- Node* context = Parameter(Descriptor::kContext); |
- Node* receiver = Parameter(Descriptor::kReceiver); |
- Node* callbackfn = Parameter(Descriptor::kCallbackFn); |
- Node* this_arg = Parameter(Descriptor::kThisArg); |
- Node* new_target = Parameter(Descriptor::kNewTarget); |
+ Node* argc = |
+ ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)); |
+ CodeStubArguments args(this, argc); |
+ Node* context = Parameter(BuiltinDescriptor::kContext); |
+ Node* new_target = Parameter(BuiltinDescriptor::kNewTarget); |
+ Node* receiver = args.GetReceiver(); |
+ Node* callbackfn = args.GetOptionalArgumentValue(0, UndefinedConstant()); |
+ Node* this_arg = args.GetOptionalArgumentValue(1, UndefinedConstant()); |
InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg, |
- new_target); |
+ new_target, argc); |
GenerateIteratingArrayBuiltinBody( |
"Array.prototype.map", &ArrayBuiltinCodeStubAssembler::MapResultGenerator, |
&ArrayBuiltinCodeStubAssembler::MapProcessor, |
&ArrayBuiltinCodeStubAssembler::NullPostLoopAction, |
- CodeFactory::ArrayMapLoopContinuation(isolate())); |
+ Builtins::CallableFor(isolate(), Builtins::kArrayMapLoopContinuation)); |
} |
TF_BUILTIN(ArrayIsArray, CodeStubAssembler) { |