Skip to content

Commit

Permalink
Fix build with ICU >= 68.
Browse files Browse the repository at this point in the history
Adapted from:
https://chromium-review.googlesource.com/c/v8/v8/+/2477751

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
  • Loading branch information
jameshilliard authored and richardlau committed Jul 23, 2021
1 parent 8a9f949 commit 34a9207
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions deps/v8/src/objects/js-list-format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace v8 {
namespace internal {

namespace {
#if U_ICU_VERSION_MAJOR_NUM < 68
const char* kStandard = "standard";
const char* kOr = "or";
const char* kUnit = "unit";
Expand All @@ -41,8 +42,24 @@ const char* kUnitNarrow = "unit-narrow";

const char* GetIcuStyleString(JSListFormat::Style style,
JSListFormat::Type type) {
#else
UListFormatterWidth GetIcuWidth(JSListFormat::Style style) {
switch (style) {
case JSListFormat::Style::LONG:
return ULISTFMT_WIDTH_WIDE;
case JSListFormat::Style::SHORT:
return ULISTFMT_WIDTH_SHORT;
case JSListFormat::Style::NARROW:
return ULISTFMT_WIDTH_NARROW;
}
UNREACHABLE();
}

UListFormatterType GetIcuType(JSListFormat::Type type) {
#endif
switch (type) {
case JSListFormat::Type::CONJUNCTION:
#if U_ICU_VERSION_MAJOR_NUM < 68
switch (style) {
case JSListFormat::Style::LONG:
return kStandard;
Expand All @@ -51,7 +68,11 @@ const char* GetIcuStyleString(JSListFormat::Style style,
case JSListFormat::Style::NARROW:
return kStandardNarrow;
}
#else
return ULISTFMT_TYPE_AND;
#endif
case JSListFormat::Type::DISJUNCTION:
#if U_ICU_VERSION_MAJOR_NUM < 68
switch (style) {
case JSListFormat::Style::LONG:
return kOr;
Expand All @@ -60,7 +81,11 @@ const char* GetIcuStyleString(JSListFormat::Style style,
case JSListFormat::Style::NARROW:
return kOrNarrow;
}
#else
return ULISTFMT_TYPE_OR;
#endif
case JSListFormat::Type::UNIT:
#if U_ICU_VERSION_MAJOR_NUM < 68
switch (style) {
case JSListFormat::Style::LONG:
return kUnit;
Expand All @@ -69,6 +94,9 @@ const char* GetIcuStyleString(JSListFormat::Style style,
case JSListFormat::Style::NARROW:
return kUnitNarrow;
}
#else
return ULISTFMT_TYPE_UNITS;
#endif
}
UNREACHABLE();
}
Expand Down Expand Up @@ -170,7 +198,11 @@ MaybeHandle<JSListFormat> JSListFormat::New(Isolate* isolate, Handle<Map> map,
icu::Locale icu_locale = r.icu_locale;
UErrorCode status = U_ZERO_ERROR;
icu::ListFormatter* formatter = icu::ListFormatter::createInstance(
#if U_ICU_VERSION_MAJOR_NUM < 68
icu_locale, GetIcuStyleString(style_enum, type_enum), status);
#else
icu_locale, GetIcuType(type_enum), GetIcuWidth(style_enum), status);
#endif
if (U_FAILURE(status)) {
delete formatter;
FATAL("Failed to create ICU list formatter, are ICU data files missing?");
Expand Down

0 comments on commit 34a9207

Please sign in to comment.