Commit 5b2822c9 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

Move the numberingSystem storage.

Use adoptSymbols(NumberingSystem *) API in Intl.NumberFormat to reduce string size

Bug: v8:10207
Change-Id: I3163c524612b61cfdad51743d58ece08b437520a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2055567Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66273}
parent 5306c2e4
......@@ -2062,7 +2062,6 @@ void JSLocale::JSLocalePrint(std::ostream& os) { // NOLINT
void JSNumberFormat::JSNumberFormatPrint(std::ostream& os) { // NOLINT
JSObjectPrintHeader(os, *this, "JSNumberFormat");
os << "\n - locale: " << Brief(locale());
os << "\n - numberingSystem: " << Brief(numberingSystem());
os << "\n - icu_number_formatter: " << Brief(icu_number_formatter());
os << "\n - bound_format: " << Brief(bound_format());
JSObjectPrintBody(os, *this);
......
......@@ -37,7 +37,6 @@ extern class JSListFormat extends JSObject {
extern class JSNumberFormat extends JSObject {
locale: String;
numberingSystem: String;
icu_number_formatter:
Foreign; // Managed<icu::number::LocalizedNumberFormatter>
bound_format: JSFunction|Undefined;
......
......@@ -21,7 +21,6 @@ namespace internal {
OBJECT_CONSTRUCTORS_IMPL(JSNumberFormat, JSObject)
ACCESSORS(JSNumberFormat, locale, String, kLocaleOffset)
ACCESSORS(JSNumberFormat, numberingSystem, String, kNumberingSystemOffset)
ACCESSORS(JSNumberFormat, icu_number_formatter,
Managed<icu::number::LocalizedNumberFormatter>,
kIcuNumberFormatterOffset)
......
......@@ -21,6 +21,7 @@
#include "unicode/nounit.h"
#include "unicode/numberformatter.h"
#include "unicode/numfmt.h"
#include "unicode/numsys.h"
#include "unicode/ucurr.h"
#include "unicode/uloc.h"
#include "unicode/unumberformatter.h"
......@@ -357,6 +358,21 @@ std::string CurrencyFromSkeleton(const icu::UnicodeString& skeleton) {
return str.substr(index + search.size(), 3);
}
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.
Handle<String> CurrencySignString(Isolate* isolate,
const icu::UnicodeString& skeleton) {
......@@ -656,8 +672,7 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions(
Handle<JSObject> options = factory->NewJSObject(isolate->object_function());
Handle<String> locale = Handle<String>(number_format->locale(), isolate);
Handle<String> numberingSystem =
Handle<String>(number_format->numberingSystem(), isolate);
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
......@@ -676,9 +691,10 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions(
factory->locale_string(), locale,
Just(kDontThrow))
.FromJust());
CHECK(JSReceiver::CreateDataProperty(isolate, options,
factory->numberingSystem_string(),
numberingSystem, Just(kDontThrow))
CHECK(JSReceiver::CreateDataProperty(
isolate, options, factory->numberingSystem_string(),
factory->NewStringFromAsciiChecked(numberingSystem.c_str()),
Just(kDontThrow))
.FromJust());
JSNumberFormat::Style style = number_format->style();
CHECK(JSReceiver::CreateDataProperty(
......@@ -884,9 +900,7 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::New(Isolate* isolate,
CHECK(U_SUCCESS(status));
}
Handle<String> numberingSystem_str =
isolate->factory()->NewStringFromAsciiChecked(
Intl::GetNumberingSystem(icu_locale).c_str());
std::string numbering_system = Intl::GetNumberingSystem(icu_locale);
// 11. Let dataLocale be r.[[dataLocale]].
......@@ -894,6 +908,13 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::New(Isolate* isolate,
icu::number::NumberFormatter::withLocale(icu_locale)
.roundingMode(UNUM_ROUND_HALFUP);
if (!numbering_system.empty()) {
icu_number_formatter = icu_number_formatter.adoptSymbols(
icu::NumberingSystem::createInstanceByName(numbering_system.c_str(),
status));
CHECK(U_SUCCESS(status));
}
// 3. Let style be ? GetOption(options, "style", "string", « "decimal",
// "percent", "currency", "unit" », "decimal").
......@@ -1183,7 +1204,6 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::New(Isolate* isolate,
number_format->set_flags(0);
number_format->set_style(style);
number_format->set_locale(*locale_str);
number_format->set_numberingSystem(*numberingSystem_str);
number_format->set_icu_number_formatter(*managed_number_formatter);
number_format->set_bound_format(*factory->undefined_value());
......
......@@ -98,7 +98,6 @@ class JSNumberFormat : public JSObject {
STATIC_ASSERT(Style::UNIT <= StyleBits::kMax);
DECL_ACCESSORS(locale, String)
DECL_ACCESSORS(numberingSystem, String)
DECL_ACCESSORS(icu_number_formatter,
Managed<icu::number::LocalizedNumberFormatter>)
DECL_ACCESSORS(bound_format, Object)
......
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