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") { ...@@ -1115,6 +1115,7 @@ v8_source_set("v8_base") {
"src/builtins/builtins-global.cc", "src/builtins/builtins-global.cc",
"src/builtins/builtins-internal.cc", "src/builtins/builtins-internal.cc",
"src/builtins/builtins-interpreter.cc", "src/builtins/builtins-interpreter.cc",
"src/builtins/builtins-intl.cc",
"src/builtins/builtins-json.cc", "src/builtins/builtins-json.cc",
"src/builtins/builtins-math.cc", "src/builtins/builtins-math.cc",
"src/builtins/builtins-number.cc", "src/builtins/builtins-number.cc",
......
...@@ -3890,21 +3890,22 @@ void Genesis::InitializeGlobal_icu_case_mapping() { ...@@ -3890,21 +3890,22 @@ void Genesis::InitializeGlobal_icu_case_mapping() {
Handle<JSObject> string_prototype( Handle<JSObject> string_prototype(
JSObject::cast(native_context()->string_function()->prototype())); JSObject::cast(native_context()->string_function()->prototype()));
Handle<JSFunction> to_lower_case = Handle<JSFunction>::cast( {
JSReceiver::GetProperty( Handle<String> name = factory()->InternalizeUtf8String("toLowerCase");
exports_container, SetFunction(string_prototype,
factory()->InternalizeUtf8String("ToLowerCaseI18N")) SimpleCreateFunction(isolate(), name,
.ToHandleChecked()); Builtins::kStringPrototypeToLowerCaseI18N,
SetFunction(string_prototype, to_lower_case, 0, false),
factory()->InternalizeUtf8String("toLowerCase")); name);
}
Handle<JSFunction> to_upper_case = Handle<JSFunction>::cast( {
JSReceiver::GetProperty( Handle<String> name = factory()->InternalizeUtf8String("toUpperCase");
exports_container, SetFunction(string_prototype,
factory()->InternalizeUtf8String("ToUpperCaseI18N")) SimpleCreateFunction(isolate(), name,
.ToHandleChecked()); Builtins::kStringPrototypeToUpperCaseI18N,
SetFunction(string_prototype, to_upper_case, 0, false),
factory()->InternalizeUtf8String("toUpperCase")); name);
}
Handle<JSFunction> to_locale_lower_case = Handle<JSFunction>::cast( Handle<JSFunction> to_locale_lower_case = Handle<JSFunction>::cast(
JSReceiver::GetProperty( 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; ...@@ -51,7 +51,7 @@ class Isolate;
// DBG: Builtin in platform-dependent assembly, used by the debugger. // DBG: Builtin in platform-dependent assembly, used by the debugger.
// Args: name // 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) \ ASM(Abort) \
/* Code aging */ \ /* Code aging */ \
CODE_AGE_LIST_WITH_ARG(DECLARE_CODE_AGE_BUILTIN, ASM) \ CODE_AGE_LIST_WITH_ARG(DECLARE_CODE_AGE_BUILTIN, ASM) \
...@@ -845,9 +845,9 @@ class Isolate; ...@@ -845,9 +845,9 @@ class Isolate;
CPP(StringPrototypeToLocaleLowerCase) \ CPP(StringPrototypeToLocaleLowerCase) \
/* ES #sec-string.prototype.tolocaleuppercase */ \ /* ES #sec-string.prototype.tolocaleuppercase */ \
CPP(StringPrototypeToLocaleUpperCase) \ CPP(StringPrototypeToLocaleUpperCase) \
/* ES #sec-string.prototype.tolowercase */ \ /* (obsolete) Unibrow version */ \
CPP(StringPrototypeToLowerCase) \ CPP(StringPrototypeToLowerCase) \
/* ES #sec-string.prototype.touppercase */ \ /* (obsolete) Unibrow version */ \
CPP(StringPrototypeToUpperCase) \ CPP(StringPrototypeToUpperCase) \
CPP(StringPrototypeTrim) \ CPP(StringPrototypeTrim) \
CPP(StringPrototypeTrimLeft) \ CPP(StringPrototypeTrimLeft) \
...@@ -936,6 +936,19 @@ class Isolate; ...@@ -936,6 +936,19 @@ class Isolate;
/* #sec-async-iterator-value-unwrap-functions */ \ /* #sec-async-iterator-value-unwrap-functions */ \
TFJ(AsyncIteratorValueUnwrap, 1, kValue) 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) \ #define BUILTIN_PROMISE_REJECTION_PREDICTION_LIST(V) \
V(AsyncFromSyncIteratorPrototypeNext) \ V(AsyncFromSyncIteratorPrototypeNext) \
V(AsyncFromSyncIteratorPrototypeReturn) \ V(AsyncFromSyncIteratorPrototypeReturn) \
......
This diff is collapsed.
...@@ -128,6 +128,16 @@ class V8BreakIterator { ...@@ -128,6 +128,16 @@ class V8BreakIterator {
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 internal
} // namespace v8 } // namespace v8
......
This diff is collapsed.
...@@ -527,6 +527,7 @@ ...@@ -527,6 +527,7 @@
'builtins/builtins-sharedarraybuffer-gen.cc', 'builtins/builtins-sharedarraybuffer-gen.cc',
'builtins/builtins-string.cc', 'builtins/builtins-string.cc',
'builtins/builtins-string-gen.cc', 'builtins/builtins-string-gen.cc',
'builtins/builtins-intl.cc',
'builtins/builtins-symbol.cc', 'builtins/builtins-symbol.cc',
'builtins/builtins-symbol-gen.cc', 'builtins/builtins-symbol-gen.cc',
'builtins/builtins-typedarray.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