Commit f3957c97 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Int] Allow 'narrow' for all types in ListFormat

Bug: v8:9040
Change-Id: Ie1c5ab982aef844c704dba5bb9a0e945ce220545
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1549435Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60662}
parent 16b62666
......@@ -324,9 +324,6 @@ namespace internal {
T(InvalidTypedArrayAlignment, "% of % should be a multiple of %") \
T(InvalidTypedArrayIndex, "Invalid typed array index") \
T(InvalidTypedArrayLength, "Invalid typed array length: %") \
T(IllegalTypeWhileStyleNarrow, \
"When style is 'narrow', 'unit' is the only allowed value for the type " \
"option.") \
T(LetInLexicalBinding, "let is disallowed as a lexically bound name") \
T(LocaleMatcher, "Illegal value for localeMatcher:%") \
T(NormalizationForm, "The normalization form should be one of %.") \
......
......@@ -33,7 +33,10 @@ const char* kStandard = "standard";
const char* kOr = "or";
const char* kUnit = "unit";
const char* kStandardShort = "standard-short";
const char* kOrShort = "or-short";
const char* kUnitShort = "unit-short";
const char* kStandardNarrow = "standard-narrow";
const char* kOrNarrow = "or-narrow";
const char* kUnitNarrow = "unit-narrow";
const char* GetIcuStyleString(JSListFormat::Style style,
......@@ -45,29 +48,19 @@ const char* GetIcuStyleString(JSListFormat::Style style,
return kStandard;
case JSListFormat::Style::SHORT:
return kStandardShort;
// NARROW is now not allowed if type is not unit
// It is impossible to reach because we've already thrown a RangeError
// when style is "narrow" and type is not "unit".
case JSListFormat::Style::NARROW:
return kStandardNarrow;
case JSListFormat::Style::COUNT:
UNREACHABLE();
}
case JSListFormat::Type::DISJUNCTION:
switch (style) {
// Currently, ListFormat::createInstance on "or-short"
// will fail so we use "or" here.
// See https://unicode.org/cldr/trac/ticket/11254
// TODO(ftang): change to return kOr or kOrShort depend on
// style after the above issue fixed in CLDR/ICU.
// CLDR bug: https://unicode.org/cldr/trac/ticket/11254
// ICU bug: https://unicode-org.atlassian.net/browse/ICU-20014
case JSListFormat::Style::LONG:
case JSListFormat::Style::SHORT:
return kOr;
// NARROW is now not allowed if type is not unit
// It is impossible to reach because we've already thrown a RangeError
// when style is "narrow" and type is not "unit".
case JSListFormat::Style::SHORT:
return kOrShort;
case JSListFormat::Style::NARROW:
return kOrNarrow;
case JSListFormat::Style::COUNT:
UNREACHABLE();
}
......@@ -181,11 +174,7 @@ MaybeHandle<JSListFormat> JSListFormat::Initialize(
// 13. Set listFormat.[[Type]] to t.
list_format->set_type(type_enum);
// 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",
// 14. 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"},
......@@ -193,15 +182,7 @@ MaybeHandle<JSListFormat> JSListFormat::Initialize(
MAYBE_RETURN(maybe_style, MaybeHandle<JSListFormat>());
Style style_enum = maybe_style.FromJust();
// 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(
isolate, NewRangeError(MessageTemplate::kIllegalTypeWhileStyleNarrow),
JSListFormat);
}
// 17. Set listFormat.[[Style]] to s.
// 15. Set listFormat.[[Style]] to s.
list_format->set_style(style_enum);
icu::Locale icu_locale = r.icu_locale;
......
......@@ -52,7 +52,8 @@ assertDoesNotThrow(
assertDoesNotThrow(
() => new Intl.ListFormat(['sr'], {style: 'short'}));
assertThrows(() => new Intl.ListFormat(['sr'], {style: 'narrow'}), RangeError);
assertDoesNotThrow(
() => new Intl.ListFormat(['sr'], {style: 'narrow'}));
assertThrows(
() => new Intl.ListFormat(['sr'], {style: 'giant'}),
......@@ -64,9 +65,8 @@ assertDoesNotThrow(
assertDoesNotThrow(
() => new Intl.ListFormat(['sr'], {type: 'conjunction', style: 'short'}));
assertThrows(
() => new Intl.ListFormat(['sr'], {type: 'conjunction', style: 'narrow'}),
RangeError);
assertDoesNotThrow(
() => new Intl.ListFormat(['sr'], {type: 'conjunction', style: 'narrow'}));
assertDoesNotThrow(
() => new Intl.ListFormat(['sr'], {type: 'disjunction', style: 'long'}));
......@@ -74,9 +74,8 @@ assertDoesNotThrow(
assertDoesNotThrow(
() => new Intl.ListFormat(['sr'], {type: 'disjunction', style: 'short'}));
assertThrows(
() => new Intl.ListFormat(['sr'], {type: 'disjunction', style: 'narrow'}),
RangeError);
assertDoesNotThrow(
() => new Intl.ListFormat(['sr'], {type: 'disjunction', style: 'narrow'}));
assertDoesNotThrow(
() => new Intl.ListFormat(['sr'], {type: 'unit', style: 'long'}));
......
......@@ -75,22 +75,20 @@ testFormatter(new Intl.ListFormat());
testFormatter(new Intl.ListFormat(["en"]));
testFormatter(new Intl.ListFormat(["en"], {style: 'long'}));
testFormatter(new Intl.ListFormat(["en"], {style: 'short'}));
assertThrows(() => new Intl.ListFormat(["en"], {style: 'narrow'}), RangeError);
testFormatter(new Intl.ListFormat(["en"], {style: 'narrow'}));
testFormatter(new Intl.ListFormat(["en"], {type: 'conjunction'}));
testFormatter(new Intl.ListFormat(["en"], {type: 'disjunction'}));
testFormatter(new Intl.ListFormat(["en"], {type: 'unit'}));
testFormatter(new Intl.ListFormat(["en"], {style: 'long', type: 'conjunction'}));
testFormatter(
new Intl.ListFormat(["en"], {style: 'short', type: 'conjunction'}));
assertThrows(
() => new Intl.ListFormat(
["en"], {style: 'narrow', type: 'conjunction'}), RangeError);
testFormatter(
new Intl.ListFormat(["en"], {style: 'narrow', type: 'conjunction'}));
testFormatter(new Intl.ListFormat(["en"], {style: 'long', type: 'disjunction'}));
testFormatter(
new Intl.ListFormat(["en"], {style: 'short', type: 'disjunction'}));
assertThrows(
() => new Intl.ListFormat(
["en"], {style: 'narrow', type: 'disjunction'}), RangeError);
testFormatter(
new Intl.ListFormat(["en"], {style: 'narrow', type: 'disjunction'}));
testFormatter(new Intl.ListFormat(["en"], {style: 'long', type: 'unit'}));
testFormatter(new Intl.ListFormat(["en"], {style: 'short', type: 'unit'}));
testFormatter(new Intl.ListFormat(["en"], {style: 'narrow', type: 'unit'}));
......@@ -46,19 +46,16 @@ testFormatter(new Intl.ListFormat());
testFormatter(new Intl.ListFormat(["en"]));
testFormatter(new Intl.ListFormat(["en"], {style: 'long'}));
testFormatter(new Intl.ListFormat(["en"], {style: 'short'}));
assertThrows(() => new Intl.ListFormat(
["en"], {style: 'narrow'}), RangeError);
testFormatter(new Intl.ListFormat(["en"], {style: 'narrow'}));
testFormatter(new Intl.ListFormat(["en"], {type: 'conjunction'}));
testFormatter(new Intl.ListFormat(["en"], {type: 'disjunction'}));
testFormatter(new Intl.ListFormat(["en"], {type: 'unit'}));
testFormatter(new Intl.ListFormat(["en"], {style: 'long', type: 'conjunction'}));
testFormatter(new Intl.ListFormat(["en"], {style: 'short', type: 'conjunction'}));
assertThrows(() => new Intl.ListFormat(
["en"], {style: 'narrow', type: 'conjunction'}), RangeError);
testFormatter(new Intl.ListFormat(["en"], {style: 'narrow', type: 'conjunction'}));
testFormatter(new Intl.ListFormat(["en"], {style: 'long', type: 'disjunction'}));
testFormatter(new Intl.ListFormat(["en"], {style: 'short', type: 'disjunction'}));
assertThrows(() => new Intl.ListFormat(
["en"], {style: 'narrow', type: 'disjunction'}), RangeError);
testFormatter(new Intl.ListFormat(["en"], {style: 'narrow', type: 'disjunction'}));
testFormatter(new Intl.ListFormat(["en"], {style: 'long', type: 'unit'}));
testFormatter(new Intl.ListFormat(["en"], {style: 'short', type: 'unit'}));
testFormatter(new Intl.ListFormat(["en"], {style: 'narrow', type: 'unit'}));
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
new Intl.ListFormat("en", {style: 'narrow'})
*%(basename)s:4: RangeError: When style is 'narrow', 'unit' is the only allowed value for the type option.
new Intl.ListFormat("en", {style: 'narrow'})
^
RangeError: When style is 'narrow', 'unit' is the only allowed value for the type option.
at new ListFormat (<anonymous>)
at *%(basename)s:4:1
......@@ -461,9 +461,6 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=7472
'intl402/NumberFormat/currency-digits': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=9040
'intl402/ListFormat/constructor/constructor/options-style-valid': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=7831
'language/statements/generators/generator-created-after-decl-inst': [FAIL],
'language/expressions/generators/generator-created-after-decl-inst': [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