Commit 7cba1ed5 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

Enable legacy locales "sh", "no", "tl"

Use new API available in ICU65.1 so legacy locales won't be hidden.

Bug: v8:9312,chromium:968269
Change-Id: I6e44501249cdb863ff9b1ab858efdf8908380a82
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2131373
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66957}
parent e0de3b6d
...@@ -563,14 +563,12 @@ bool ValidateResource(const icu::Locale locale, const char* path, ...@@ -563,14 +563,12 @@ bool ValidateResource(const icu::Locale locale, const char* path,
} // namespace } // namespace
std::set<std::string> Intl::BuildLocaleSet( std::set<std::string> Intl::BuildLocaleSet(
const icu::Locale* icu_available_locales, int32_t count, const char* path, const std::vector<std::string>& icu_available_locales, const char* path,
const char* validate_key) { const char* validate_key) {
std::set<std::string> locales; std::set<std::string> locales;
for (int32_t i = 0; i < count; ++i) { for (const std::string& locale : icu_available_locales) {
std::string locale =
Intl::ToLanguageTag(icu_available_locales[i]).FromJust();
if (path != nullptr || validate_key != nullptr) { if (path != nullptr || validate_key != nullptr) {
if (!ValidateResource(icu_available_locales[i], path, validate_key)) { if (!ValidateResource(icu::Locale(locale.c_str()), path, validate_key)) {
continue; continue;
} }
} }
...@@ -2107,9 +2105,9 @@ Maybe<bool> Intl::GetNumberingSystem(Isolate* isolate, ...@@ -2107,9 +2105,9 @@ Maybe<bool> Intl::GetNumberingSystem(Isolate* isolate,
return Just(false); return Just(false);
} }
const std::set<std::string>& Intl::GetAvailableLocalesForLocale() { const std::set<std::string>& Intl::GetAvailableLocales() {
static base::LazyInstance<Intl::AvailableLocales<icu::Locale>>::type static base::LazyInstance<Intl::AvailableLocales<>>::type available_locales =
available_locales = LAZY_INSTANCE_INITIALIZER; LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get(); return available_locales.Pointer()->Get();
} }
...@@ -2123,8 +2121,7 @@ struct CheckCalendar { ...@@ -2123,8 +2121,7 @@ struct CheckCalendar {
} // namespace } // namespace
const std::set<std::string>& Intl::GetAvailableLocalesForDateFormat() { const std::set<std::string>& Intl::GetAvailableLocalesForDateFormat() {
static base::LazyInstance< static base::LazyInstance<Intl::AvailableLocales<CheckCalendar>>::type
Intl::AvailableLocales<icu::DateFormat, CheckCalendar>>::type
available_locales = LAZY_INSTANCE_INITIALIZER; available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get(); return available_locales.Pointer()->Get();
} }
......
...@@ -49,7 +49,7 @@ class Intl { ...@@ -49,7 +49,7 @@ class Intl {
// script; eg, pa_Guru_IN (language=Panjabi, script=Gurmukhi, country-India) // script; eg, pa_Guru_IN (language=Panjabi, script=Gurmukhi, country-India)
// would include pa_IN. // would include pa_IN.
static std::set<std::string> BuildLocaleSet( static std::set<std::string> BuildLocaleSet(
const icu::Locale* icu_available_locales, int32_t count, const char* path, const std::vector<std::string>& locales, const char* path,
const char* validate_key); const char* validate_key);
static Maybe<std::string> ToLanguageTag(const icu::Locale& locale); static Maybe<std::string> ToLanguageTag(const icu::Locale& locale);
...@@ -276,21 +276,34 @@ class Intl { ...@@ -276,21 +276,34 @@ class Intl {
static const char* path() { return nullptr; } static const char* path() { return nullptr; }
}; };
template <typename T, typename C = SkipResourceCheck> template <typename C = SkipResourceCheck>
class AvailableLocales { class AvailableLocales {
public: public:
AvailableLocales() { AvailableLocales() {
int32_t num_locales = 0; UErrorCode status = U_ZERO_ERROR;
const icu::Locale* icu_available_locales = UEnumeration* uenum =
T::getAvailableLocales(num_locales); uloc_openAvailableByType(ULOC_AVAILABLE_WITH_LEGACY_ALIASES, &status);
set = Intl::BuildLocaleSet(icu_available_locales, num_locales, C::path(), DCHECK(U_SUCCESS(status));
C::key());
std::vector<std::string> all_locales;
const char* loc;
while ((loc = uenum_next(uenum, NULL, &status)) != nullptr) {
DCHECK(U_SUCCESS(status));
std::string locstr(loc);
std::replace(locstr.begin(), locstr.end(), '_', '-');
// Handle special case
if (locstr == "en-US-POSIX") locstr = "en-US-u-va-posix";
all_locales.push_back(locstr);
}
uenum_close(uenum);
set_ = Intl::BuildLocaleSet(all_locales, C::path(), C::key());
} }
virtual ~AvailableLocales() {} virtual ~AvailableLocales() {}
const std::set<std::string>& Get() const { return set; } const std::set<std::string>& Get() const { return set_; }
private: private:
std::set<std::string> set; std::set<std::string> set_;
}; };
// Utility function to set text to BreakIterator. // Utility function to set text to BreakIterator.
...@@ -311,7 +324,7 @@ class Intl { ...@@ -311,7 +324,7 @@ class Intl {
static String ConvertOneByteToLower(String src, String dst); static String ConvertOneByteToLower(String src, String dst);
static const std::set<std::string>& GetAvailableLocalesForLocale(); static const std::set<std::string>& GetAvailableLocales();
static const std::set<std::string>& GetAvailableLocalesForDateFormat(); static const std::set<std::string>& GetAvailableLocalesForDateFormat();
}; };
......
...@@ -239,9 +239,7 @@ String JSV8BreakIterator::BreakType(Isolate* isolate, ...@@ -239,9 +239,7 @@ String JSV8BreakIterator::BreakType(Isolate* isolate,
} }
const std::set<std::string>& JSV8BreakIterator::GetAvailableLocales() { const std::set<std::string>& JSV8BreakIterator::GetAvailableLocales() {
static base::LazyInstance<Intl::AvailableLocales<icu::BreakIterator>>::type return Intl::GetAvailableLocales();
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
} }
} // namespace internal } // namespace internal
......
...@@ -493,18 +493,33 @@ MaybeHandle<JSCollator> JSCollator::New(Isolate* isolate, Handle<Map> map, ...@@ -493,18 +493,33 @@ MaybeHandle<JSCollator> JSCollator::New(Isolate* isolate, Handle<Map> map,
namespace { namespace {
struct CheckColl { class CollatorAvailableLocales {
static const char* key() { return nullptr; } public:
CollatorAvailableLocales() {
int32_t num_locales = 0;
const icu::Locale* icu_available_locales =
icu::Collator::getAvailableLocales(num_locales);
std::vector<std::string> locales;
for (int32_t i = 0; i < num_locales; ++i) {
locales.push_back(
Intl::ToLanguageTag(icu_available_locales[i]).FromJust());
}
#define U_ICUDATA_COLL U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "coll" #define U_ICUDATA_COLL U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "coll"
static const char* path() { return U_ICUDATA_COLL; } set_ = Intl::BuildLocaleSet(locales, U_ICUDATA_COLL, nullptr);
#undef U_ICUDATA_COLL #undef U_ICUDATA_COLL
}
virtual ~CollatorAvailableLocales() {}
const std::set<std::string>& Get() const { return set_; }
private:
std::set<std::string> set_;
}; };
} // namespace } // namespace
const std::set<std::string>& JSCollator::GetAvailableLocales() { const std::set<std::string>& JSCollator::GetAvailableLocales() {
static base::LazyInstance<Intl::AvailableLocales<icu::Collator, CheckColl>>:: static base::LazyInstance<CollatorAvailableLocales>::type available_locales =
type available_locales = LAZY_INSTANCE_INITIALIZER; LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get(); return available_locales.Pointer()->Get();
} }
......
...@@ -750,8 +750,7 @@ struct CheckCalendar { ...@@ -750,8 +750,7 @@ struct CheckCalendar {
} // namespace } // namespace
const std::set<std::string>& JSDisplayNames::GetAvailableLocales() { const std::set<std::string>& JSDisplayNames::GetAvailableLocales() {
static base::LazyInstance< static base::LazyInstance<Intl::AvailableLocales<CheckCalendar>>::type
Intl::AvailableLocales<icu::Locale, CheckCalendar>>::type
available_locales = LAZY_INSTANCE_INITIALIZER; available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get(); return available_locales.Pointer()->Get();
} }
......
...@@ -331,8 +331,7 @@ struct CheckListPattern { ...@@ -331,8 +331,7 @@ struct CheckListPattern {
} // namespace } // namespace
const std::set<std::string>& JSListFormat::GetAvailableLocales() { const std::set<std::string>& JSListFormat::GetAvailableLocales() {
static base::LazyInstance< static base::LazyInstance<Intl::AvailableLocales<CheckListPattern>>::type
Intl::AvailableLocales<icu::Locale, CheckListPattern>>::type
available_locales = LAZY_INSTANCE_INITIALIZER; available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get(); return available_locales.Pointer()->Get();
} }
......
...@@ -1494,8 +1494,7 @@ struct CheckNumberElements { ...@@ -1494,8 +1494,7 @@ struct CheckNumberElements {
} // namespace } // namespace
const std::set<std::string>& JSNumberFormat::GetAvailableLocales() { const std::set<std::string>& JSNumberFormat::GetAvailableLocales() {
static base::LazyInstance< static base::LazyInstance<Intl::AvailableLocales<CheckNumberElements>>::type
Intl::AvailableLocales<icu::NumberFormat, CheckNumberElements>>::type
available_locales = LAZY_INSTANCE_INITIALIZER; available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get(); return available_locales.Pointer()->Get();
} }
......
...@@ -325,7 +325,6 @@ const std::set<std::string>& JSPluralRules::GetAvailableLocales() { ...@@ -325,7 +325,6 @@ const std::set<std::string>& JSPluralRules::GetAvailableLocales() {
static base::LazyInstance<PluralRulesAvailableLocales>::type static base::LazyInstance<PluralRulesAvailableLocales>::type
available_locales = LAZY_INSTANCE_INITIALIZER; available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get(); return available_locales.Pointer()->Get();
// return Intl::GetAvailableLocalesForLocale();
} }
} // namespace internal } // namespace internal
......
...@@ -163,9 +163,7 @@ Handle<String> JSSegmenter::GranularityAsString() const { ...@@ -163,9 +163,7 @@ Handle<String> JSSegmenter::GranularityAsString() const {
} }
const std::set<std::string>& JSSegmenter::GetAvailableLocales() { const std::set<std::string>& JSSegmenter::GetAvailableLocales() {
static base::LazyInstance<Intl::AvailableLocales<icu::BreakIterator>>::type return Intl::GetAvailableLocales();
available_locales = LAZY_INSTANCE_INITIALIZER;
return available_locales.Pointer()->Get();
} }
} // namespace internal } // namespace internal
......
...@@ -34,9 +34,6 @@ ...@@ -34,9 +34,6 @@
'collator/check-kf-option': [FAIL], 'collator/check-kf-option': [FAIL],
'collator/check-kn-option': [FAIL], 'collator/check-kn-option': [FAIL],
# https://code.google.com/p/v8/issues/detail?id=9312
'regress-9312': [FAIL],
# http://crbug/v8/9930 # http://crbug/v8/9930
'date-format/format_range_hour_cycle': [FAIL], 'date-format/format_range_hour_cycle': [FAIL],
}], # ALWAYS }], # ALWAYS
......
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