diff --git a/common.gypi b/common.gypi index 476cd2dbdd1606..fec140bbae983b 100644 --- a/common.gypi +++ b/common.gypi @@ -35,7 +35,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.31', + 'v8_embedder_string': '-node.32', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/objects/js-number-format.cc b/deps/v8/src/objects/js-number-format.cc index 92d3e2fb82eaed..ced408aa173d92 100644 --- a/deps/v8/src/objects/js-number-format.cc +++ b/deps/v8/src/objects/js-number-format.cc @@ -1197,42 +1197,31 @@ MaybeHandle JSNumberFormat::New(Isolate* isolate, } namespace { -Maybe IcuFormatNumber( +Maybe IcuFormatNumber( Isolate* isolate, const icu::number::LocalizedNumberFormatter& number_format, - Handle numeric_obj, icu::FieldPositionIterator* fp_iter) { + Handle numeric_obj, icu::number::FormattedNumber* formatted) { // If it is BigInt, handle it differently. UErrorCode status = U_ZERO_ERROR; - icu::number::FormattedNumber formatted; if (numeric_obj->IsBigInt()) { Handle big_int = Handle::cast(numeric_obj); Handle big_int_string; ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, big_int_string, BigInt::ToString(isolate, big_int), - Nothing()); - formatted = number_format.formatDecimal( + Nothing()); + *formatted = number_format.formatDecimal( {big_int_string->ToCString().get(), big_int_string->length()}, status); } else { double number = numeric_obj->Number(); - formatted = number_format.formatDouble(number, status); + *formatted = number_format.formatDouble(number, status); } if (U_FAILURE(status)) { // This happen because of icu data trimming trim out "unit". // See https://bugs.chromium.org/p/v8/issues/detail?id=8641 - THROW_NEW_ERROR_RETURN_VALUE(isolate, - NewTypeError(MessageTemplate::kIcuError), - Nothing()); - } - if (fp_iter) { - formatted.getAllFieldPositions(*fp_iter, status); + THROW_NEW_ERROR_RETURN_VALUE( + isolate, NewTypeError(MessageTemplate::kIcuError), Nothing()); } - icu::UnicodeString result = formatted.toString(status); - if (U_FAILURE(status)) { - THROW_NEW_ERROR_RETURN_VALUE(isolate, - NewTypeError(MessageTemplate::kIcuError), - Nothing()); - } - return Just(result); + return Just(true); } } // namespace @@ -1243,10 +1232,16 @@ MaybeHandle JSNumberFormat::FormatNumeric( Handle numeric_obj) { DCHECK(numeric_obj->IsNumeric()); - Maybe maybe_format = - IcuFormatNumber(isolate, number_format, numeric_obj, nullptr); + icu::number::FormattedNumber formatted; + Maybe maybe_format = + IcuFormatNumber(isolate, number_format, numeric_obj, &formatted); MAYBE_RETURN(maybe_format, Handle()); - 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 { @@ -1359,12 +1354,18 @@ std::vector FlattenRegionsToParts( } namespace { -Maybe ConstructParts(Isolate* isolate, const icu::UnicodeString& formatted, - icu::FieldPositionIterator* fp_iter, +Maybe ConstructParts(Isolate* isolate, + icu::number::FormattedNumber* formatted, Handle result, int start_index, Handle 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()); + } DCHECK(numeric_obj->IsNumeric()); - int32_t length = formatted.length(); + int32_t length = formatted_text.length(); int index = start_index; if (length == 0) return Just(index); @@ -1373,13 +1374,14 @@ Maybe ConstructParts(Isolate* isolate, const icu::UnicodeString& formatted, // 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, // 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; - while (fp_iter->next(fp)) { - regions.push_back(NumberFormatSpan(fp.getField(), fp.getBeginIndex(), - fp.getEndIndex())); + icu::ConstrainedFieldPosition cfp; + cfp.constrainCategory(UFIELD_CATEGORY_NUMBER); + while (formatted->nextPosition(cfp, status)) { + regions.push_back( + NumberFormatSpan(cfp.getField(), cfp.getStart(), cfp.getLimit())); } } @@ -1401,7 +1403,7 @@ Maybe ConstructParts(Isolate* isolate, const icu::UnicodeString& formatted, Handle substring; ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate, substring, - Intl::ToString(isolate, formatted, part.begin_pos, part.end_pos), + Intl::ToString(isolate, formatted_text, part.begin_pos, part.end_pos), Nothing()); Intl::AddElement(isolate, result, index, field_type_string, substring); ++index; @@ -1421,14 +1423,14 @@ MaybeHandle JSNumberFormat::FormatToParts( number_format->icu_number_formatter().raw(); CHECK_NOT_NULL(fmt); - icu::FieldPositionIterator fp_iter; - Maybe maybe_format = - IcuFormatNumber(isolate, *fmt, numeric_obj, &fp_iter); + icu::number::FormattedNumber formatted; + Maybe maybe_format = + IcuFormatNumber(isolate, *fmt, numeric_obj, &formatted); MAYBE_RETURN(maybe_format, Handle()); Handle result = factory->NewJSArray(0); Maybe maybe_format_to_parts = ConstructParts( - isolate, maybe_format.FromJust(), &fp_iter, result, 0, numeric_obj, + isolate, &formatted, result, 0, numeric_obj, number_format->style() == JSNumberFormat::Style::UNIT); MAYBE_RETURN(maybe_format_to_parts, Handle());