From 5972e3e5163a5901d10dd4d310675fd788d42d5e Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Wed, 24 Apr 2019 12:35:27 -0700 Subject: [PATCH] DO NOT USE. Hack v8 to not use ICU v63 draft stuff to test https://github.com/nodejs/node/issues/27379 --- deps/icu-small/source/i18n/listformatter.cpp | 4 ++ deps/v8/src/objects/intl-objects.cc | 21 +++++++++++ deps/v8/src/objects/intl-objects.h | 2 +- deps/v8/src/objects/js-list-format.cc | 10 ++++- deps/v8/src/objects/js-locale.cc | 39 ++++++++++++++++++++ deps/v8/src/objects/js-plural-rules.cc | 1 + tools/icu/icu_versions.json | 2 +- 7 files changed, 76 insertions(+), 3 deletions(-) diff --git a/deps/icu-small/source/i18n/listformatter.cpp b/deps/icu-small/source/i18n/listformatter.cpp index d9195348529c57..935c7e70bdb5b5 100644 --- a/deps/icu-small/source/i18n/listformatter.cpp +++ b/deps/icu-small/source/i18n/listformatter.cpp @@ -415,11 +415,13 @@ UnicodeString& ListFormatter::format_( if (index == 0) { offset = appendTo.length(); } +#if U_ICU_VERSION_MAJOR_NUM >= 63 if (handler != nullptr) { handler->addAttribute(ULISTFMT_ELEMENT_FIELD, appendTo.length(), appendTo.length() + items[0].length()); } +#endif appendTo.append(items[0]); return appendTo; } @@ -484,6 +486,7 @@ UnicodeString& ListFormatter::format_( // If there are already some data in appendTo, we need to adjust the index // by shifting that lenght while insert into handler. int32_t shift = appendTo.length() + prefixLength; +#if U_ICU_VERSION_MAJOR_NUM >= 63 // Output the ULISTFMT_ELEMENT_FIELD in the order of the input elements for (int32_t i = 0; i < nItems; ++i) { offsets[i + nItems] = offsets[i] + items[i].length() + shift; @@ -493,6 +496,7 @@ UnicodeString& ListFormatter::format_( offsets[i], // index offsets[i + nItems]); // limit } +#endif // The locale pattern may reorder the items (such as in ur-IN locale), // so we cannot assume the array is in accendning order. // To handle the edging case, just insert the two ends into the array diff --git a/deps/v8/src/objects/intl-objects.cc b/deps/v8/src/objects/intl-objects.cc index b990a85bed6886..d4563f32d8658d 100644 --- a/deps/v8/src/objects/intl-objects.cc +++ b/deps/v8/src/objects/intl-objects.cc @@ -410,7 +410,14 @@ icu::Locale Intl::CreateICULocale(const std::string& bcp47_locale) { // Convert BCP47 into ICU locale format. UErrorCode status = U_ZERO_ERROR; +#if U_ICU_VERSION_MAJOR_NUM < 63 + char buf[ULOC_FULLNAME_CAPACITY+1] = {0}; + int32_t len = uloc_forLanguageTag(bcp47_locale.c_str(), buf, ULOC_FULLNAME_CAPACITY+1, + NULL, &status); + icu::Locale icu_locale(buf); +#else icu::Locale icu_locale = icu::Locale::forLanguageTag(bcp47_locale, status); +#endif CHECK(U_SUCCESS(status)); if (icu_locale.isBogus()) { FATAL("Failed to create ICU locale, are ICU data files missing?"); @@ -519,7 +526,14 @@ std::set Intl::BuildLocaleSet( Maybe Intl::ToLanguageTag(const icu::Locale& locale) { UErrorCode status = U_ZERO_ERROR; +#if U_ICU_VERSION_MAJOR_NUM < 63 + char buf[ULOC_FULLNAME_CAPACITY] = {0}; + int32_t len = + uloc_toLanguageTag(locale.getName(), buf, ULOC_FULLNAME_CAPACITY+1, false, &status); + std::string res(buf, len); +#else std::string res = locale.toLanguageTag(status); +#endif if (U_FAILURE(status)) { return Nothing(); } @@ -781,7 +795,14 @@ Maybe Intl::CanonicalizeLanguageTag(Isolate* isolate, // language tag is parsed all the way to the end, it indicates that the input // is structurally valid. Due to a couple of bugs, we can't use it // without Chromium patches or ICU 62 or earlier. +#if U_ICU_VERSION_MAJOR_NUM < 63 + char buf[ULOC_FULLNAME_CAPACITY+1] = {0}; + int32_t len = uloc_forLanguageTag(locale.c_str(), buf, ULOC_FULLNAME_CAPACITY+1, + NULL, &error); + icu::Locale icu_locale(buf); +#else icu::Locale icu_locale = icu::Locale::forLanguageTag(locale.c_str(), error); +#endif if (U_FAILURE(error) || icu_locale.isBogus()) { THROW_NEW_ERROR_RETURN_VALUE( isolate, diff --git a/deps/v8/src/objects/intl-objects.h b/deps/v8/src/objects/intl-objects.h index 4dcafab793db8f..174db582c1347e 100644 --- a/deps/v8/src/objects/intl-objects.h +++ b/deps/v8/src/objects/intl-objects.h @@ -20,7 +20,7 @@ #include "unicode/locid.h" #include "unicode/uversion.h" -#define V8_MINIMUM_ICU_VERSION 63 +#define V8_MINIMUM_ICU_VERSION 62 namespace U_ICU_NAMESPACE { class BreakIterator; diff --git a/deps/v8/src/objects/js-list-format.cc b/deps/v8/src/objects/js-list-format.cc index dd7ab172afa8ce..dc590c942e11af 100644 --- a/deps/v8/src/objects/js-list-format.cc +++ b/deps/v8/src/objects/js-list-format.cc @@ -284,7 +284,9 @@ MaybeHandle GenerateListFormatParts( Handle substring; for (const icu::FieldPosition pos : positions) { CHECK(pos.getBeginIndex() >= prev_item_end_index); +#if U_ICU_VERSION_MAJOR_NUM >= 63 CHECK(pos.getField() == ULISTFMT_ELEMENT_FIELD); +#endif if (pos.getBeginIndex() != prev_item_end_index) { ASSIGN_RETURN_ON_EXCEPTION( isolate, substring, @@ -323,11 +325,13 @@ std::vector GenerateFieldPosition( icu::FieldPosition pos; while (iter.next(pos)) { // Only take the information of the ULISTFMT_ELEMENT_FIELD field. +#if U_ICU_VERSION_MAJOR_NUM >= 63 if (pos.getField() == ULISTFMT_ELEMENT_FIELD) { positions.push_back(pos); } +#endif } - // Because the format may reoder the items, ICU FieldPositionIterator + // Because the format may reorder the items, ICU FieldPositionIterator // keep the order for FieldPosition based on the order of the input items. // But the formatToParts API in ECMA402 expects in formatted output order. // Therefore we have to sort based on beginIndex of the FieldPosition. @@ -436,8 +440,12 @@ MaybeHandle JSListFormat::FormatListToParts( UErrorCode status = U_ZERO_ERROR; icu::UnicodeString formatted; icu::FieldPositionIterator iter; +#if U_ICU_VERSION_MAJOR_NUM >= 63 formatter->format(array.data(), static_cast(array.size()), formatted, &iter, status); +#else + if(U_SUCCESS(status)) status = U_REGEX_OCTAL_TOO_BIG; +#endif DCHECK(U_SUCCESS(status)); std::vector field_positions = GenerateFieldPosition(iter); diff --git a/deps/v8/src/objects/js-locale.cc b/deps/v8/src/objects/js-locale.cc index 94b4cb2aba8703..97e6ec5bc43d82 100644 --- a/deps/v8/src/objects/js-locale.cc +++ b/deps/v8/src/objects/js-locale.cc @@ -129,8 +129,15 @@ Handle UnicodeKeywordValue(Isolate* isolate, Handle locale, const char* key) { icu::Locale* icu_locale = locale->icu_locale()->raw(); UErrorCode status = U_ZERO_ERROR; +#if U_ICU_VERSION_MAJOR_NUM < 63 + char buf[ULOC_FULLNAME_CAPACITY] = {0}; + int32_t len = + icu_locale -> getKeywordValue(key, buf, ULOC_FULLNAME_CAPACITY, status); + std::string value(buf, len); +#else std::string value = icu_locale->getUnicodeKeywordValue(key, status); +#endif if (status == U_ILLEGAL_ARGUMENT_ERROR || value == "") { return isolate->factory()->undefined_value(); } @@ -260,8 +267,15 @@ Maybe ApplyOptionsToTag(Isolate* isolate, Handle tag, Nothing()); } UErrorCode status = U_ZERO_ERROR; +#if U_ICU_VERSION_MAJOR_NUM < 63 + char buf[ULOC_FULLNAME_CAPACITY+1] = {0}; + int32_t len = uloc_forLanguageTag(*bcp47_tag, buf, ULOC_FULLNAME_CAPACITY+1, + NULL, &status); + icu::Locale icu_locale(buf); +#else icu::Locale icu_locale = icu::Locale::forLanguageTag({*bcp47_tag, bcp47_tag.length()}, status); +#endif if (U_FAILURE(status)) { THROW_NEW_ERROR_RETURN_VALUE( isolate, NewRangeError(MessageTemplate::kLocaleBadParameters), @@ -400,8 +414,15 @@ MaybeHandle JSLocale::Initialize(Isolate* isolate, ApplyOptionsToTag(isolate, locale_str, options); MAYBE_RETURN(maybe_locale, MaybeHandle()); UErrorCode status = U_ZERO_ERROR; +#if U_ICU_VERSION_MAJOR_NUM < 63 + char buf[ULOC_FULLNAME_CAPACITY+1] = {0}; + int32_t len = uloc_forLanguageTag(maybe_locale.FromJust().c_str(), buf, ULOC_FULLNAME_CAPACITY+1, + NULL, &status); + icu::Locale icu_locale(buf); +#else icu::Locale icu_locale = icu::Locale::forLanguageTag(maybe_locale.FromJust().c_str(), status); +#endif if (U_FAILURE(status)) { THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kLocaleBadParameters), @@ -428,8 +449,15 @@ namespace { Handle MorphLocale(Isolate* isolate, String locale, void (*morph_func)(icu::Locale*, UErrorCode*)) { UErrorCode status = U_ZERO_ERROR; +#if U_ICU_VERSION_MAJOR_NUM < 63 + char buf[ULOC_FULLNAME_CAPACITY+1] = {0}; + int32_t len = uloc_forLanguageTag(locale.ToCString().get(), buf, ULOC_FULLNAME_CAPACITY+1, + NULL, &status); + icu::Locale icu_locale(buf); +#else icu::Locale icu_locale = icu::Locale::forLanguageTag(locale.ToCString().get(), status); +#endif // TODO(ftang): Remove the following lines after ICU-8420 fixed. // Due to ICU-8420 "und" is turn into "" by forLanguageTag, // we have to work around to use icu::Locale("und") directly @@ -448,14 +476,18 @@ Handle MorphLocale(Isolate* isolate, String locale, Handle JSLocale::Maximize(Isolate* isolate, String locale) { return MorphLocale(isolate, locale, [](icu::Locale* icu_locale, UErrorCode* status) { +#if U_ICU_VERSION_MAJOR_NUM >= 63 icu_locale->addLikelySubtags(*status); +#endif }); } Handle JSLocale::Minimize(Isolate* isolate, String locale) { return MorphLocale(isolate, locale, [](icu::Locale* icu_locale, UErrorCode* status) { +#if U_ICU_VERSION_MAJOR_NUM >= 63 icu_locale->minimizeSubtags(*status); +#endif }); } @@ -507,8 +539,15 @@ Handle JSLocale::Numeric(Isolate* isolate, Handle locale) { Factory* factory = isolate->factory(); icu::Locale* icu_locale = locale->icu_locale()->raw(); UErrorCode status = U_ZERO_ERROR; +#if U_ICU_VERSION_MAJOR_NUM < 63 + char buf[ULOC_FULLNAME_CAPACITY] = {0}; + int32_t len = + icu_locale -> getKeywordValue("kn", buf, ULOC_FULLNAME_CAPACITY, status); + std::string numeric(buf, len); +#else std::string numeric = icu_locale->getUnicodeKeywordValue("kn", status); +#endif return (numeric == "true") ? factory->true_value() : factory->false_value(); } diff --git a/deps/v8/src/objects/js-plural-rules.cc b/deps/v8/src/objects/js-plural-rules.cc index da349dcd8159fc..ae560a5055c8e6 100644 --- a/deps/v8/src/objects/js-plural-rules.cc +++ b/deps/v8/src/objects/js-plural-rules.cc @@ -15,6 +15,7 @@ #include "unicode/locid.h" #include "unicode/numfmt.h" #include "unicode/plurrule.h" +#include "unicode/strenum.h" namespace v8 { namespace internal { diff --git a/tools/icu/icu_versions.json b/tools/icu/icu_versions.json index 7224e9debec893..a2f6f280f25e9f 100644 --- a/tools/icu/icu_versions.json +++ b/tools/icu/icu_versions.json @@ -1,3 +1,3 @@ { - "minimum_icu": 63 + "minimum_icu": 62 }