Commit c4311e52 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Remove intl.(h|cc)

Fold methods from intl.* to objects/intl-objects.*
Move Isolate* to the first parameter for some method
Move ICUSerice type under Intl
Hide ICUTimeZoneCache under a CreateTimeZoneCache factory method.

Bug: v8:5751
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: Ie6f6a1ceee789333a077c1965de8e11d8c15c175
Reviewed-on: https://chromium-review.googlesource.com/c/1293109
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56873}
parent 66daabcc
......@@ -2150,8 +2150,6 @@ v8_source_set("v8_base") {
"src/interpreter/interpreter-intrinsics.h",
"src/interpreter/interpreter.cc",
"src/interpreter/interpreter.h",
"src/intl.cc",
"src/intl.h",
"src/isolate-data.h",
"src/isolate-inl.h",
"src/isolate.cc",
......@@ -2976,8 +2974,6 @@ v8_source_set("v8_base") {
sources -= [
"src/builtins/builtins-intl.cc",
"src/char-predicates.cc",
"src/intl.cc",
"src/intl.h",
"src/objects/intl-objects.cc",
"src/objects/intl-objects.h",
"src/objects/js-break-iterator-inl.h",
......
......@@ -14,7 +14,6 @@
#include "src/builtins/builtins.h"
#include "src/date.h"
#include "src/elements.h"
#include "src/intl.h"
#include "src/objects-inl.h"
#include "src/objects/intl-objects.h"
#include "src/objects/js-array-inl.h"
......@@ -50,7 +49,7 @@ BUILTIN(StringPrototypeToUpperCaseIntl) {
HandleScope scope(isolate);
TO_THIS_STRING(string, "String.prototype.toUpperCase");
string = String::Flatten(isolate, string);
RETURN_RESULT_OR_FAILURE(isolate, ConvertCase(string, true, isolate));
RETURN_RESULT_OR_FAILURE(isolate, Intl::ConvertToUpper(isolate, string));
}
BUILTIN(StringPrototypeNormalizeIntl) {
......@@ -98,27 +97,22 @@ BUILTIN(StringPrototypeNormalizeIntl) {
icu::UnicodeString result;
std::unique_ptr<uc16[]> sap;
UErrorCode status = U_ZERO_ERROR;
{
DisallowHeapAllocation no_gc;
String::FlatContent flat = string->GetFlatContent();
const UChar* src = GetUCharBufferFromFlat(flat, &sap, length);
icu::UnicodeString input(false, src, length);
// Getting a singleton. Should not free it.
const icu::Normalizer2* normalizer =
icu::Normalizer2::getInstance(nullptr, form_name, form_mode, status);
DCHECK(U_SUCCESS(status));
CHECK_NOT_NULL(normalizer);
int32_t normalized_prefix_length =
normalizer->spanQuickCheckYes(input, status);
// Quick return if the input is already normalized.
if (length == normalized_prefix_length) return *string;
icu::UnicodeString unnormalized =
input.tempSubString(normalized_prefix_length);
// Read-only alias of the normalized prefix.
result.setTo(false, input.getBuffer(), normalized_prefix_length);
// copy-on-write; normalize the suffix and append to |result|.
normalizer->normalizeSecondAndAppend(result, unnormalized, status);
}
icu::UnicodeString input = Intl::ToICUUnicodeString(isolate, string);
// Getting a singleton. Should not free it.
const icu::Normalizer2* normalizer =
icu::Normalizer2::getInstance(nullptr, form_name, form_mode, status);
DCHECK(U_SUCCESS(status));
CHECK_NOT_NULL(normalizer);
int32_t normalized_prefix_length =
normalizer->spanQuickCheckYes(input, status);
// Quick return if the input is already normalized.
if (length == normalized_prefix_length) return *string;
icu::UnicodeString unnormalized =
input.tempSubString(normalized_prefix_length);
// Read-only alias of the normalized prefix.
result.setTo(false, input.getBuffer(), normalized_prefix_length);
// copy-on-write; normalize the suffix and append to |result|.
normalizer->normalizeSecondAndAppend(result, unnormalized, status);
if (U_FAILURE(status)) {
THROW_NEW_ERROR_RETURN_FAILURE(isolate,
......@@ -137,8 +131,9 @@ BUILTIN(V8BreakIteratorSupportedLocalesOf) {
Handle<Object> options = args.atOrUndefined(isolate, 2);
RETURN_RESULT_OR_FAILURE(
isolate, Intl::SupportedLocalesOf(isolate, ICUService::kBreakIterator,
locales, options));
isolate,
Intl::SupportedLocalesOf(isolate, Intl::ICUService::kBreakIterator,
locales, options));
}
BUILTIN(NumberFormatSupportedLocalesOf) {
......@@ -147,8 +142,8 @@ BUILTIN(NumberFormatSupportedLocalesOf) {
Handle<Object> options = args.atOrUndefined(isolate, 2);
RETURN_RESULT_OR_FAILURE(
isolate, Intl::SupportedLocalesOf(isolate, ICUService::kNumberFormat,
locales, options));
isolate, Intl::SupportedLocalesOf(
isolate, Intl::ICUService::kNumberFormat, locales, options));
}
BUILTIN(NumberFormatPrototypeFormatToParts) {
......@@ -189,7 +184,7 @@ BUILTIN(DateTimeFormatSupportedLocalesOf) {
Handle<Object> options = args.atOrUndefined(isolate, 2);
RETURN_RESULT_OR_FAILURE(
isolate, Intl::SupportedLocalesOf(isolate, ICUService::kDateFormat,
isolate, Intl::SupportedLocalesOf(isolate, Intl::ICUService::kDateFormat,
locales, options));
}
......@@ -540,8 +535,9 @@ BUILTIN(ListFormatSupportedLocalesOf) {
Handle<Object> options = args.atOrUndefined(isolate, 2);
RETURN_RESULT_OR_FAILURE(
isolate, Intl::SupportedLocalesOf(isolate, ICUService::kListFormatter,
locales, options));
isolate,
Intl::SupportedLocalesOf(isolate, Intl::ICUService::kListFormatter,
locales, options));
}
namespace {
......@@ -647,9 +643,9 @@ BUILTIN(RelativeTimeFormatSupportedLocalesOf) {
Handle<Object> options = args.atOrUndefined(isolate, 2);
RETURN_RESULT_OR_FAILURE(
isolate,
Intl::SupportedLocalesOf(isolate, ICUService::kRelativeDateTimeFormatter,
locales, options));
isolate, Intl::SupportedLocalesOf(
isolate, Intl::ICUService::kRelativeDateTimeFormatter,
locales, options));
}
BUILTIN(RelativeTimeFormatPrototypeFormat) {
......@@ -911,7 +907,7 @@ BUILTIN(PluralRulesSupportedLocalesOf) {
Handle<Object> options = args.atOrUndefined(isolate, 2);
RETURN_RESULT_OR_FAILURE(
isolate, Intl::SupportedLocalesOf(isolate, ICUService::kPluralRules,
isolate, Intl::SupportedLocalesOf(isolate, Intl::ICUService::kPluralRules,
locales, options));
}
......@@ -961,8 +957,8 @@ BUILTIN(CollatorSupportedLocalesOf) {
Handle<Object> options = args.atOrUndefined(isolate, 2);
RETURN_RESULT_OR_FAILURE(
isolate, Intl::SupportedLocalesOf(isolate, ICUService::kCollator, locales,
options));
isolate, Intl::SupportedLocalesOf(isolate, Intl::ICUService::kCollator,
locales, options));
}
BUILTIN(CollatorPrototypeCompare) {
......@@ -1117,7 +1113,7 @@ BUILTIN(SegmenterSupportedLocalesOf) {
Handle<Object> options = args.atOrUndefined(isolate, 2);
RETURN_RESULT_OR_FAILURE(
isolate, Intl::SupportedLocalesOf(isolate, ICUService::kSegmenter,
isolate, Intl::SupportedLocalesOf(isolate, Intl::ICUService::kSegmenter,
locales, options));
}
......
......@@ -6,11 +6,10 @@
#include "src/conversions.h"
#include "src/objects-inl.h"
#include "src/objects.h"
#ifdef V8_INTL_SUPPORT
#include "src/intl.h"
#include "src/objects/intl-objects.h"
#endif
#include "src/objects.h"
namespace v8 {
namespace internal {
......@@ -30,8 +29,7 @@ DateCache::DateCache()
: stamp_(nullptr),
tz_cache_(
#ifdef V8_INTL_SUPPORT
FLAG_icu_timezone_data ? new ICUTimezoneCache()
: base::OS::CreateTimezoneCache()
Intl::CreateTimeZoneCache()
#else
base::OS::CreateTimezoneCache()
#endif
......
......@@ -47,7 +47,7 @@
#endif // V8_INTERPRETED_REGEXP
#ifdef V8_INTL_SUPPORT
#include "src/intl.h"
#include "src/objects/intl-objects.h"
#endif // V8_INTL_SUPPORT
namespace v8 {
......@@ -815,11 +815,12 @@ ExternalReference ExternalReference::check_object_type() {
#ifdef V8_INTL_SUPPORT
ExternalReference ExternalReference::intl_convert_one_byte_to_lower() {
return ExternalReference(Redirect(FUNCTION_ADDR(ConvertOneByteToLower)));
return ExternalReference(
Redirect(FUNCTION_ADDR(Intl::ConvertOneByteToLower)));
}
ExternalReference ExternalReference::intl_to_latin1_lower_table() {
uint8_t* ptr = const_cast<uint8_t*>(ToLatin1LowerTable());
uint8_t* ptr = const_cast<uint8_t*>(Intl::ToLatin1LowerTable());
return ExternalReference(reinterpret_cast<Address>(ptr));
}
#endif // V8_INTL_SUPPORT
......
This diff is collapsed.
// Copyright 2013 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.
#ifndef V8_INTL_SUPPORT
#error Internationalization is expected to be enabled.
#endif // V8_INTL_SUPPORT
#ifndef V8_INTL_H_
#define V8_INTL_H_
#include <string>
#include "src/base/timezone-cache.h"
#include "src/objects.h"
#include "src/objects/string.h"
#include "unicode/uversion.h"
namespace U_ICU_NAMESPACE {
class TimeZone;
}
namespace v8 {
namespace internal {
enum class ICUService {
kBreakIterator,
kCollator,
kDateFormat,
kNumberFormat,
kPluralRules,
kRelativeDateTimeFormatter,
kListFormatter,
kSegmenter
};
const UChar* GetUCharBufferFromFlat(const String::FlatContent& flat,
std::unique_ptr<uc16[]>* dest,
int32_t length);
MaybeHandle<String> LocaleConvertCase(Handle<String> s, Isolate* isolate,
bool is_to_upper, const char* lang);
MaybeHandle<String> ConvertToLower(Handle<String> s, Isolate* isolate);
MaybeHandle<String> ConvertToUpper(Handle<String> s, Isolate* isolate);
MaybeHandle<String> ConvertCase(Handle<String> s, bool is_upper,
Isolate* isolate);
V8_WARN_UNUSED_RESULT String* ConvertOneByteToLower(String* src, String* dst);
const uint8_t* ToLatin1LowerTable();
// ICUTimezoneCache calls out to ICU for TimezoneCache
// functionality in a straightforward way.
class ICUTimezoneCache : public base::TimezoneCache {
public:
ICUTimezoneCache();
~ICUTimezoneCache() override;
const char* LocalTimezone(double time_ms) override;
double DaylightSavingsOffset(double time_ms) override;
double LocalTimeOffset(double time_ms, bool is_utc) override;
void Clear() override;
private:
icu::TimeZone* GetTimeZone();
bool GetOffsets(double time_ms, bool is_utc, int32_t* raw_offset,
int32_t* dst_offset);
icu::TimeZone* timezone_;
std::string timezone_name_;
std::string dst_timezone_name_;
};
} // namespace internal
} // namespace v8
#endif // V8_INTL_H_
This diff is collapsed.
......@@ -13,8 +13,8 @@
#include <set>
#include <string>
#include "src/base/timezone-cache.h"
#include "src/contexts.h"
#include "src/intl.h"
#include "src/objects.h"
#include "src/objects/managed.h"
#include "unicode/locid.h"
......@@ -41,6 +41,17 @@ class Intl {
kLength
};
enum class ICUService {
kBreakIterator,
kCollator,
kDateFormat,
kNumberFormat,
kPluralRules,
kRelativeDateTimeFormatter,
kListFormatter,
kSegmenter
};
// Gets the ICU locales for a given service. If there is a locale with a
// script tag then the locales also include a locale without the script; eg,
// pa_Guru_IN (language=Panjabi, script=Gurmukhi, country-India) would include
......@@ -117,6 +128,12 @@ class Intl {
Isolate* isolate, Handle<String> s, bool is_upper,
Handle<Object> locales);
V8_WARN_UNUSED_RESULT static MaybeHandle<String> ConvertToUpper(
Isolate* isolate, Handle<String> s);
V8_WARN_UNUSED_RESULT static MaybeHandle<String> ConvertToLower(
Isolate* isolate, Handle<String> s);
V8_WARN_UNUSED_RESULT static MaybeHandle<Object> StringLocaleCompare(
Isolate* isolate, Handle<String> s1, Handle<String> s2,
Handle<Object> locales, Handle<Object> options);
......@@ -198,6 +215,16 @@ class Intl {
static Managed<icu::UnicodeString>* SetTextToBreakIterator(
Isolate* isolate, Handle<String> text,
icu::BreakIterator* break_iterator);
static base::TimezoneCache* CreateTimeZoneCache();
// Convert a Handle<String> to icu::UnicodeString
static icu::UnicodeString ToICUUnicodeString(Isolate* isolate,
Handle<String> string);
static const uint8_t* ToLatin1LowerTable();
static String* ConvertOneByteToLower(String* src, String* dst);
};
} // namespace internal
......
......@@ -60,7 +60,7 @@ MaybeHandle<JSV8BreakIterator> JSV8BreakIterator::Initialize(
}
}
std::set<std::string> available_locales =
Intl::GetAvailableLocales(ICUService::kBreakIterator);
Intl::GetAvailableLocales(Intl::ICUService::kBreakIterator);
Intl::ResolvedLocale r = Intl::ResolveLocale(isolate, available_locales,
requested_locales, matcher, {});
......
......@@ -309,7 +309,7 @@ MaybeHandle<JSCollator> JSCollator::Initialize(Isolate* isolate,
// requestedLocales, opt, %Collator%.[[RelevantExtensionKeys]],
// localeData).
std::set<std::string> available_locales =
Intl::GetAvailableLocales(ICUService::kCollator);
Intl::GetAvailableLocales(Intl::ICUService::kCollator);
Intl::ResolvedLocale r =
Intl::ResolveLocale(isolate, available_locales, requested_locales,
matcher, relevant_extension_keys);
......
......@@ -785,7 +785,7 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::Initialize(
// requestedLocales, opt, %DateTimeFormat%.[[RelevantExtensionKeys]],
// localeData).
std::set<std::string> available_locales =
Intl::GetAvailableLocales(ICUService::kDateFormat);
Intl::GetAvailableLocales(Intl::ICUService::kDateFormat);
Intl::ResolvedLocale r = Intl::ResolveLocale(
isolate, available_locales, requested_locales, locale_matcher, {"nu"});
......
......@@ -203,7 +203,7 @@ MaybeHandle<JSListFormat> JSListFormat::Initialize(
// 15. Let r be ResolveLocale(%ListFormat%.[[AvailableLocales]],
// requestedLocales, opt, undefined, localeData).
std::set<std::string> available_locales =
Intl::GetAvailableLocales(ICUService::kListFormatter);
Intl::GetAvailableLocales(Intl::ICUService::kListFormatter);
Intl::ResolvedLocale r = Intl::ResolveLocale(isolate, available_locales,
requested_locales, matcher, {});
......@@ -353,13 +353,7 @@ Maybe<bool> ToUnicodeStringArray(Isolate* isolate, Handle<JSArray> array,
}
for (uint32_t i = 0; i < length; i++) {
Handle<String> string = Handle<String>::cast(accessor->Get(array, i));
DisallowHeapAllocation no_gc;
string = String::Flatten(isolate, string);
std::unique_ptr<uc16[]> sap;
items[i] =
icu::UnicodeString(GetUCharBufferFromFlat(string->GetFlatContent(),
&sap, string->length()),
string->length());
items[i] = Intl::ToICUUnicodeString(isolate, string);
}
return Just(true);
}
......
......@@ -235,7 +235,7 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize(
// requestedLocales, opt, %NumberFormat%.[[RelevantExtensionKeys]],
// localeData).
std::set<std::string> available_locales =
Intl::GetAvailableLocales(ICUService::kNumberFormat);
Intl::GetAvailableLocales(Intl::ICUService::kNumberFormat);
std::set<std::string> relevant_extension_keys{"nu"};
Intl::ResolvedLocale r =
Intl::ResolveLocale(isolate, available_locales, requested_locales,
......
......@@ -152,7 +152,7 @@ MaybeHandle<JSPluralRules> JSPluralRules::Initialize(
// requestedLocales, opt, %PluralRules%.[[RelevantExtensionKeys]],
// localeData).
std::set<std::string> available_locales =
Intl::GetAvailableLocales(ICUService::kPluralRules);
Intl::GetAvailableLocales(Intl::ICUService::kPluralRules);
Intl::ResolvedLocale r = Intl::ResolveLocale(isolate, available_locales,
requested_locales, matcher, {});
......
......@@ -103,7 +103,7 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::Initialize(
// requestedLocales, opt,
// %RelativeTimeFormat%.[[RelevantExtensionKeys]], localeData).
std::set<std::string> available_locales =
Intl::GetAvailableLocales(ICUService::kRelativeDateTimeFormatter);
Intl::GetAvailableLocales(Intl::ICUService::kRelativeDateTimeFormatter);
Intl::ResolvedLocale r = Intl::ResolveLocale(isolate, available_locales,
requested_locales, matcher, {});
......
......@@ -13,7 +13,6 @@
#include <string>
#include "src/heap/factory.h"
#include "src/intl.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/objects/intl-objects.h"
......
......@@ -86,7 +86,7 @@ MaybeHandle<JSSegmenter> JSSegmenter::Initialize(
// 9. Let r be ResolveLocale(%Segmenter%.[[AvailableLocales]],
// requestedLocales, opt, %Segmenter%.[[RelevantExtensionKeys]]).
std::set<std::string> available_locales =
Intl::GetAvailableLocales(ICUService::kSegmenter);
Intl::GetAvailableLocales(Intl::ICUService::kSegmenter);
Intl::ResolvedLocale r = Intl::ResolveLocale(isolate, available_locales,
requested_locales, matcher, {});
......
......@@ -15,7 +15,6 @@
#include "src/date.h"
#include "src/global-handles.h"
#include "src/heap/factory.h"
#include "src/intl.h"
#include "src/isolate-inl.h"
#include "src/objects/intl-objects.h"
#include "src/objects/js-array-inl.h"
......@@ -103,7 +102,7 @@ RUNTIME_FUNCTION(Runtime_StringToLowerCaseIntl) {
DCHECK_EQ(args.length(), 1);
CONVERT_ARG_HANDLE_CHECKED(String, s, 0);
s = String::Flatten(isolate, s);
RETURN_RESULT_OR_FAILURE(isolate, ConvertToLower(s, isolate));
RETURN_RESULT_OR_FAILURE(isolate, Intl::ConvertToLower(isolate, s));
}
RUNTIME_FUNCTION(Runtime_StringToUpperCaseIntl) {
......@@ -111,7 +110,7 @@ RUNTIME_FUNCTION(Runtime_StringToUpperCaseIntl) {
DCHECK_EQ(args.length(), 1);
CONVERT_ARG_HANDLE_CHECKED(String, s, 0);
s = String::Flatten(isolate, s);
RETURN_RESULT_OR_FAILURE(isolate, ConvertToUpper(s, isolate));
RETURN_RESULT_OR_FAILURE(isolate, Intl::ConvertToUpper(isolate, s));
}
RUNTIME_FUNCTION(Runtime_DateCacheVersion) {
......
......@@ -211,23 +211,24 @@ TEST(GetBoolOption) {
TEST(GetAvailableLocales) {
std::set<std::string> locales;
locales = Intl::GetAvailableLocales(ICUService::kBreakIterator);
locales = Intl::GetAvailableLocales(Intl::ICUService::kBreakIterator);
CHECK(locales.count("en-US"));
CHECK(!locales.count("abcdefg"));
locales = Intl::GetAvailableLocales(ICUService::kCollator);
locales = Intl::GetAvailableLocales(Intl::ICUService::kCollator);
CHECK(locales.count("en-US"));
locales = Intl::GetAvailableLocales(ICUService::kDateFormat);
locales = Intl::GetAvailableLocales(Intl::ICUService::kDateFormat);
CHECK(locales.count("en-US"));
locales = Intl::GetAvailableLocales(ICUService::kNumberFormat);
locales = Intl::GetAvailableLocales(Intl::ICUService::kNumberFormat);
CHECK(locales.count("en-US"));
locales = Intl::GetAvailableLocales(ICUService::kPluralRules);
locales = Intl::GetAvailableLocales(Intl::ICUService::kPluralRules);
CHECK(locales.count("en-US"));
locales = Intl::GetAvailableLocales(ICUService::kRelativeDateTimeFormatter);
locales =
Intl::GetAvailableLocales(Intl::ICUService::kRelativeDateTimeFormatter);
CHECK(locales.count("en-US"));
}
......
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