Commit 4682a357 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Move GetOptions('localeMatcher') earlier

See https://github.com/tc39/proposal-intl-list-format/pull/36

Bug: v8:8614
Change-Id: Ifa9bebf27163420562c0d62867b9a240b5c4c502
Reviewed-on: https://chromium-review.googlesource.com/c/1386324
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58938}
parent 5a81b207
......@@ -149,7 +149,27 @@ MaybeHandle<JSListFormat> JSListFormat::Initialize(
// Note: No need to create a record. It's not observable.
// 6. Let opt be a new Record.
// 7. Let t be GetOption(options, "type", "string", «"conjunction",
// 7. Let matcher be ? GetOption(options, "localeMatcher", "string", «
// "lookup", "best fit" », "best fit").
Maybe<Intl::MatcherOption> maybe_locale_matcher =
Intl::GetLocaleMatcher(isolate, options, "Intl.ListFormat");
MAYBE_RETURN(maybe_locale_matcher, MaybeHandle<JSListFormat>());
// 8. Set opt.[[localeMatcher]] to matcher.
Intl::MatcherOption matcher = maybe_locale_matcher.FromJust();
// 10. Let r be ResolveLocale(%ListFormat%.[[AvailableLocales]],
// requestedLocales, opt, undefined, localeData).
Intl::ResolvedLocale r =
Intl::ResolveLocale(isolate, JSListFormat::GetAvailableLocales(),
requested_locales, matcher, {});
// 11. Set listFormat.[[Locale]] to r.[[Locale]].
Handle<String> locale_str =
isolate->factory()->NewStringFromAsciiChecked(r.locale.c_str());
list_format->set_locale(*locale_str);
// 12. Let t be GetOption(options, "type", "string", «"conjunction",
// "disjunction", "unit"», "conjunction").
Maybe<Type> maybe_type = Intl::GetStringOption<Type>(
isolate, options, "type", "Intl.ListFormat",
......@@ -158,10 +178,14 @@ MaybeHandle<JSListFormat> JSListFormat::Initialize(
MAYBE_RETURN(maybe_type, MaybeHandle<JSListFormat>());
Type type_enum = maybe_type.FromJust();
// 8. Set listFormat.[[Type]] to t.
// 13. Set listFormat.[[Type]] to t.
list_format->set_type(type_enum);
// 9. Let s be ? GetOption(options, "style", "string",
// NOTE: Keep the old way of GetOptions on style for now. I discover a
// disadvantage of following the lastest spec and propose to rollback that
// part in https://github.com/tc39/proposal-intl-list-format/pull/40
// Let s be ? GetOption(options, "style", "string",
// «"long", "short", "narrow"», "long").
Maybe<Style> maybe_style = Intl::GetStringOption<Style>(
isolate, options, "style", "Intl.ListFormat", {"long", "short", "narrow"},
......@@ -169,17 +193,7 @@ MaybeHandle<JSListFormat> JSListFormat::Initialize(
MAYBE_RETURN(maybe_style, MaybeHandle<JSListFormat>());
Style style_enum = maybe_style.FromJust();
// 10. Set listFormat.[[Style]] to s.
list_format->set_style(style_enum);
// 12. Let matcher be ? GetOption(options, "localeMatcher", "string", «
// "lookup", "best fit" », "best fit").
Maybe<Intl::MatcherOption> maybe_locale_matcher =
Intl::GetLocaleMatcher(isolate, options, "Intl.ListFormat");
MAYBE_RETURN(maybe_locale_matcher, MaybeHandle<JSListFormat>());
Intl::MatcherOption matcher = maybe_locale_matcher.FromJust();
// 14. If style is "narrow" and type is not "unit", throw a RangeError
// If _style_ is `"narrow"` and _type_ is not `"unit"`, throw a *RangeError*
// exception.
if (style_enum == Style::NARROW && type_enum != Type::UNIT) {
THROW_NEW_ERROR(
......@@ -187,16 +201,8 @@ MaybeHandle<JSListFormat> JSListFormat::Initialize(
JSListFormat);
}
// 15. Let r be ResolveLocale(%ListFormat%.[[AvailableLocales]],
// requestedLocales, opt, undefined, localeData).
Intl::ResolvedLocale r =
Intl::ResolveLocale(isolate, JSListFormat::GetAvailableLocales(),
requested_locales, matcher, {});
// 24. Set listFormat.[[Locale]] to r.[[Locale]].
Handle<String> locale_str =
isolate->factory()->NewStringFromAsciiChecked(r.locale.c_str());
list_format->set_locale(*locale_str);
// 17. Set listFormat.[[Style]] to s.
list_format->set_style(style_enum);
icu::Locale icu_locale = r.icu_locale;
UErrorCode status = U_ZERO_ERROR;
......
......@@ -8,13 +8,13 @@
let getCount = 0;
new Intl.ListFormat(['en-US'], {
get type() {
get localeMatcher() {
assertEquals(0, getCount++);
},
get style() {
get type() {
assertEquals(1, getCount++);
},
get localeMatcher() {
get style() {
assertEquals(2, getCount++);
},
});
......
......@@ -5,3 +5,4 @@ RangeError: When style is 'narrow', 'unit' is the only allowed value for the typ
at new ListFormat (<anonymous>)
at *%(basename)s:7:1
......@@ -521,6 +521,9 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=7483
'annexB/built-ins/Function/createdynfn-html-close-comment-params': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=8614
'intl402/ListFormat/constructor/constructor/options-order': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=8260
'intl402/Locale/constructor-non-iana-canon': [FAIL],
......
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