Commit 4bca8f74 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by Commit Bot

Revert "Avoid UTF8 conversion in JSNumberFormat"

This reverts commit f70e5abf.

Reason for revert: Arm64 build breakage: https://ci.chromium.org/p/v8/builders/ci/V8%20Android%20Arm64%20-%20builder/30710

Original change's description:
> Avoid UTF8 conversion in JSNumberFormat
> 
> Change-Id: Idf4e95e6979adfbca24f8fd213967f821a136d87
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2057930
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Commit-Queue: Frank Tang <ftang@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#66353}

TBR=jkummerow@chromium.org,ftang@chromium.org

Change-Id: I01300a6eec5cb3f2e97da74744328d58d9e51d14
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2062742Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66354}
parent f70e5abf
......@@ -353,26 +353,28 @@ bool UseGroupingFromSkeleton(const icu::UnicodeString& skeleton) {
// Parse currency code from skeleton. For example, skeleton as
// "currency/TWD .00 rounding-mode-half-up unit-width-full-name;"
const icu::UnicodeString CurrencyFromSkeleton(
const icu::UnicodeString& skeleton) {
const char currency[] = "currency/";
int32_t index = skeleton.indexOf(currency);
if (index < 0) return "";
return skeleton.tempSubString(index + std::strlen(currency), 3);
std::string CurrencyFromSkeleton(const icu::UnicodeString& skeleton) {
std::string str;
str = skeleton.toUTF8String<std::string>(str);
std::string search("currency/");
size_t index = str.find(search);
if (index == str.npos) return "";
return str.substr(index + search.size(), 3);
}
const icu::UnicodeString NumberingSystemFromSkeleton(
const icu::UnicodeString& skeleton) {
int32_t index = skeleton.indexOf("latin");
if (index >= 0) return "latn";
const char numbering_system[] = "numbering-system/";
index = skeleton.indexOf(numbering_system);
if (index < 0) return "";
const icu::UnicodeString res =
skeleton.tempSubString(index + std::strlen(numbering_system));
index = res.indexOf(" ");
if (index < 0) return res;
return res.tempSubString(0, index);
std::string NumberingSystemFromSkeleton(const icu::UnicodeString& skeleton) {
std::string str;
str = skeleton.toUTF8String<std::string>(str);
size_t index = str.find("latin");
if (index != str.npos) return "latn";
std::string search("numbering-system/");
index = str.find(search);
if (index == str.npos) return "";
size_t space_index = str.find(" ", index + search.size());
if (space_index != str.npos) {
space_index -= index + search.size();
}
return str.substr(index + search.size(), space_index);
}
// Return CurrencySign as string based on skeleton.
......@@ -687,8 +689,7 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions(
Handle<JSObject> options = factory->NewJSObject(isolate->object_function());
Handle<String> locale = Handle<String>(number_format->locale(), isolate);
const icu::UnicodeString numberingSystem_ustr =
NumberingSystemFromSkeleton(skeleton);
std::string numberingSystem = NumberingSystemFromSkeleton(skeleton);
// 5. For each row of Table 4, except the header row, in table order, do
// Table 4: Resolved Options of NumberFormat Instances
// Internal Slot Property
......@@ -707,25 +708,22 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions(
factory->locale_string(), locale,
Just(kDontThrow))
.FromJust());
Handle<String> numberingSystem_string;
CHECK(Intl::ToString(isolate, numberingSystem_ustr)
.ToHandle(&numberingSystem_string));
CHECK(JSReceiver::CreateDataProperty(isolate, options,
factory->numberingSystem_string(),
numberingSystem_string, Just(kDontThrow))
CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->numberingSystem_string(),
factory->NewStringFromAsciiChecked(numberingSystem.c_str()),
Just(kDontThrow))
.FromJust());
Style style = StyleFromSkeleton(skeleton);
CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->style_string(),
StyleAsString(isolate, style), Just(kDontThrow))
.FromJust());
const icu::UnicodeString currency_ustr = CurrencyFromSkeleton(skeleton);
if (!currency_ustr.isEmpty()) {
Handle<String> currency_string;
CHECK(Intl::ToString(isolate, currency_ustr).ToHandle(&currency_string));
CHECK(JSReceiver::CreateDataProperty(isolate, options,
factory->currency_string(),
currency_string, Just(kDontThrow))
std::string currency = CurrencyFromSkeleton(skeleton);
if (!currency.empty()) {
CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->currency_string(),
factory->NewStringFromAsciiChecked(currency.c_str()),
Just(kDontThrow))
.FromJust());
CHECK(JSReceiver::CreateDataProperty(
......
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