]>
Commit | Line | Data |
---|---|---|
6b0906cb JP |
1 | From 2b107e7670ffb43719a66ee4a55ab408a5dcf2a5 Mon Sep 17 00:00:00 2001 |
2 | From: Ujjwal Sharma <ryzokuken@disroot.org> | |
3 | Date: Wed, 22 Apr 2020 12:20:17 +0530 | |
4 | Subject: [PATCH] deps: V8: backport 3f8dc4b2e5ba | |
5 | ||
6 | Original commit message: | |
7 | ||
8 | [intl] Remove soon-to-be removed getAllFieldPositions | |
9 | ||
10 | Needed to land ICU67.1 soon. | |
11 | ||
12 | Bug: v8:10393 | |
13 | Change-Id: I3c7737ca600d6ccfdc46ffaddfb318ce60bc7618 | |
14 | Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2136489 | |
15 | Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> | |
16 | Commit-Queue: Frank Tang <ftang@chromium.org> | |
17 | Cr-Commit-Position: refs/heads/master@{#67027} | |
18 | ||
19 | Refs: https://github.com/v8/v8/commit/3f8dc4b2e5baf77b463334c769af85b79d8c1463 | |
20 | --- | |
21 | common.gypi | 2 +- | |
22 | deps/v8/src/objects/js-number-format.cc | 72 +++++++++++++------------ | |
23 | 2 files changed, 38 insertions(+), 36 deletions(-) | |
24 | ||
25 | diff --git a/deps/v8/src/objects/js-number-format.cc b/deps/v8/src/objects/js-number-format.cc | |
26 | index 92d3e2fb82e..ced408aa173 100644 | |
27 | --- a/deps/v8/src/objects/js-number-format.cc | |
28 | +++ b/deps/v8/src/objects/js-number-format.cc | |
29 | @@ -1197,42 +1197,31 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::New(Isolate* isolate, | |
30 | } | |
31 | ||
32 | namespace { | |
33 | -Maybe<icu::UnicodeString> IcuFormatNumber( | |
34 | +Maybe<bool> IcuFormatNumber( | |
35 | Isolate* isolate, | |
36 | const icu::number::LocalizedNumberFormatter& number_format, | |
37 | - Handle<Object> numeric_obj, icu::FieldPositionIterator* fp_iter) { | |
38 | + Handle<Object> numeric_obj, icu::number::FormattedNumber* formatted) { | |
39 | // If it is BigInt, handle it differently. | |
40 | UErrorCode status = U_ZERO_ERROR; | |
41 | - icu::number::FormattedNumber formatted; | |
42 | if (numeric_obj->IsBigInt()) { | |
43 | Handle<BigInt> big_int = Handle<BigInt>::cast(numeric_obj); | |
44 | Handle<String> big_int_string; | |
45 | ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, big_int_string, | |
46 | BigInt::ToString(isolate, big_int), | |
47 | - Nothing<icu::UnicodeString>()); | |
48 | - formatted = number_format.formatDecimal( | |
49 | + Nothing<bool>()); | |
50 | + *formatted = number_format.formatDecimal( | |
51 | {big_int_string->ToCString().get(), big_int_string->length()}, status); | |
52 | } else { | |
53 | double number = numeric_obj->Number(); | |
54 | - formatted = number_format.formatDouble(number, status); | |
55 | + *formatted = number_format.formatDouble(number, status); | |
56 | } | |
57 | if (U_FAILURE(status)) { | |
58 | // This happen because of icu data trimming trim out "unit". | |
59 | // See https://bugs.chromium.org/p/v8/issues/detail?id=8641 | |
60 | - THROW_NEW_ERROR_RETURN_VALUE(isolate, | |
61 | - NewTypeError(MessageTemplate::kIcuError), | |
62 | - Nothing<icu::UnicodeString>()); | |
63 | - } | |
64 | - if (fp_iter) { | |
65 | - formatted.getAllFieldPositions(*fp_iter, status); | |
66 | + THROW_NEW_ERROR_RETURN_VALUE( | |
67 | + isolate, NewTypeError(MessageTemplate::kIcuError), Nothing<bool>()); | |
68 | } | |
69 | - icu::UnicodeString result = formatted.toString(status); | |
70 | - if (U_FAILURE(status)) { | |
71 | - THROW_NEW_ERROR_RETURN_VALUE(isolate, | |
72 | - NewTypeError(MessageTemplate::kIcuError), | |
73 | - Nothing<icu::UnicodeString>()); | |
74 | - } | |
75 | - return Just(result); | |
76 | + return Just(true); | |
77 | } | |
78 | ||
79 | } // namespace | |
80 | @@ -1243,10 +1232,16 @@ MaybeHandle<String> JSNumberFormat::FormatNumeric( | |
81 | Handle<Object> numeric_obj) { | |
82 | DCHECK(numeric_obj->IsNumeric()); | |
83 | ||
84 | - Maybe<icu::UnicodeString> maybe_format = | |
85 | - IcuFormatNumber(isolate, number_format, numeric_obj, nullptr); | |
86 | + icu::number::FormattedNumber formatted; | |
87 | + Maybe<bool> maybe_format = | |
88 | + IcuFormatNumber(isolate, number_format, numeric_obj, &formatted); | |
89 | MAYBE_RETURN(maybe_format, Handle<String>()); | |
90 | - return Intl::ToString(isolate, maybe_format.FromJust()); | |
91 | + UErrorCode status = U_ZERO_ERROR; | |
92 | + icu::UnicodeString result = formatted.toString(status); | |
93 | + if (U_FAILURE(status)) { | |
94 | + THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kIcuError), String); | |
95 | + } | |
96 | + return Intl::ToString(isolate, result); | |
97 | } | |
98 | ||
99 | namespace { | |
100 | @@ -1359,12 +1354,18 @@ std::vector<NumberFormatSpan> FlattenRegionsToParts( | |
101 | } | |
102 | ||
103 | namespace { | |
104 | -Maybe<int> ConstructParts(Isolate* isolate, const icu::UnicodeString& formatted, | |
105 | - icu::FieldPositionIterator* fp_iter, | |
106 | +Maybe<int> ConstructParts(Isolate* isolate, | |
107 | + icu::number::FormattedNumber* formatted, | |
108 | Handle<JSArray> result, int start_index, | |
109 | Handle<Object> numeric_obj, bool style_is_unit) { | |
110 | + UErrorCode status = U_ZERO_ERROR; | |
111 | + icu::UnicodeString formatted_text = formatted->toString(status); | |
112 | + if (U_FAILURE(status)) { | |
113 | + THROW_NEW_ERROR_RETURN_VALUE( | |
114 | + isolate, NewTypeError(MessageTemplate::kIcuError), Nothing<int>()); | |
115 | + } | |
116 | DCHECK(numeric_obj->IsNumeric()); | |
117 | - int32_t length = formatted.length(); | |
118 | + int32_t length = formatted_text.length(); | |
119 | int index = start_index; | |
120 | if (length == 0) return Just(index); | |
121 | ||
122 | @@ -1373,13 +1374,14 @@ Maybe<int> ConstructParts(Isolate* isolate, const icu::UnicodeString& formatted, | |
123 | // other region covers some part of the formatted string. It's possible | |
124 | // there's another field with exactly the same begin and end as this backdrop, | |
125 | // in which case the backdrop's field_id of -1 will give it lower priority. | |
126 | - regions.push_back(NumberFormatSpan(-1, 0, formatted.length())); | |
127 | + regions.push_back(NumberFormatSpan(-1, 0, formatted_text.length())); | |
128 | ||
129 | { | |
130 | - icu::FieldPosition fp; | |
131 | - while (fp_iter->next(fp)) { | |
132 | - regions.push_back(NumberFormatSpan(fp.getField(), fp.getBeginIndex(), | |
133 | - fp.getEndIndex())); | |
134 | + icu::ConstrainedFieldPosition cfp; | |
135 | + cfp.constrainCategory(UFIELD_CATEGORY_NUMBER); | |
136 | + while (formatted->nextPosition(cfp, status)) { | |
137 | + regions.push_back( | |
138 | + NumberFormatSpan(cfp.getField(), cfp.getStart(), cfp.getLimit())); | |
139 | } | |
140 | } | |
141 | ||
142 | @@ -1401,7 +1403,7 @@ Maybe<int> ConstructParts(Isolate* isolate, const icu::UnicodeString& formatted, | |
143 | Handle<String> substring; | |
144 | ASSIGN_RETURN_ON_EXCEPTION_VALUE( | |
145 | isolate, substring, | |
146 | - Intl::ToString(isolate, formatted, part.begin_pos, part.end_pos), | |
147 | + Intl::ToString(isolate, formatted_text, part.begin_pos, part.end_pos), | |
148 | Nothing<int>()); | |
149 | Intl::AddElement(isolate, result, index, field_type_string, substring); | |
150 | ++index; | |
151 | @@ -1421,14 +1423,14 @@ MaybeHandle<JSArray> JSNumberFormat::FormatToParts( | |
152 | number_format->icu_number_formatter().raw(); | |
153 | CHECK_NOT_NULL(fmt); | |
154 | ||
155 | - icu::FieldPositionIterator fp_iter; | |
156 | - Maybe<icu::UnicodeString> maybe_format = | |
157 | - IcuFormatNumber(isolate, *fmt, numeric_obj, &fp_iter); | |
158 | + icu::number::FormattedNumber formatted; | |
159 | + Maybe<bool> maybe_format = | |
160 | + IcuFormatNumber(isolate, *fmt, numeric_obj, &formatted); | |
161 | MAYBE_RETURN(maybe_format, Handle<JSArray>()); | |
162 | ||
163 | Handle<JSArray> result = factory->NewJSArray(0); | |
164 | Maybe<int> maybe_format_to_parts = ConstructParts( | |
165 | - isolate, maybe_format.FromJust(), &fp_iter, result, 0, numeric_obj, | |
166 | + isolate, &formatted, result, 0, numeric_obj, | |
167 | number_format->style() == JSNumberFormat::Style::UNIT); | |
168 | MAYBE_RETURN(maybe_format_to_parts, Handle<JSArray>()); | |
169 |