Commit 4a5d1e25 authored by jwolfe's avatar jwolfe Committed by Commit bot

Migrate String.prototype.to{Upper,Lower}Case functions from JS to CPP builtins.

Move ICU case conversion utility functions to a common location.

BUG=v8:5751
CQ_INCLUDE_TRYBOTS=master.tryserver.v8:v8_linux_noi18n_rel_ng

Review-Url: https://codereview.chromium.org/2728763006
Cr-Commit-Position: refs/heads/master@{#44050}
parent ff1a155a
......@@ -1115,6 +1115,7 @@ v8_source_set("v8_base") {
"src/builtins/builtins-global.cc",
"src/builtins/builtins-internal.cc",
"src/builtins/builtins-interpreter.cc",
"src/builtins/builtins-intl.cc",
"src/builtins/builtins-json.cc",
"src/builtins/builtins-math.cc",
"src/builtins/builtins-number.cc",
......
......@@ -3890,21 +3890,22 @@ void Genesis::InitializeGlobal_icu_case_mapping() {
Handle<JSObject> string_prototype(
JSObject::cast(native_context()->string_function()->prototype()));
Handle<JSFunction> to_lower_case = Handle<JSFunction>::cast(
JSReceiver::GetProperty(
exports_container,
factory()->InternalizeUtf8String("ToLowerCaseI18N"))
.ToHandleChecked());
SetFunction(string_prototype, to_lower_case,
factory()->InternalizeUtf8String("toLowerCase"));
Handle<JSFunction> to_upper_case = Handle<JSFunction>::cast(
JSReceiver::GetProperty(
exports_container,
factory()->InternalizeUtf8String("ToUpperCaseI18N"))
.ToHandleChecked());
SetFunction(string_prototype, to_upper_case,
factory()->InternalizeUtf8String("toUpperCase"));
{
Handle<String> name = factory()->InternalizeUtf8String("toLowerCase");
SetFunction(string_prototype,
SimpleCreateFunction(isolate(), name,
Builtins::kStringPrototypeToLowerCaseI18N,
0, false),
name);
}
{
Handle<String> name = factory()->InternalizeUtf8String("toUpperCase");
SetFunction(string_prototype,
SimpleCreateFunction(isolate(), name,
Builtins::kStringPrototypeToUpperCaseI18N,
0, false),
name);
}
Handle<JSFunction> to_locale_lower_case = Handle<JSFunction>::cast(
JSReceiver::GetProperty(
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef V8_I18N_SUPPORT
#include "src/builtins/builtins-utils.h"
#include "src/builtins/builtins.h"
#include "src/i18n.h"
#include "src/objects-inl.h"
namespace v8 {
namespace internal {
BUILTIN(StringPrototypeToLowerCaseI18N) {
HandleScope scope(isolate);
TO_THIS_STRING(string, "String.prototype.toLowerCase");
string = String::Flatten(string);
return ConvertCase(string, false, isolate);
}
BUILTIN(StringPrototypeToUpperCaseI18N) {
HandleScope scope(isolate);
TO_THIS_STRING(string, "String.prototype.toUpperCase");
string = String::Flatten(string);
return ConvertCase(string, true, isolate);
}
} // namespace internal
} // namespace v8
#endif // V8_I18N_SUPPORT
......@@ -51,7 +51,7 @@ class Isolate;
// DBG: Builtin in platform-dependent assembly, used by the debugger.
// Args: name
#define BUILTIN_LIST(CPP, API, TFJ, TFS, ASM, ASH, DBG) \
#define BUILTIN_LIST_BASE(CPP, API, TFJ, TFS, ASM, ASH, DBG) \
ASM(Abort) \
/* Code aging */ \
CODE_AGE_LIST_WITH_ARG(DECLARE_CODE_AGE_BUILTIN, ASM) \
......@@ -845,9 +845,9 @@ class Isolate;
CPP(StringPrototypeToLocaleLowerCase) \
/* ES #sec-string.prototype.tolocaleuppercase */ \
CPP(StringPrototypeToLocaleUpperCase) \
/* ES #sec-string.prototype.tolowercase */ \
/* (obsolete) Unibrow version */ \
CPP(StringPrototypeToLowerCase) \
/* ES #sec-string.prototype.touppercase */ \
/* (obsolete) Unibrow version */ \
CPP(StringPrototypeToUpperCase) \
CPP(StringPrototypeTrim) \
CPP(StringPrototypeTrimLeft) \
......@@ -936,6 +936,19 @@ class Isolate;
/* #sec-async-iterator-value-unwrap-functions */ \
TFJ(AsyncIteratorValueUnwrap, 1, kValue)
#ifdef V8_I18N_SUPPORT
#define BUILTIN_LIST(CPP, API, TFJ, TFS, ASM, ASH, DBG) \
BUILTIN_LIST_BASE(CPP, API, TFJ, TFS, ASM, ASH, DBG) \
\
/* ES #sec-string.prototype.tolowercase */ \
CPP(StringPrototypeToLowerCaseI18N) \
/* ES #sec-string.prototype.touppercase */ \
CPP(StringPrototypeToUpperCaseI18N)
#else
#define BUILTIN_LIST(CPP, API, TFJ, TFS, ASM, ASH, DBG) \
BUILTIN_LIST_BASE(CPP, API, TFJ, TFS, ASM, ASH, DBG)
#endif // V8_I18N_SUPPORT
#define BUILTIN_PROMISE_REJECTION_PREDICTION_LIST(V) \
V(AsyncFromSyncIteratorPrototypeNext) \
V(AsyncFromSyncIteratorPrototypeReturn) \
......
This diff is collapsed.
......@@ -128,6 +128,16 @@ class V8BreakIterator {
V8BreakIterator();
};
const UChar* GetUCharBufferFromFlat(const String::FlatContent& flat,
std::unique_ptr<uc16[]>* dest,
int32_t length);
MUST_USE_RESULT Object* LocaleConvertCase(Handle<String> s, Isolate* isolate,
bool is_to_upper, const char* lang);
MUST_USE_RESULT Object* ConvertToLower(Handle<String> s, Isolate* isolate);
MUST_USE_RESULT Object* ConvertToUpper(Handle<String> s, Isolate* isolate);
MUST_USE_RESULT Object* ConvertCase(Handle<String> s, bool is_upper,
Isolate* isolate);
} // namespace internal
} // namespace v8
......
This diff is collapsed.
......@@ -527,6 +527,7 @@
'builtins/builtins-sharedarraybuffer-gen.cc',
'builtins/builtins-string.cc',
'builtins/builtins-string-gen.cc',
'builtins/builtins-intl.cc',
'builtins/builtins-symbol.cc',
'builtins/builtins-symbol-gen.cc',
'builtins/builtins-typedarray.cc',
......
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