Port StringPrototypeConcat to Torque

Bug: v8:8996
Change-Id: Icb454f8ff5f0964b019f360e71119158341307de
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1622743
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61756}
This commit is contained in:
Z Duong Nguyen-Huu 2019-05-22 09:49:51 -07:00 committed by Commit Bot
parent 5d0b4ad649
commit aaecb43329
3 changed files with 16 additions and 29 deletions

View File

@ -940,8 +940,6 @@ namespace internal {
CPP(StringFromCodePoint) \
/* ES6 #sec-string.fromcharcode */ \
TFJ(StringFromCharCode, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
/* ES6 #sec-string.prototype.concat */ \
TFJ(StringPrototypeConcat, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
/* ES6 #sec-string.prototype.includes */ \
TFJ(StringPrototypeIncludes, \
SharedFunctionInfo::kDontAdaptArgumentsSentinel) \

View File

@ -686,33 +686,6 @@ TF_BUILTIN(StringFromCharCode, CodeStubAssembler) {
}
}
// ES6 String.prototype.concat(...args)
// ES6 #sec-string.prototype.concat
TF_BUILTIN(StringPrototypeConcat, CodeStubAssembler) {
// TODO(ishell): use constants from Descriptor once the JSFunction linkage
// arguments are reordered.
CodeStubArguments arguments(
this,
ChangeInt32ToIntPtr(Parameter(Descriptor::kJSActualArgumentsCount)));
TNode<Object> receiver = arguments.GetReceiver();
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
// Check that {receiver} is coercible to Object and convert it to a String.
receiver = ToThisString(context, receiver, "String.prototype.concat");
// Concatenate all the arguments passed to this builtin.
VARIABLE(var_result, MachineRepresentation::kTagged);
var_result.Bind(receiver);
arguments.ForEach(
CodeStubAssembler::VariableList({&var_result}, zone()),
[this, context, &var_result](Node* arg) {
arg = ToString_Inline(context, arg);
var_result.Bind(CallStub(CodeFactory::StringAdd(isolate()), context,
var_result.value(), arg));
});
arguments.PopAndReturn(var_result.value());
}
void StringBuiltinsAssembler::StringIndexOf(
Node* const subject_string, Node* const search_string, Node* const position,
const std::function<void(Node*)>& f_return) {

View File

@ -117,4 +117,20 @@ namespace string {
return Undefined;
}
}
// ES6 String.prototype.concat(...args)
// ES6 #sec-string.prototype.concat
transitioning javascript builtin StringPrototypeConcat(
implicit context: Context)(receiver: Object, ...arguments): Object {
// Check that {receiver} is coercible to Object and convert it to a String.
let string: String = ToThisString(receiver, 'String.prototype.concat');
// Concatenate all the arguments passed to this builtin.
const length: intptr = Convert<intptr>(arguments.length);
for (let i: intptr = 0; i < length; i++) {
const temp: String = ToString_Inline(context, arguments[i]);
string = string + temp;
}
return string;
}
}