Commit 9db83763 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Move caching of default locale from JS into Intl::DefaultLocale

Bug: v8:7988
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: Ib06e07b20c4a80baac7667241906142d60ada8e8
Reviewed-on: https://chromium-review.googlesource.com/1152453
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarJungshik Shin <jshin@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54797}
parent 6f23c89e
......@@ -2486,6 +2486,7 @@ Isolate::Isolate()
language_singleton_regexp_matcher_(nullptr),
language_tag_regexp_matcher_(nullptr),
language_variant_regexp_matcher_(nullptr),
default_locale_(""),
#endif // V8_INTL_SUPPORT
serializer_enabled_(false),
has_fatal_error_(false),
......
......@@ -1116,6 +1116,13 @@ class Isolate : private HiddenFactory {
return language_variant_regexp_matcher_;
}
const std::string& default_locale() { return default_locale_; }
void set_default_locale(const std::string& locale) {
DCHECK_EQ(default_locale_.length(), 0);
default_locale_ = locale;
}
void set_language_tag_regexp_matchers(
icu::RegexMatcher* language_singleton_regexp_matcher,
icu::RegexMatcher* language_tag_regexp_matcher,
......@@ -1625,6 +1632,7 @@ class Isolate : private HiddenFactory {
icu::RegexMatcher* language_singleton_regexp_matcher_;
icu::RegexMatcher* language_tag_regexp_matcher_;
icu::RegexMatcher* language_variant_regexp_matcher_;
std::string default_locale_;
#endif // V8_INTL_SUPPORT
// Whether the isolate has been created for snapshotting.
......
......@@ -141,18 +141,6 @@ var AVAILABLE_LOCALES = {
'listformat': UNDEFINED,
};
/**
* Caches default ICU locale.
*/
var DEFAULT_ICU_LOCALE = UNDEFINED;
function GetDefaultICULocaleJS() {
if (IS_UNDEFINED(DEFAULT_ICU_LOCALE)) {
DEFAULT_ICU_LOCALE = %GetDefaultICULocale();
}
return DEFAULT_ICU_LOCALE;
}
/**
* Unicode extension regular expression.
*/
......@@ -453,7 +441,7 @@ function lookupMatcher(service, requestedLocales) {
}
}
var defLocale = GetDefaultICULocaleJS();
var defLocale = %GetDefaultICULocale();
// While ECMA-402 returns defLocale directly, we have to check if it is
// supported, as such support is not guaranteed.
......
......@@ -1203,25 +1203,25 @@ V8_WARN_UNUSED_RESULT MaybeHandle<JSObject> Intl::AvailableLocalesOf(
}
V8_WARN_UNUSED_RESULT Handle<String> Intl::DefaultLocale(Isolate* isolate) {
Factory* factory = isolate->factory();
icu::Locale default_locale;
// Translate ICU's fallback locale to a well-known locale.
if (strcmp(default_locale.getName(), "en_US_POSIX") == 0) {
return factory->NewStringFromStaticChars("en-US");
}
// Set the locale
char result[ULOC_FULLNAME_CAPACITY];
UErrorCode status = U_ZERO_ERROR;
uloc_toLanguageTag(default_locale.getName(), result, ULOC_FULLNAME_CAPACITY,
FALSE, &status);
if (U_SUCCESS(status)) {
return factory->NewStringFromAsciiChecked(result);
if (isolate->default_locale().empty()) {
icu::Locale default_locale;
// Translate ICU's fallback locale to a well-known locale.
if (strcmp(default_locale.getName(), "en_US_POSIX") == 0) {
isolate->set_default_locale("en-US");
} else {
// Set the locale
char result[ULOC_FULLNAME_CAPACITY];
UErrorCode status = U_ZERO_ERROR;
int32_t length =
uloc_toLanguageTag(default_locale.getName(), result,
ULOC_FULLNAME_CAPACITY, FALSE, &status);
isolate->set_default_locale(
U_SUCCESS(status) ? std::string(result, length) : "und");
}
DCHECK(!isolate->default_locale().empty());
}
return factory->NewStringFromStaticChars("und");
return isolate->factory()->NewStringFromAsciiChecked(
isolate->default_locale().c_str());
}
bool Intl::IsObjectOfType(Isolate* isolate, Handle<Object> input,
......
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