Commit 9a52cc11 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

Refactor to remove dup code.

Bug: v8:9300
Change-Id: I8eee82f41e19858f1688c64e6bc6800e26db6050
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1638257
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61968}
parent a642ba6f
...@@ -635,6 +635,28 @@ std::string UnitFromSkeleton(const icu::UnicodeString& skeleton) { ...@@ -635,6 +635,28 @@ std::string UnitFromSkeleton(const icu::UnicodeString& skeleton) {
} // anonymous namespace } // anonymous namespace
icu::number::LocalizedNumberFormatter
JSNumberFormat::SetDigitOptionsToFormatter(
const icu::number::LocalizedNumberFormatter& icu_number_formatter,
const Intl::NumberFormatDigitOptions& digit_options) {
icu::number::Precision precision =
(digit_options.minimum_significant_digits > 0)
? icu::number::Precision::minMaxSignificantDigits(
digit_options.minimum_significant_digits,
digit_options.maximum_significant_digits)
: icu::number::Precision::minMaxFraction(
digit_options.minimum_fraction_digits,
digit_options.maximum_fraction_digits);
icu::number::LocalizedNumberFormatter result =
icu_number_formatter.precision(precision);
if (digit_options.minimum_integer_digits > 1) {
result = result.integerWidth(icu::number::IntegerWidth::zeroFillTo(
digit_options.minimum_integer_digits));
}
return result;
}
// static // static
// ecma402 #sec-intl.numberformat.prototype.resolvedoptions // ecma402 #sec-intl.numberformat.prototype.resolvedoptions
Handle<JSObject> JSNumberFormat::ResolvedOptions( Handle<JSObject> JSNumberFormat::ResolvedOptions(
...@@ -1129,15 +1151,8 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize( ...@@ -1129,15 +1151,8 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize(
mxfd_default); mxfd_default);
MAYBE_RETURN(maybe_digit_options, Handle<JSNumberFormat>()); MAYBE_RETURN(maybe_digit_options, Handle<JSNumberFormat>());
Intl::NumberFormatDigitOptions digit_options = maybe_digit_options.FromJust(); Intl::NumberFormatDigitOptions digit_options = maybe_digit_options.FromJust();
icu_number_formatter = JSNumberFormat::SetDigitOptionsToFormatter(
icu::number::Precision precision = icu_number_formatter, digit_options);
(digit_options.minimum_significant_digits > 0)
? icu::number::Precision::minMaxSignificantDigits(
digit_options.minimum_significant_digits,
digit_options.maximum_significant_digits)
: icu::number::Precision::minMaxFraction(
digit_options.minimum_fraction_digits,
digit_options.maximum_fraction_digits);
if (digit_options.minimum_significant_digits > 0) { if (digit_options.minimum_significant_digits > 0) {
// Currenct ECMA 402 spec mandate to record (Min|Max)imumFractionDigits // Currenct ECMA 402 spec mandate to record (Min|Max)imumFractionDigits
...@@ -1157,13 +1172,6 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize( ...@@ -1157,13 +1172,6 @@ MaybeHandle<JSNumberFormat> JSNumberFormat::Initialize(
digit_options.maximum_fraction_digits); digit_options.maximum_fraction_digits);
} }
icu_number_formatter = icu_number_formatter.precision(precision);
if (digit_options.minimum_integer_digits > 1) {
icu_number_formatter =
icu_number_formatter.integerWidth(icu::number::IntegerWidth::zeroFillTo(
digit_options.minimum_integer_digits));
}
if (FLAG_harmony_intl_numberformat_unified) { if (FLAG_harmony_intl_numberformat_unified) {
// Let notation be ? GetOption(options, "notation", "string", « "standard", // Let notation be ? GetOption(options, "notation", "string", « "standard",
// "scientific", "engineering", "compact" », "standard"). // "scientific", "engineering", "compact" », "standard").
......
...@@ -57,12 +57,16 @@ class JSNumberFormat : public JSObject { ...@@ -57,12 +57,16 @@ class JSNumberFormat : public JSObject {
V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales(); V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales();
// Helper functions shared with JSPluralRules.
static int32_t MinimumIntegerDigitsFromSkeleton( static int32_t MinimumIntegerDigitsFromSkeleton(
const icu::UnicodeString& skeleton); const icu::UnicodeString& skeleton);
static bool FractionDigitsFromSkeleton(const icu::UnicodeString& skeleton, static bool FractionDigitsFromSkeleton(const icu::UnicodeString& skeleton,
int32_t* minimum, int32_t* maximum); int32_t* minimum, int32_t* maximum);
static bool SignificantDigitsFromSkeleton(const icu::UnicodeString& skeleton, static bool SignificantDigitsFromSkeleton(const icu::UnicodeString& skeleton,
int32_t* minimum, int32_t* maximum); int32_t* minimum, int32_t* maximum);
static icu::number::LocalizedNumberFormatter SetDigitOptionsToFormatter(
const icu::number::LocalizedNumberFormatter& icu_number_formatter,
const Intl::NumberFormatDigitOptions& digit_options);
DECL_CAST(JSNumberFormat) DECL_CAST(JSNumberFormat)
DECL_PRINTER(JSNumberFormat) DECL_PRINTER(JSNumberFormat)
......
...@@ -153,21 +153,8 @@ MaybeHandle<JSPluralRules> JSPluralRules::Initialize( ...@@ -153,21 +153,8 @@ MaybeHandle<JSPluralRules> JSPluralRules::Initialize(
Intl::SetNumberFormatDigitOptions(isolate, options, 0, 3); Intl::SetNumberFormatDigitOptions(isolate, options, 0, 3);
MAYBE_RETURN(maybe_digit_options, MaybeHandle<JSPluralRules>()); MAYBE_RETURN(maybe_digit_options, MaybeHandle<JSPluralRules>());
Intl::NumberFormatDigitOptions digit_options = maybe_digit_options.FromJust(); Intl::NumberFormatDigitOptions digit_options = maybe_digit_options.FromJust();
icu::number::Precision precision = icu_number_formatter = JSNumberFormat::SetDigitOptionsToFormatter(
(digit_options.minimum_significant_digits > 0) icu_number_formatter, digit_options);
? icu::number::Precision::minMaxSignificantDigits(
digit_options.minimum_significant_digits,
digit_options.maximum_significant_digits)
: icu::number::Precision::minMaxFraction(
digit_options.minimum_fraction_digits,
digit_options.maximum_fraction_digits);
icu_number_formatter = icu_number_formatter.precision(precision);
if (digit_options.minimum_integer_digits > 1) {
icu_number_formatter =
icu_number_formatter.integerWidth(icu::number::IntegerWidth::zeroFillTo(
digit_options.minimum_integer_digits));
}
Handle<Managed<icu::PluralRules>> managed_plural_rules = Handle<Managed<icu::PluralRules>> managed_plural_rules =
Managed<icu::PluralRules>::FromUniquePtr(isolate, 0, Managed<icu::PluralRules>::FromUniquePtr(isolate, 0,
......
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