Commit 31b34fe9 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

Change FATAL to IcuError exception

Bug: v8:10224
Change-Id: Ief05b93d71f6da53b0bcfd68719fa79fc2b59e51
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2068903Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66410}
parent f07db34d
......@@ -433,7 +433,7 @@ std::string Intl::GetNumberingSystem(const icu::Locale& icu_locale) {
namespace {
icu::Locale CreateICULocale(const std::string& bcp47_locale) {
Maybe<icu::Locale> CreateICULocale(const std::string& bcp47_locale) {
DisallowHeapAllocation no_gc;
// Convert BCP47 into ICU locale format.
......@@ -442,10 +442,10 @@ icu::Locale CreateICULocale(const std::string& bcp47_locale) {
icu::Locale icu_locale = icu::Locale::forLanguageTag(bcp47_locale, status);
CHECK(U_SUCCESS(status));
if (icu_locale.isBogus()) {
FATAL("Failed to create ICU locale, are ICU data files missing?");
return Nothing<icu::Locale>();
}
return icu_locale;
return Just(icu_locale);
}
} // anonymous namespace
......@@ -1867,7 +1867,7 @@ std::string LookupMatcher(Isolate* isolate,
// this method perform such normalization.
//
// ecma402/#sec-resolvelocale
Intl::ResolvedLocale Intl::ResolveLocale(
Maybe<Intl::ResolvedLocale> Intl::ResolveLocale(
Isolate* isolate, const std::set<std::string>& available_locales,
const std::vector<std::string>& requested_locales, MatcherOption matcher,
const std::set<std::string>& relevant_extension_keys) {
......@@ -1878,7 +1878,9 @@ Intl::ResolvedLocale Intl::ResolveLocale(
locale = LookupMatcher(isolate, available_locales, requested_locales);
}
icu::Locale icu_locale = CreateICULocale(locale);
Maybe<icu::Locale> maybe_icu_locale = CreateICULocale(locale);
MAYBE_RETURN(maybe_icu_locale, Nothing<Intl::ResolvedLocale>());
icu::Locale icu_locale = maybe_icu_locale.FromJust();
std::map<std::string, std::string> extensions =
LookupAndValidateUnicodeExtensions(&icu_locale, relevant_extension_keys);
......@@ -1886,7 +1888,8 @@ Intl::ResolvedLocale Intl::ResolveLocale(
// TODO(gsathya): Remove privateuse subtags from extensions.
return Intl::ResolvedLocale{canonicalized_locale, icu_locale, extensions};
return Just(
Intl::ResolvedLocale{canonicalized_locale, icu_locale, extensions});
}
Handle<Managed<icu::UnicodeString>> Intl::SetTextToBreakIterator(
......
......@@ -258,7 +258,7 @@ class Intl {
std::map<std::string, std::string> extensions;
};
static ResolvedLocale ResolveLocale(
static Maybe<ResolvedLocale> ResolveLocale(
Isolate* isolate, const std::set<std::string>& available_locales,
const std::vector<std::string>& requested_locales, MatcherOption options,
const std::set<std::string>& relevant_extension_keys);
......
......@@ -46,9 +46,14 @@ MaybeHandle<JSV8BreakIterator> JSV8BreakIterator::New(
MAYBE_RETURN(maybe_locale_matcher, MaybeHandle<JSV8BreakIterator>());
Intl::MatcherOption matcher = maybe_locale_matcher.FromJust();
Intl::ResolvedLocale r =
Maybe<Intl::ResolvedLocale> maybe_resolve_locale =
Intl::ResolveLocale(isolate, JSV8BreakIterator::GetAvailableLocales(),
requested_locales, matcher, {});
if (maybe_resolve_locale.IsNothing()) {
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kIcuError),
JSV8BreakIterator);
}
Intl::ResolvedLocale r = maybe_resolve_locale.FromJust();
// Extract type from options
Maybe<Type> maybe_type = Intl::GetStringOption<Type>(
......
......@@ -323,9 +323,14 @@ MaybeHandle<JSCollator> JSCollator::New(Isolate* isolate, Handle<Map> map,
// 17. Let r be ResolveLocale(%Collator%.[[AvailableLocales]],
// requestedLocales, opt, %Collator%.[[RelevantExtensionKeys]],
// localeData).
Intl::ResolvedLocale r =
Maybe<Intl::ResolvedLocale> maybe_resolve_locale =
Intl::ResolveLocale(isolate, JSCollator::GetAvailableLocales(),
requested_locales, matcher, relevant_extension_keys);
if (maybe_resolve_locale.IsNothing()) {
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kIcuError),
JSCollator);
}
Intl::ResolvedLocale r = maybe_resolve_locale.FromJust();
// 18. Set collator.[[Locale]] to r.[[locale]].
icu::Locale icu_locale = r.icu_locale;
......
......@@ -1377,9 +1377,14 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::New(
// requestedLocales, opt, %DateTimeFormat%.[[RelevantExtensionKeys]],
// localeData).
//
Intl::ResolvedLocale r = Intl::ResolveLocale(
Maybe<Intl::ResolvedLocale> maybe_resolve_locale = Intl::ResolveLocale(
isolate, JSDateTimeFormat::GetAvailableLocales(), requested_locales,
locale_matcher, relevant_extension_keys);
if (maybe_resolve_locale.IsNothing()) {
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kIcuError),
JSDateTimeFormat);
}
Intl::ResolvedLocale r = maybe_resolve_locale.FromJust();
icu::Locale icu_locale = r.icu_locale;
DCHECK(!icu_locale.isBogus());
......
......@@ -556,11 +556,16 @@ MaybeHandle<JSDisplayNames> JSDisplayNames::New(Isolate* isolate,
std::set<std::string> relevant_extension_keys = {};
// 13. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]],
// requestedLocales, opt, %DisplayNames%.[[RelevantExtensionKeys]]).
Intl::ResolvedLocale r = Intl::ResolveLocale(
Maybe<Intl::ResolvedLocale> maybe_resolve_locale = Intl::ResolveLocale(
isolate, JSDisplayNames::GetAvailableLocales(), requested_locales,
matcher,
FLAG_harmony_intl_displaynames_date_types ? relevant_extension_keys_ca
: relevant_extension_keys);
if (maybe_resolve_locale.IsNothing()) {
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kIcuError),
JSDisplayNames);
}
Intl::ResolvedLocale r = maybe_resolve_locale.FromJust();
icu::Locale icu_locale = r.icu_locale;
UErrorCode status = U_ZERO_ERROR;
......
......@@ -112,9 +112,14 @@ MaybeHandle<JSListFormat> JSListFormat::New(Isolate* isolate, Handle<Map> map,
// 10. Let r be ResolveLocale(%ListFormat%.[[AvailableLocales]],
// requestedLocales, opt, undefined, localeData).
Intl::ResolvedLocale r =
Maybe<Intl::ResolvedLocale> maybe_resolve_locale =
Intl::ResolveLocale(isolate, JSListFormat::GetAvailableLocales(),
requested_locales, matcher, {});
if (maybe_resolve_locale.IsNothing()) {
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kIcuError),
JSListFormat);
}
Intl::ResolvedLocale r = maybe_resolve_locale.FromJust();
Handle<String> locale_str =
isolate->factory()->NewStringFromAsciiChecked(r.locale.c_str());
......
......@@ -891,9 +891,14 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::New(Isolate* isolate,
// requestedLocales, opt, %NumberFormat%.[[RelevantExtensionKeys]],
// localeData).
std::set<std::string> relevant_extension_keys{"nu"};
Intl::ResolvedLocale r =
Maybe<Intl::ResolvedLocale> maybe_resolve_locale =
Intl::ResolveLocale(isolate, JSNumberFormat::GetAvailableLocales(),
requested_locales, matcher, relevant_extension_keys);
if (maybe_resolve_locale.IsNothing()) {
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kIcuError),
JSNumberFormat);
}
Intl::ResolvedLocale r = maybe_resolve_locale.FromJust();
icu::Locale icu_locale = r.icu_locale;
UErrorCode status = U_ZERO_ERROR;
......
......@@ -111,9 +111,14 @@ MaybeHandle<JSPluralRules> JSPluralRules::New(Isolate* isolate, Handle<Map> map,
// 11. Let r be ResolveLocale(%PluralRules%.[[AvailableLocales]],
// requestedLocales, opt, %PluralRules%.[[RelevantExtensionKeys]],
// localeData).
Intl::ResolvedLocale r =
Maybe<Intl::ResolvedLocale> maybe_resolve_locale =
Intl::ResolveLocale(isolate, JSPluralRules::GetAvailableLocales(),
requested_locales, matcher, {});
if (maybe_resolve_locale.IsNothing()) {
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kIcuError),
JSPluralRules);
}
Intl::ResolvedLocale r = maybe_resolve_locale.FromJust();
Handle<String> locale_str =
isolate->factory()->NewStringFromAsciiChecked(r.locale.c_str());
......
......@@ -112,9 +112,14 @@ MaybeHandle<JSRelativeTimeFormat> JSRelativeTimeFormat::New(
// ResolveLocale(%RelativeTimeFormat%.[[AvailableLocales]],
// requestedLocales, opt,
// %RelativeTimeFormat%.[[RelevantExtensionKeys]], localeData).
Intl::ResolvedLocale r =
Maybe<Intl::ResolvedLocale> maybe_resolve_locale =
Intl::ResolveLocale(isolate, JSRelativeTimeFormat::GetAvailableLocales(),
requested_locales, matcher, {"nu"});
if (maybe_resolve_locale.IsNothing()) {
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kIcuError),
JSRelativeTimeFormat);
}
Intl::ResolvedLocale r = maybe_resolve_locale.FromJust();
UErrorCode status = U_ZERO_ERROR;
......
......@@ -57,9 +57,15 @@ MaybeHandle<JSSegmenter> JSSegmenter::New(Isolate* isolate, Handle<Map> map,
// 9. Let r be ResolveLocale(%Segmenter%.[[AvailableLocales]],
// requestedLocales, opt, %Segmenter%.[[RelevantExtensionKeys]]).
Intl::ResolvedLocale r =
Maybe<Intl::ResolvedLocale> maybe_resolve_locale =
Intl::ResolveLocale(isolate, JSSegmenter::GetAvailableLocales(),
requested_locales, matcher, {});
if (maybe_resolve_locale.IsNothing()) {
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kIcuError),
JSSegmenter);
}
Intl::ResolvedLocale r = maybe_resolve_locale.FromJust();
Handle<String> locale_str =
isolate->factory()->NewStringFromAsciiChecked(r.locale.c_str());
......
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