Commit 3f8dc4b2 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[intl] Remove soon-to-be removed getAllFieldPositions

Needed to land ICU67.1 soon.

Bug: v8:10393
Change-Id: I3c7737ca600d6ccfdc46ffaddfb318ce60bc7618
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2136489Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67027}
parent 44d3ae70
...@@ -1241,44 +1241,33 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::New(Isolate* isolate, ...@@ -1241,44 +1241,33 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::New(Isolate* isolate,
} }
namespace { namespace {
Maybe<icu::UnicodeString> IcuFormatNumber( Maybe<bool> IcuFormatNumber(
Isolate* isolate, Isolate* isolate,
const icu::number::LocalizedNumberFormatter& number_format, const icu::number::LocalizedNumberFormatter& number_format,
Handle<Object> numeric_obj, icu::FieldPositionIterator* fp_iter) { Handle<Object> numeric_obj, icu::number::FormattedNumber* formatted) {
// If it is BigInt, handle it differently. // If it is BigInt, handle it differently.
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
icu::number::FormattedNumber formatted;
if (numeric_obj->IsBigInt()) { if (numeric_obj->IsBigInt()) {
Handle<BigInt> big_int = Handle<BigInt>::cast(numeric_obj); Handle<BigInt> big_int = Handle<BigInt>::cast(numeric_obj);
Handle<String> big_int_string; Handle<String> big_int_string;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, big_int_string, ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, big_int_string,
BigInt::ToString(isolate, big_int), BigInt::ToString(isolate, big_int),
Nothing<icu::UnicodeString>()); Nothing<bool>());
formatted = number_format.formatDecimal( *formatted = number_format.formatDecimal(
{big_int_string->ToCString().get(), big_int_string->length()}, status); {big_int_string->ToCString().get(), big_int_string->length()}, status);
} else { } else {
double number = numeric_obj->IsNaN() double number = numeric_obj->IsNaN()
? std::numeric_limits<double>::quiet_NaN() ? std::numeric_limits<double>::quiet_NaN()
: numeric_obj->Number(); : numeric_obj->Number();
formatted = number_format.formatDouble(number, status); *formatted = number_format.formatDouble(number, status);
} }
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
// This happen because of icu data trimming trim out "unit". // This happen because of icu data trimming trim out "unit".
// See https://bugs.chromium.org/p/v8/issues/detail?id=8641 // See https://bugs.chromium.org/p/v8/issues/detail?id=8641
THROW_NEW_ERROR_RETURN_VALUE(isolate, THROW_NEW_ERROR_RETURN_VALUE(
NewTypeError(MessageTemplate::kIcuError), isolate, NewTypeError(MessageTemplate::kIcuError), Nothing<bool>());
Nothing<icu::UnicodeString>());
}
if (fp_iter) {
formatted.getAllFieldPositions(*fp_iter, status);
}
icu::UnicodeString result = formatted.toString(status);
if (U_FAILURE(status)) {
THROW_NEW_ERROR_RETURN_VALUE(isolate,
NewTypeError(MessageTemplate::kIcuError),
Nothing<icu::UnicodeString>());
} }
return Just(result); return Just(true);
} }
} // namespace } // namespace
...@@ -1289,10 +1278,16 @@ MaybeHandle<String> JSNumberFormat::FormatNumeric( ...@@ -1289,10 +1278,16 @@ MaybeHandle<String> JSNumberFormat::FormatNumeric(
Handle<Object> numeric_obj) { Handle<Object> numeric_obj) {
DCHECK(numeric_obj->IsNumeric()); DCHECK(numeric_obj->IsNumeric());
Maybe<icu::UnicodeString> maybe_format = icu::number::FormattedNumber formatted;
IcuFormatNumber(isolate, number_format, numeric_obj, nullptr); Maybe<bool> maybe_format =
IcuFormatNumber(isolate, number_format, numeric_obj, &formatted);
MAYBE_RETURN(maybe_format, Handle<String>()); MAYBE_RETURN(maybe_format, Handle<String>());
return Intl::ToString(isolate, maybe_format.FromJust()); UErrorCode status = U_ZERO_ERROR;
icu::UnicodeString result = formatted.toString(status);
if (U_FAILURE(status)) {
THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kIcuError), String);
}
return Intl::ToString(isolate, result);
} }
namespace { namespace {
...@@ -1405,12 +1400,18 @@ std::vector<NumberFormatSpan> FlattenRegionsToParts( ...@@ -1405,12 +1400,18 @@ std::vector<NumberFormatSpan> FlattenRegionsToParts(
} }
namespace { namespace {
Maybe<int> ConstructParts(Isolate* isolate, const icu::UnicodeString& formatted, Maybe<int> ConstructParts(Isolate* isolate,
icu::FieldPositionIterator* fp_iter, icu::number::FormattedNumber* formatted,
Handle<JSArray> result, int start_index, Handle<JSArray> result, int start_index,
Handle<Object> numeric_obj, bool style_is_unit) { Handle<Object> numeric_obj, bool style_is_unit) {
UErrorCode status = U_ZERO_ERROR;
icu::UnicodeString formatted_text = formatted->toString(status);
if (U_FAILURE(status)) {
THROW_NEW_ERROR_RETURN_VALUE(
isolate, NewTypeError(MessageTemplate::kIcuError), Nothing<int>());
}
DCHECK(numeric_obj->IsNumeric()); DCHECK(numeric_obj->IsNumeric());
int32_t length = formatted.length(); int32_t length = formatted_text.length();
int index = start_index; int index = start_index;
if (length == 0) return Just(index); if (length == 0) return Just(index);
...@@ -1419,13 +1420,14 @@ Maybe<int> ConstructParts(Isolate* isolate, const icu::UnicodeString& formatted, ...@@ -1419,13 +1420,14 @@ Maybe<int> ConstructParts(Isolate* isolate, const icu::UnicodeString& formatted,
// other region covers some part of the formatted string. It's possible // other region covers some part of the formatted string. It's possible
// there's another field with exactly the same begin and end as this backdrop, // there's another field with exactly the same begin and end as this backdrop,
// in which case the backdrop's field_id of -1 will give it lower priority. // in which case the backdrop's field_id of -1 will give it lower priority.
regions.push_back(NumberFormatSpan(-1, 0, formatted.length())); regions.push_back(NumberFormatSpan(-1, 0, formatted_text.length()));
{ {
icu::FieldPosition fp; icu::ConstrainedFieldPosition cfp;
while (fp_iter->next(fp)) { cfp.constrainCategory(UFIELD_CATEGORY_NUMBER);
regions.push_back(NumberFormatSpan(fp.getField(), fp.getBeginIndex(), while (formatted->nextPosition(cfp, status)) {
fp.getEndIndex())); regions.push_back(
NumberFormatSpan(cfp.getField(), cfp.getStart(), cfp.getLimit()));
} }
} }
...@@ -1447,7 +1449,7 @@ Maybe<int> ConstructParts(Isolate* isolate, const icu::UnicodeString& formatted, ...@@ -1447,7 +1449,7 @@ Maybe<int> ConstructParts(Isolate* isolate, const icu::UnicodeString& formatted,
Handle<String> substring; Handle<String> substring;
ASSIGN_RETURN_ON_EXCEPTION_VALUE( ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, substring, isolate, substring,
Intl::ToString(isolate, formatted, part.begin_pos, part.end_pos), Intl::ToString(isolate, formatted_text, part.begin_pos, part.end_pos),
Nothing<int>()); Nothing<int>());
Intl::AddElement(isolate, result, index, field_type_string, substring); Intl::AddElement(isolate, result, index, field_type_string, substring);
++index; ++index;
...@@ -1467,20 +1469,19 @@ MaybeHandle<JSArray> JSNumberFormat::FormatToParts( ...@@ -1467,20 +1469,19 @@ MaybeHandle<JSArray> JSNumberFormat::FormatToParts(
number_format->icu_number_formatter().raw(); number_format->icu_number_formatter().raw();
CHECK_NOT_NULL(fmt); CHECK_NOT_NULL(fmt);
icu::FieldPositionIterator fp_iter; icu::number::FormattedNumber formatted;
Maybe<icu::UnicodeString> maybe_format = Maybe<bool> maybe_format =
IcuFormatNumber(isolate, *fmt, numeric_obj, &fp_iter); IcuFormatNumber(isolate, *fmt, numeric_obj, &formatted);
MAYBE_RETURN(maybe_format, Handle<JSArray>()); MAYBE_RETURN(maybe_format, Handle<JSArray>());
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
bool style_is_unit = bool style_is_unit =
Style::UNIT == StyleFromSkeleton(fmt->toSkeleton(status)); Style::UNIT == StyleFromSkeleton(fmt->toSkeleton(status));
CHECK(U_SUCCESS(status)); CHECK(U_SUCCESS(status));
Handle<JSArray> result = factory->NewJSArray(0); Handle<JSArray> result = factory->NewJSArray(0);
Maybe<int> maybe_format_to_parts = Maybe<int> maybe_format_to_parts = ConstructParts(
ConstructParts(isolate, maybe_format.FromJust(), &fp_iter, result, 0, isolate, &formatted, result, 0, numeric_obj, style_is_unit);
numeric_obj, style_is_unit);
MAYBE_RETURN(maybe_format_to_parts, Handle<JSArray>()); MAYBE_RETURN(maybe_format_to_parts, Handle<JSArray>());
return result; return result;
......
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