Commit 4e668888 authored by bmeurer's avatar bmeurer Committed by Commit bot

[builtins] Also migrate String.prototype.toLowerCase/toUpperCase to C++.

These builtins always call into C++ anyways and so there's no point in
having the JavaScript wrapper around them, but instead they can be
implemented as C++ builtins directly.

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

Review-Url: https://codereview.chromium.org/2018983002
Cr-Commit-Position: refs/heads/master@{#36569}
parent b43ea19d
......@@ -1340,6 +1340,17 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
1, true);
SimpleInstallFunction(prototype, "charCodeAt",
Builtins::kStringPrototypeCharCodeAt, 1, true);
// TODO(bmeurer): One day we will want to install the correct i18n functions
// here directly instead of first installing the dummy, and overriding those
// in i18n.js later.
SimpleInstallFunction(prototype, "toLocaleLowerCase",
Builtins::kStringPrototypeToLowerCase, 0, false);
SimpleInstallFunction(prototype, "toLocaleUpperCase",
Builtins::kStringPrototypeToUpperCase, 0, false);
SimpleInstallFunction(prototype, "toLowerCase",
Builtins::kStringPrototypeToLowerCase, 0, false);
SimpleInstallFunction(prototype, "toUpperCase",
Builtins::kStringPrototypeToUpperCase, 0, false);
SimpleInstallFunction(prototype, "trim", Builtins::kStringPrototypeTrim, 0,
false);
SimpleInstallFunction(prototype, "trimLeft",
......
......@@ -4554,6 +4554,24 @@ void Builtins::Generate_StringPrototypeCharCodeAt(
assembler->Return(result);
}
// ES6 section 21.1.3.22 String.prototype.toLowerCase ( )
BUILTIN(StringPrototypeToLowerCase) {
HandleScope scope(isolate);
TO_THIS_STRING(string, "String.prototype.toLowerCase");
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, string,
String::ToLowerCase(string));
return *string;
}
// ES6 section 21.1.3.24 String.prototype.toUpperCase ( )
BUILTIN(StringPrototypeToUpperCase) {
HandleScope scope(isolate);
TO_THIS_STRING(string, "String.prototype.toUpperCase");
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, string,
String::ToUpperCase(string));
return *string;
}
// ES6 section 21.1.3.25 String.prototype.trim ()
BUILTIN(StringPrototypeTrim) {
HandleScope scope(isolate);
......
......@@ -172,6 +172,8 @@ inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) {
V(ReflectSetPrototypeOf, kNone) \
\
V(StringFromCharCode, kNone) \
V(StringPrototypeToLowerCase, kNone) \
V(StringPrototypeToUpperCase, kNone) \
V(StringPrototypeTrim, kNone) \
V(StringPrototypeTrimLeft, kNone) \
V(StringPrototypeTrimRight, kNone) \
......
......@@ -84,6 +84,8 @@ enum BindingFlags {
V(REFLECT_CONSTRUCT_INDEX, JSFunction, reflect_construct) \
V(REFLECT_DEFINE_PROPERTY_INDEX, JSFunction, reflect_define_property) \
V(REFLECT_DELETE_PROPERTY_INDEX, JSFunction, reflect_delete_property) \
V(STRING_TO_LOWER_CASE_INDEX, JSFunction, string_to_lower_case) \
V(STRING_TO_UPPER_CASE_INDEX, JSFunction, string_to_upper_case) \
V(SPREAD_ARGUMENTS_INDEX, JSFunction, spread_arguments) \
V(SPREAD_ITERABLE_INDEX, JSFunction, spread_iterable) \
V(MATH_FLOOR, JSFunction, math_floor) \
......
......@@ -46,6 +46,8 @@ var StringLastIndexOf;
var StringSplit;
var StringSubstr;
var StringSubstring;
var StringToLowerCase = GlobalString.prototype.toLowerCase;
var StringToUpperCase = GlobalString.prototype.toUpperCase;
utils.Import(function(from) {
ArrayIndexOf = from.ArrayIndexOf;
......@@ -693,8 +695,8 @@ function addWECPropertyIfDefined(object, property, value) {
* Returns titlecased word, aMeRricA -> America.
*/
function toTitleCaseWord(word) {
return %StringToUpperCase(%_Call(StringSubstr, word, 0, 1)) +
%StringToLowerCase(%_Call(StringSubstr, word, 1));
return %_Call(StringToUpperCase, %_Call(StringSubstr, word, 0, 1)) +
%_Call(StringToLowerCase, %_Call(StringSubstr, word, 1));
}
/**
......@@ -715,7 +717,7 @@ function toTitleCaseTimezoneLocation(location) {
var parts = %_Call(StringSplit, match[2], separator);
for (var i = 1; i < parts.length; i++) {
var part = parts[i]
var lowercasedPart = %StringToLowerCase(part);
var lowercasedPart = %_Call(StringToLowerCase, part);
result = result + separator +
((lowercasedPart !== 'es' &&
lowercasedPart !== 'of' && lowercasedPart !== 'au') ?
......@@ -1155,7 +1157,8 @@ function initializeNumberFormat(numberFormat, locales, options) {
var currencyDisplay = getOption(
'currencyDisplay', 'string', ['code', 'symbol', 'name'], 'symbol');
if (internalOptions.style === 'currency') {
defineWEProperty(internalOptions, 'currency', %StringToUpperCase(currency));
defineWEProperty(internalOptions, 'currency',
%_Call(StringToUpperCase, currency));
defineWEProperty(internalOptions, 'currencyDisplay', currencyDisplay);
}
......@@ -1789,7 +1792,7 @@ function canonicalizeTimeZoneID(tzID) {
}
// Special case handling (UTC, GMT).
var upperID = %StringToUpperCase(tzID);
var upperID = %_Call(StringToUpperCase, tzID);
if (upperID === 'UTC' || upperID === 'GMT' ||
upperID === 'ETC/UTC' || upperID === 'ETC/GMT') {
return 'UTC';
......
......@@ -487,38 +487,6 @@ function StringSubstr(start, n) {
}
// ECMA-262, 15.5.4.16
function StringToLowerCaseJS() {
CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLowerCase");
return %StringToLowerCase(TO_STRING(this));
}
// ECMA-262, 15.5.4.17
function StringToLocaleLowerCase() {
CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleLowerCase");
return %StringToLowerCase(TO_STRING(this));
}
// ECMA-262, 15.5.4.18
function StringToUpperCaseJS() {
CHECK_OBJECT_COERCIBLE(this, "String.prototype.toUpperCase");
return %StringToUpperCase(TO_STRING(this));
}
// ECMA-262, 15.5.4.19
function StringToLocaleUpperCase() {
CHECK_OBJECT_COERCIBLE(this, "String.prototype.toLocaleUpperCase");
return %StringToUpperCase(TO_STRING(this));
}
// ES6 draft, revision 26 (2014-07-18), section B.2.3.2.1
function HtmlEscape(str) {
return %_Call(StringReplace, TO_STRING(str), /"/g, "&quot;");
......@@ -827,10 +795,6 @@ utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [
"substring", StringSubstring,
"substr", StringSubstr,
"startsWith", StringStartsWith,
"toLowerCase", StringToLowerCaseJS,
"toLocaleLowerCase", StringToLocaleLowerCase,
"toUpperCase", StringToUpperCaseJS,
"toLocaleUpperCase", StringToLocaleUpperCase,
"link", StringLink,
"anchor", StringAnchor,
......
This diff is collapsed.
......@@ -8861,6 +8861,12 @@ class String: public Name {
// Conversion.
inline bool AsArrayIndex(uint32_t* index);
// Case conversion.
static MaybeHandle<String> ToLowerCase(Handle<String> string)
WARN_UNUSED_RESULT;
static MaybeHandle<String> ToUpperCase(Handle<String> string)
WARN_UNUSED_RESULT;
// Trimming.
enum TrimMode { kTrim, kTrimLeft, kTrimRight };
static Handle<String> Trim(Handle<String> string, TrimMode mode);
......
This diff is collapsed.
......@@ -829,8 +829,6 @@ namespace internal {
F(StringBuilderJoin, 3, 1) \
F(SparseJoinWithSeparator, 3, 1) \
F(StringToArray, 2, 1) \
F(StringToLowerCase, 1, 1) \
F(StringToUpperCase, 1, 1) \
F(StringLessThan, 2, 1) \
F(StringLessThanOrEqual, 2, 1) \
F(StringGreaterThan, 2, 1) \
......
......@@ -80,7 +80,7 @@ bytecodes: [
/* 15 S> */ B(LdrUndefined), R(0),
B(CreateArrayLiteral), U8(0), U8(0), U8(3),
B(Star), R(1),
B(CallJSRuntime), U8(122), R(0), U8(2),
B(CallJSRuntime), U8(124), R(0), U8(2),
/* 44 S> */ B(Return),
]
constant pool: [
......
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