|
28 | 28 | namespace v8 { |
29 | 29 | namespace internal { |
30 | 30 |
|
| 31 | +#if U_ICU_VERSION_MAJOR_NUM >= 67 |
| 32 | +namespace { |
| 33 | + |
| 34 | +UListFormatterWidth GetIcuWidth(JSListFormat::Style style) { |
| 35 | + switch (style) { |
| 36 | + case JSListFormat::Style::LONG: |
| 37 | + return ULISTFMT_WIDTH_WIDE; |
| 38 | + case JSListFormat::Style::SHORT: |
| 39 | + return ULISTFMT_WIDTH_SHORT; |
| 40 | + case JSListFormat::Style::NARROW: |
| 41 | + return ULISTFMT_WIDTH_NARROW; |
| 42 | + } |
| 43 | + UNREACHABLE(); |
| 44 | +} |
| 45 | + |
| 46 | +UListFormatterType GetIcuType(JSListFormat::Type type) { |
| 47 | + switch (type) { |
| 48 | + case JSListFormat::Type::CONJUNCTION: |
| 49 | + return ULISTFMT_TYPE_AND; |
| 50 | + case JSListFormat::Type::DISJUNCTION: |
| 51 | + return ULISTFMT_TYPE_OR; |
| 52 | + case JSListFormat::Type::UNIT: |
| 53 | + return ULISTFMT_TYPE_UNITS; |
| 54 | + } |
| 55 | + UNREACHABLE(); |
| 56 | +} |
| 57 | + |
| 58 | +} // namespace |
| 59 | +#else |
31 | 60 | namespace { |
32 | 61 | const char* kStandard = "standard"; |
33 | 62 | const char* kOr = "or"; |
@@ -74,7 +103,7 @@ const char* GetIcuStyleString(JSListFormat::Style style, |
74 | 103 | } |
75 | 104 |
|
76 | 105 | } // namespace |
77 | | - |
| 106 | +#endif |
78 | 107 | MaybeHandle<JSListFormat> JSListFormat::New(Isolate* isolate, Handle<Map> map, |
79 | 108 | Handle<Object> locales, |
80 | 109 | Handle<Object> input_options) { |
@@ -143,7 +172,11 @@ MaybeHandle<JSListFormat> JSListFormat::New(Isolate* isolate, Handle<Map> map, |
143 | 172 | icu::Locale icu_locale = r.icu_locale; |
144 | 173 | UErrorCode status = U_ZERO_ERROR; |
145 | 174 | icu::ListFormatter* formatter = icu::ListFormatter::createInstance( |
| 175 | +#if U_ICU_VERSION_MAJOR_NUM >= 67 |
| 176 | + icu_locale, GetIcuType(type_enum), GetIcuWidth(style_enum), status); |
| 177 | +#else |
146 | 178 | icu_locale, GetIcuStyleString(style_enum, type_enum), status); |
| 179 | +#endif |
147 | 180 | if (U_FAILURE(status) || formatter == nullptr) { |
148 | 181 | delete formatter; |
149 | 182 | THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kIcuError), |
|
0 commit comments