Skip to content

Commit

Permalink
DO NOT USE. Hack v8 to not use ICU v63 draft stuff to test nodejs#27379
Browse files Browse the repository at this point in the history
  • Loading branch information
srl295 committed Apr 24, 2019
1 parent a763de1 commit 5972e3e
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 3 deletions.
4 changes: 4 additions & 0 deletions deps/icu-small/source/i18n/listformatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions deps/v8/src/objects/intl-objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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?");
Expand Down Expand Up @@ -519,7 +526,14 @@ std::set<std::string> Intl::BuildLocaleSet(

Maybe<std::string> 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<std::string>(status);
#endif
if (U_FAILURE(status)) {
return Nothing<std::string>();
}
Expand Down Expand Up @@ -781,7 +795,14 @@ Maybe<std::string> 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,
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/objects/intl-objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion deps/v8/src/objects/js-list-format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ MaybeHandle<JSArray> GenerateListFormatParts(
Handle<String> 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,
Expand Down Expand Up @@ -323,11 +325,13 @@ std::vector<icu::FieldPosition> 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.
Expand Down Expand Up @@ -436,8 +440,12 @@ MaybeHandle<JSArray> 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<int32_t>(array.size()), formatted,
&iter, status);
#else
if(U_SUCCESS(status)) status = U_REGEX_OCTAL_TOO_BIG;
#endif
DCHECK(U_SUCCESS(status));

std::vector<icu::FieldPosition> field_positions = GenerateFieldPosition(iter);
Expand Down
39 changes: 39 additions & 0 deletions deps/v8/src/objects/js-locale.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,15 @@ Handle<Object> UnicodeKeywordValue(Isolate* isolate, Handle<JSLocale> 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<std::string>(key, status);
#endif
if (status == U_ILLEGAL_ARGUMENT_ERROR || value == "") {
return isolate->factory()->undefined_value();
}
Expand Down Expand Up @@ -260,8 +267,15 @@ Maybe<std::string> ApplyOptionsToTag(Isolate* isolate, Handle<String> tag,
Nothing<std::string>());
}
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),
Expand Down Expand Up @@ -400,8 +414,15 @@ MaybeHandle<JSLocale> JSLocale::Initialize(Isolate* isolate,
ApplyOptionsToTag(isolate, locale_str, options);
MAYBE_RETURN(maybe_locale, MaybeHandle<JSLocale>());
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),
Expand All @@ -428,8 +449,15 @@ namespace {
Handle<String> 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
Expand All @@ -448,14 +476,18 @@ Handle<String> MorphLocale(Isolate* isolate, String locale,
Handle<String> 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<String> 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
});
}

Expand Down Expand Up @@ -507,8 +539,15 @@ Handle<Object> JSLocale::Numeric(Isolate* isolate, Handle<JSLocale> 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<std::string>("kn", status);
#endif
return (numeric == "true") ? factory->true_value() : factory->false_value();
}

Expand Down
1 change: 1 addition & 0 deletions deps/v8/src/objects/js-plural-rules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "unicode/locid.h"
#include "unicode/numfmt.h"
#include "unicode/plurrule.h"
#include "unicode/strenum.h"

namespace v8 {
namespace internal {
Expand Down
2 changes: 1 addition & 1 deletion tools/icu/icu_versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"minimum_icu": 63
"minimum_icu": 62
}

0 comments on commit 5972e3e

Please sign in to comment.