Commit cd306d91 authored by Michael Hablich's avatar Michael Hablich Committed by Commit Bot

Revert "Implement ResolveLocale in C++."

This reverts commit 1a225459.

Reason for revert: Makes GC stress unhappy: https://ci.chromium.org/p/v8/builders/luci.v8.ci/V8%20Linux%20-%20gc%20stress/18325 and blocks the roll

Original change's description:
> Implement ResolveLocale in C++.
> 
> Bug: v8:8065, v8:5751
> Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
> Change-Id: Id9dc16455d63b7c436126c21758d64fae0ec8de9
> Reviewed-on: https://chromium-review.googlesource.com/1211402
> Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org>
> Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#55925}

TBR=bstell@chromium.org,gsathya@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: v8:8065, v8:5751
Change-Id: I4d71adb31ffd5ab0d2ae42c0255d0a05edbaad29
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Reviewed-on: https://chromium-review.googlesource.com/1226646Reviewed-by: 's avatarMichael Hablich <hablich@chromium.org>
Commit-Queue: Michael Hablich <hablich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55932}
parent c8fd2870
......@@ -96,6 +96,7 @@ enum ContextLookupFlags {
V(REFERENCE_ERROR_FUNCTION_INDEX, JSFunction, reference_error_function) \
V(CACHED_OR_NEW_SERVICE_LOCALE_FUNCTION_INDEX, JSFunction, \
cached_or_new_service) \
V(RESOLVE_LOCALE_FUNCTION_INDEX, JSFunction, resolve_locale) \
V(SET_ADD_INDEX, JSFunction, set_add) \
V(SET_DELETE_INDEX, JSFunction, set_delete) \
V(SET_HAS_INDEX, JSFunction, set_has) \
......
This diff is collapsed.
This diff is collapsed.
......@@ -89,13 +89,6 @@ class Intl {
static bool RemoveLocaleScriptTag(const std::string& icu_locale,
std::string* locale_less_script);
struct ResolvedLocale {
std::string locale; // The bcp47 locale to use.
std::string unicode_extensions;
std::map<std::string, std::string> extensions;
std::string locale_with_extensions;
};
// The ResolveLocale abstract operation compares a BCP 47 language
// priority list requestedLocales against the locales in
// availableLocales and determines the best available language to
......@@ -105,15 +98,14 @@ class Intl {
//
// #ecma402/sec-partitiondatetimepattern
//
// Returns an object with two properties:
// Returns a JSObject with two properties:
// (1) locale
// (2) extension
V8_WARN_UNUSED_RESULT static Maybe<ResolvedLocale*> ResolveLocale(
Isolate* isolate, const char* service,
const std::set<std::string>& available_locales,
const std::vector<std::string>& requested_locales,
const std::set<std::string>& relevant_extension_keys,
Handle<JSReceiver> options);
//
// To access either, use JSObject::GetDataProperty.
V8_WARN_UNUSED_RESULT static MaybeHandle<JSObject> ResolveLocale(
Isolate* isolate, const char* service, Handle<Object> requestedLocales,
Handle<Object> options);
// This currently calls out to the JavaScript implementation of
// CanonicalizeLocaleList.
......
......@@ -28,9 +28,6 @@ MaybeHandle<JSV8BreakIterator> JSV8BreakIterator::InitializeV8BreakIterator(
Isolate* isolate, Handle<JSV8BreakIterator> break_iterator_holder,
Handle<Object> locales, Handle<Object> options_obj) {
Factory* factory = isolate->factory();
Maybe<std::vector<std::string>> requested_locales =
Intl::CanonicalizeLocaleList(isolate, locales, false);
MAYBE_RETURN(requested_locales, MaybeHandle<JSV8BreakIterator>());
Handle<JSReceiver> options;
if (options_obj->IsUndefined(isolate)) {
......@@ -43,18 +40,15 @@ MaybeHandle<JSV8BreakIterator> JSV8BreakIterator::InitializeV8BreakIterator(
}
// Extract locale string
const std::set<std::string> relevant_extension_keys;
std::set<std::string> available_locales =
Intl::GetAvailableLocales(IcuService::kListFormatter);
Maybe<Intl::ResolvedLocale*> maybe_resolved_locale = Intl::ResolveLocale(
isolate, "breakiterator", available_locales, requested_locales.FromJust(),
relevant_extension_keys, options);
MAYBE_RETURN(maybe_resolved_locale, MaybeHandle<JSV8BreakIterator>());
std::unique_ptr<Intl::ResolvedLocale> r(maybe_resolved_locale.FromJust());
CHECK_NOT_NULL(r.get());
Handle<String> locale =
isolate->factory()->NewStringFromAsciiChecked(r.get()->locale.c_str());
Handle<JSObject> r;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, r,
Intl::ResolveLocale(isolate, "breakiterator", locales, options),
JSV8BreakIterator);
Handle<Object> locale_obj =
JSObject::GetDataProperty(r, factory->locale_string());
CHECK(locale_obj->IsString());
Handle<String> locale = Handle<String>::cast(locale_obj);
// Extract type from options
std::unique_ptr<char[]> type_str = nullptr;
......
......@@ -221,9 +221,10 @@ MaybeHandle<JSCollator> JSCollator::InitializeCollator(
Isolate* isolate, Handle<JSCollator> collator, Handle<Object> locales,
Handle<Object> options_obj) {
// 1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
Maybe<std::vector<std::string>> requested_locales =
Intl::CanonicalizeLocaleList(isolate, locales, false);
MAYBE_RETURN(requested_locales, MaybeHandle<JSCollator>());
Handle<JSObject> requested_locales;
ASSIGN_RETURN_ON_EXCEPTION(isolate, requested_locales,
Intl::CanonicalizeLocaleListJS(isolate, locales),
JSCollator);
// 2. If options is undefined, then
if (options_obj->IsUndefined(isolate)) {
......@@ -256,7 +257,10 @@ MaybeHandle<JSCollator> JSCollator::InitializeCollator(
}
}
// Steps 9 and 10 are done as part of the Intl::ResolveLocale call below.
// TODO(gsathya): This is currently done as part of the
// Intl::ResolveLocale call below. Fix this once resolveLocale is
// changed to not do the lookup.
//
// 9. Let matcher be ? GetOption(options, "localeMatcher", "string",
// « "lookup", "best fit" », "best fit").
// 10. Set opt.[[localeMatcher]] to matcher.
......@@ -312,20 +316,25 @@ MaybeHandle<JSCollator> JSCollator::InitializeCollator(
// requestedLocales, opt, %Collator%.[[RelevantExtensionKeys]],
// localeData).
// 18. Set collator.[[Locale]] to r.[[locale]].
std::set<std::string> available_locales =
Intl::GetAvailableLocales(IcuService::kCollator);
Maybe<Intl::ResolvedLocale*> maybe_resolved_locale = Intl::ResolveLocale(
isolate, "collator", available_locales, requested_locales.FromJust(),
relevant_extension_keys, options);
MAYBE_RETURN(maybe_resolved_locale, MaybeHandle<JSCollator>());
std::unique_ptr<Intl::ResolvedLocale> r(maybe_resolved_locale.FromJust());
CHECK_NOT_NULL(r.get());
std::string locale_with_extension = r.get()->locale_with_extensions;
Handle<String> locale = isolate->factory()->NewStringFromAsciiChecked(
locale_with_extension.c_str());
icu::Locale icu_locale = Intl::CreateICULocale(isolate, locale);
Handle<JSObject> r;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, r,
Intl::ResolveLocale(isolate, "collator", requested_locales, options),
JSCollator);
Handle<String> locale_with_extension_str =
isolate->factory()->NewStringFromStaticChars("localeWithExtension");
Handle<Object> locale_with_extension_obj =
JSObject::GetDataProperty(r, locale_with_extension_str);
// The locale_with_extension has to be a string. Either a user
// provided canonicalized string or the default locale.
CHECK(locale_with_extension_obj->IsString());
Handle<String> locale_with_extension =
Handle<String>::cast(locale_with_extension_obj);
icu::Locale icu_locale =
Intl::CreateICULocale(isolate, locale_with_extension);
DCHECK(!icu_locale.isBogus());
std::map<std::string, std::string> extensions =
......
......@@ -775,12 +775,7 @@ enum FormatMatcherOption { kBestFit, kBasic };
// ecma402/#sec-initializedatetimeformat
MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::Initialize(
Isolate* isolate, Handle<JSDateTimeFormat> date_time_format,
Handle<Object> locales, Handle<Object> input_options) {
// 1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
Maybe<std::vector<std::string>> requested_locales =
Intl::CanonicalizeLocaleList(isolate, locales, false);
MAYBE_RETURN(requested_locales, MaybeHandle<JSDateTimeFormat>());
Handle<Object> requested_locales, Handle<Object> input_options) {
// 2. Let options be ? ToDateTimeOptions(options, "any", "date").
Handle<JSObject> options;
ASSIGN_RETURN_ON_EXCEPTION(
......@@ -789,26 +784,29 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::Initialize(
isolate, input_options, RequiredOption::kAny, DefaultsOption::kDate),
JSDateTimeFormat);
const std::set<std::string> relevant_extension_keys{"ca", "nu", "hc"};
// 11. Let r be ResolveLocale( %DateTimeFormat%.[[AvailableLocales]],
// requestedLocales, opt, %DateTimeFormat%.[[RelevantExtensionKeys]],
// localeData).
const char* kService = "Intl.DateTimeFormat";
std::set<std::string> available_locales =
Intl::GetAvailableLocales(IcuService::kRelativeDateTimeFormatter);
Maybe<Intl::ResolvedLocale*> maybe_resolved_locale = Intl::ResolveLocale(
isolate, "datetimeformat", available_locales,
requested_locales.FromJust(), relevant_extension_keys, options);
MAYBE_RETURN(maybe_resolved_locale, MaybeHandle<JSDateTimeFormat>());
std::unique_ptr<Intl::ResolvedLocale> r(maybe_resolved_locale.FromJust());
CHECK_NOT_NULL(r.get());
std::string locale_with_extension = r.get()->locale_with_extensions;
Handle<String> locale = isolate->factory()->NewStringFromAsciiChecked(
locale_with_extension.c_str());
icu::Locale icu_locale = Intl::CreateICULocale(isolate, locale);
Handle<JSObject> r;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, r,
Intl::ResolveLocale(isolate, "dateformat", requested_locales, options),
JSDateTimeFormat);
Handle<String> locale_with_extension_str =
isolate->factory()->NewStringFromStaticChars("localeWithExtension");
Handle<Object> locale_with_extension_obj =
JSObject::GetDataProperty(r, locale_with_extension_str);
// The locale_with_extension has to be a string. Either a user
// provided canonicalized string or the default locale.
CHECK(locale_with_extension_obj->IsString());
Handle<String> locale_with_extension =
Handle<String>::cast(locale_with_extension_obj);
icu::Locale icu_locale =
Intl::CreateICULocale(isolate, locale_with_extension);
DCHECK(!icu_locale.isBogus());
// We implement only best fit algorithm, but still need to check
......
......@@ -122,10 +122,7 @@ JSListFormat::Type get_type(const char* str) {
MaybeHandle<JSListFormat> JSListFormat::InitializeListFormat(
Isolate* isolate, Handle<JSListFormat> list_format_holder,
Handle<Object> input_locales, Handle<Object> input_options) {
Maybe<std::vector<std::string>> requested_locales =
Intl::CanonicalizeLocaleList(isolate, input_locales, false);
MAYBE_RETURN(requested_locales, MaybeHandle<JSListFormat>());
Factory* factory = isolate->factory();
list_format_holder->set_flags(0);
Handle<JSReceiver> options;
......@@ -173,23 +170,23 @@ MaybeHandle<JSListFormat> JSListFormat::InitializeListFormat(
// 10. Let r be ResolveLocale(%ListFormat%.[[AvailableLocales]],
// requestedLocales, opt, undefined, localeData).
const std::set<std::string> relevant_extension_keys;
std::set<std::string> available_locales =
Intl::GetAvailableLocales(IcuService::kListFormatter);
Maybe<Intl::ResolvedLocale*> maybe_resolved_locale = Intl::ResolveLocale(
isolate, "listformatter", available_locales, requested_locales.FromJust(),
relevant_extension_keys, options);
MAYBE_RETURN(maybe_resolved_locale, MaybeHandle<JSListFormat>());
std::unique_ptr<Intl::ResolvedLocale> r(maybe_resolved_locale.FromJust());
CHECK_NOT_NULL(r.get());
Handle<String> locale =
isolate->factory()->NewStringFromAsciiChecked(r.get()->locale.c_str());
Handle<JSObject> r;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, r,
Intl::ResolveLocale(isolate, "listformat", input_locales, options),
JSListFormat);
Handle<Object> locale_obj =
JSObject::GetDataProperty(r, factory->locale_string());
Handle<String> locale;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, locale, Object::ToString(isolate, locale_obj), JSListFormat);
// 18. Set listFormat.[[Locale]] to the value of r.[[Locale]].
list_format_holder->set_locale(*locale);
icu::Locale icu_locale(r.get()->locale.c_str());
std::unique_ptr<char[]> locale_name = locale->ToCString();
icu::Locale icu_locale(locale_name.get());
UErrorCode status = U_ZERO_ERROR;
icu::ListFormatter* formatter = icu::ListFormatter::createInstance(
icu_locale, GetIcuStyleString(style_enum, type_enum), status);
......
......@@ -189,9 +189,10 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize(
number_format->set_flags(0);
Factory* factory = isolate->factory();
// 1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
Maybe<std::vector<std::string>> requested_locales =
Intl::CanonicalizeLocaleList(isolate, locales, false);
MAYBE_RETURN(requested_locales, MaybeHandle<JSNumberFormat>());
Handle<JSObject> requested_locales;
ASSIGN_RETURN_ON_EXCEPTION(isolate, requested_locales,
Intl::CanonicalizeLocaleListJS(isolate, locales),
JSNumberFormat);
// 2. If options is undefined, then
if (options_obj->IsUndefined(isolate)) {
......@@ -211,8 +212,6 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize(
// 4. Let opt be a new Record.
//
// Steps 5 and 6 are currently done as part of the
// Intl::ResolveLocale call below.
// 5. Let matcher be ? GetOption(options, "localeMatcher", "string", «
// "lookup", "best fit" », "best fit").
//
......@@ -226,26 +225,29 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize(
//
// 9. Set numberFormat.[[Locale]] to r.[[locale]].
std::set<std::string> available_locales =
Intl::GetAvailableLocales(IcuService::kNumberFormat);
// 13.3.3 Internal slots
// https://tc39.github.io/ecma402/#sec-intl.numberformat-internal-slots
const std::set<std::string> relevant_extension_keys{"nu"};
Maybe<Intl::ResolvedLocale*> maybe_resolved_locale = Intl::ResolveLocale(
isolate, "numberformat", available_locales, requested_locales.FromJust(),
relevant_extension_keys, options);
MAYBE_RETURN(maybe_resolved_locale, MaybeHandle<JSNumberFormat>());
std::unique_ptr<Intl::ResolvedLocale> r(maybe_resolved_locale.FromJust());
CHECK_NOT_NULL(r.get());
std::string locale_with_extension = r.get()->locale_with_extensions;
Handle<String> locale = isolate->factory()->NewStringFromAsciiChecked(
locale_with_extension.c_str());
icu::Locale icu_locale = Intl::CreateICULocale(isolate, locale);
number_format->set_locale(*locale);
Handle<JSObject> r;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, r,
Intl::ResolveLocale(isolate, "numberformat", requested_locales, options),
JSNumberFormat);
Handle<String> locale_with_extension_str =
isolate->factory()->NewStringFromStaticChars("localeWithExtension");
Handle<Object> locale_with_extension_obj =
JSObject::GetDataProperty(r, locale_with_extension_str);
// The locale_with_extension has to be a string. Either a user
// provided canonicalized string or the default locale.
CHECK(locale_with_extension_obj->IsString());
Handle<String> locale_with_extension =
Handle<String>::cast(locale_with_extension_obj);
icu::Locale icu_locale =
Intl::CreateICULocale(isolate, locale_with_extension);
number_format->set_locale(*locale_with_extension);
DCHECK(!icu_locale.isBogus());
std::set<std::string> relevant_extension_keys{"nu"};
std::map<std::string, std::string> extensions =
Intl::LookupUnicodeExtensions(icu_locale, relevant_extension_keys);
......
......@@ -89,9 +89,12 @@ MaybeHandle<JSPluralRules> JSPluralRules::InitializePluralRules(
Isolate* isolate, Handle<JSPluralRules> plural_rules,
Handle<Object> locales, Handle<Object> options_obj) {
// 1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
Maybe<std::vector<std::string>> requested_locales =
Intl::CanonicalizeLocaleList(isolate, locales, false);
MAYBE_RETURN(requested_locales, MaybeHandle<JSPluralRules>());
// TODO(jkummerow): Port ResolveLocale, then use the C++ version of
// CanonicalizeLocaleList here.
Handle<JSObject> requested_locales;
ASSIGN_RETURN_ON_EXCEPTION(isolate, requested_locales,
Intl::CanonicalizeLocaleListJS(isolate, locales),
JSPluralRules);
// 2. If options is undefined, then
if (options_obj->IsUndefined(isolate)) {
......@@ -109,8 +112,10 @@ MaybeHandle<JSPluralRules> JSPluralRules::InitializePluralRules(
// At this point, options_obj can either be a JSObject or a JSProxy only.
Handle<JSReceiver> options = Handle<JSReceiver>::cast(options_obj);
// Steps 5 and 6 are currently done as part of the
// Intl::ResolveLocale call below.
// TODO(gsathya): This is currently done as part of the
// Intl::ResolveLocale call below. Fix this once resolveLocale is
// changed to not do the lookup.
//
// 5. Let matcher be ? GetOption(options, "localeMatcher", "string",
// « "lookup", "best fit" », "best fit").
// 6. Set opt.[[localeMatcher]] to matcher.
......@@ -141,21 +146,19 @@ MaybeHandle<JSPluralRules> JSPluralRules::InitializePluralRules(
// 11. Let r be ResolveLocale(%PluralRules%.[[AvailableLocales]],
// requestedLocales, opt, %PluralRules%.[[RelevantExtensionKeys]],
// localeData).
std::set<std::string> available_locales =
Intl::GetAvailableLocales(IcuService::kPluralRules);
// 13.3.3 Internal slots
// https://tc39.github.io/ecma402/#sec-intl.pluralrules-internal-slots
// The value of the [[RelevantExtensionKeys]] internal slot is [].
const std::set<std::string> relevant_extension_keys;
Maybe<Intl::ResolvedLocale*> maybe_resolved_locale = Intl::ResolveLocale(
isolate, "pluralrules", available_locales, requested_locales.FromJust(),
relevant_extension_keys, options);
MAYBE_RETURN(maybe_resolved_locale, MaybeHandle<JSPluralRules>());
std::unique_ptr<Intl::ResolvedLocale> r(maybe_resolved_locale.FromJust());
CHECK_NOT_NULL(r.get());
Handle<String> locale =
isolate->factory()->NewStringFromAsciiChecked(r.get()->locale.c_str());
Handle<JSObject> r;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, r,
Intl::ResolveLocale(isolate, "pluralrules", requested_locales, options),
JSPluralRules);
Handle<String> locale_str = isolate->factory()->locale_string();
Handle<Object> locale_obj = JSObject::GetDataProperty(r, locale_str);
// The locale has to be a string. Either a user provided
// canonicalized string or the default locale.
CHECK(locale_obj->IsString());
Handle<String> locale = Handle<String>::cast(locale_obj);
// 12. Set pluralRules.[[Locale]] to the value of r.[[locale]].
plural_rules->set_locale(*locale);
......
......@@ -59,10 +59,7 @@ MaybeHandle<JSRelativeTimeFormat>
JSRelativeTimeFormat::InitializeRelativeTimeFormat(
Isolate* isolate, Handle<JSRelativeTimeFormat> relative_time_format_holder,
Handle<Object> input_locales, Handle<Object> input_options) {
Maybe<std::vector<std::string>> requested_locales =
Intl::CanonicalizeLocaleList(isolate, input_locales, false);
MAYBE_RETURN(requested_locales, MaybeHandle<JSRelativeTimeFormat>());
Factory* factory = isolate->factory();
relative_time_format_holder->set_flags(0);
// 4. If options is undefined, then
Handle<JSReceiver> options;
......@@ -81,20 +78,17 @@ JSRelativeTimeFormat::InitializeRelativeTimeFormat(
// requestedLocales, opt,
// %RelativeTimeFormat%.[[RelevantExtensionKeys]],
// localeData).
std::set<std::string> available_locales =
Intl::GetAvailableLocales(IcuService::kRelativeDateTimeFormatter);
// 13.3.3 Internal slots
// The value of the [[RelevantExtensionKeys]] internal slot is [].
const std::set<std::string> relevant_extension_keys;
Maybe<Intl::ResolvedLocale*> maybe_resolved_locale = Intl::ResolveLocale(
isolate, "relativetimeformat", available_locales,
requested_locales.FromJust(), relevant_extension_keys, options);
MAYBE_RETURN(maybe_resolved_locale, MaybeHandle<JSRelativeTimeFormat>());
std::unique_ptr<Intl::ResolvedLocale> r(maybe_resolved_locale.FromJust());
CHECK_NOT_NULL(r.get());
Handle<String> locale =
isolate->factory()->NewStringFromAsciiChecked(r.get()->locale.c_str());
Handle<JSObject> r;
ASSIGN_RETURN_ON_EXCEPTION(isolate, r,
Intl::ResolveLocale(isolate, "relativetimeformat",
input_locales, options),
JSRelativeTimeFormat);
Handle<Object> locale_obj =
JSObject::GetDataProperty(r, factory->locale_string());
Handle<String> locale;
ASSIGN_RETURN_ON_EXCEPTION(isolate, locale,
Object::ToString(isolate, locale_obj),
JSRelativeTimeFormat);
// 11. Let locale be r.[[Locale]].
// 12. Set relativeTimeFormat.[[Locale]] to locale.
......
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