Commit 0a7d3138 authored by bmeurer's avatar bmeurer Committed by Commit bot

[csa] Migrate String.prototype.concat to TurboFan builtin.

R=yangguo@chromium.org
BUG=v8:5049

Review-Url: https://codereview.chromium.org/2766593002
Cr-Commit-Position: refs/heads/master@{#43961}
parent 7a905861
......@@ -1688,6 +1688,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
1, true);
SimpleInstallFunction(prototype, "charCodeAt",
Builtins::kStringPrototypeCharCodeAt, 1, true);
SimpleInstallFunction(prototype, "concat", Builtins::kStringPrototypeConcat,
1, false);
SimpleInstallFunction(prototype, "endsWith",
Builtins::kStringPrototypeEndsWith, 1, false);
SimpleInstallFunction(prototype, "includes",
......
......@@ -662,6 +662,30 @@ TF_BUILTIN(StringPrototypeCharCodeAt, CodeStubAssembler) {
Return(result);
}
// ES6 String.prototype.concat(...args)
// #sec-string.prototype.concat
TF_BUILTIN(StringPrototypeConcat, CodeStubAssembler) {
CodeStubArguments arguments(
this, ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount)));
Node* receiver = arguments.GetReceiver();
Node* context = Parameter(BuiltinDescriptor::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(this, MachineRepresentation::kTagged);
var_result.Bind(receiver);
arguments.ForEach(
CodeStubAssembler::VariableList({&var_result}, zone()),
[this, context, &var_result](Node* arg) {
arg = CallStub(CodeFactory::ToString(isolate()), context, arg);
var_result.Bind(CallStub(CodeFactory::StringAdd(isolate()), context,
var_result.value(), arg));
});
arguments.PopAndReturn(var_result.value());
}
void StringBuiltinsAssembler::StringIndexOf(
Node* receiver, Node* instance_type, Node* search_string,
Node* search_string_instance_type, Node* position,
......
......@@ -774,6 +774,8 @@ class Isolate;
TFJ(StringPrototypeCharAt, 1) \
/* ES6 section 21.1.3.2 String.prototype.charCodeAt ( pos ) */ \
TFJ(StringPrototypeCharCodeAt, 1) \
/* ES6 #sec-string.prototype.concat */ \
TFJ(StringPrototypeConcat, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
/* ES6 section 21.1.3.6 */ \
/* String.prototype.endsWith ( searchString [ , endPosition ] ) */ \
CPP(StringPrototypeEndsWith) \
......
......@@ -108,8 +108,9 @@ class V8_EXPORT_PRIVATE CodeFactory final {
static Callable Equal(Isolate* isolate);
static Callable StrictEqual(Isolate* isolate);
static Callable StringAdd(Isolate* isolate, StringAddFlags flags,
PretenureFlag pretenure_flag);
static Callable StringAdd(Isolate* isolate,
StringAddFlags flags = STRING_ADD_CHECK_NONE,
PretenureFlag pretenure_flag = NOT_TENURED);
static Callable StringCharAt(Isolate* isolate);
static Callable StringCharCodeAt(Isolate* isolate);
static Callable StringCompare(Isolate* isolate, Token::Value token);
......
......@@ -524,6 +524,7 @@ bool BuiltinHasNoSideEffect(Builtins::Name id) {
case Builtins::kStringConstructor:
case Builtins::kStringPrototypeCharAt:
case Builtins::kStringPrototypeCharCodeAt:
case Builtins::kStringPrototypeConcat:
case Builtins::kStringPrototypeEndsWith:
case Builtins::kStringPrototypeIncludes:
case Builtins::kStringPrototypeIndexOf:
......
......@@ -15,19 +15,6 @@ var searchSymbol = utils.ImportNow("search_symbol");
//-------------------------------------------------------------------
// ECMA-262, section 15.5.4.6
function StringConcat(other /* and more */) { // length == 1
"use strict";
CHECK_OBJECT_COERCIBLE(this, "String.prototype.concat");
var s = TO_STRING(this);
var len = arguments.length;
for (var i = 0; i < len; ++i) {
s = s + TO_STRING(arguments[i]);
}
return s;
}
// ES6 21.1.3.11.
function StringMatchJS(pattern) {
CHECK_OBJECT_COERCIBLE(this, "String.prototype.match");
......@@ -288,7 +275,6 @@ utils.InstallFunctions(GlobalString, DONT_ENUM, [
// Set up the non-enumerable functions on the String prototype object.
utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [
"codePointAt", StringCodePointAt,
"concat", StringConcat,
"match", StringMatchJS,
"repeat", StringRepeat,
"search", StringSearch,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment