From b411e300246b700cbf311c90a30dca3b75055d29 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 11 Apr 2023 08:02:33 -0400 Subject: [PATCH] LibJS: Require a [[RoundingMode]] slot within FormatNumericToString This was optional to work around a spec issue. That issue was fixed and brought into LibJS in commit 5b3b14b, but this FIXME was neglected. --- .../Libraries/LibJS/Runtime/Intl/NumberFormat.cpp | 12 ++++-------- Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.h | 6 +++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp index f1958db630..de3215b1c0 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp @@ -406,10 +406,7 @@ ThrowCompletionOr format_numeric_to_string(VM& vm, NumberFormatBas } // 3. Let unsignedRoundingMode be GetUnsignedRoundingMode(intlObject.[[RoundingMode]], isNegative). - // FIXME: Spec issue: Intl.PluralRules does not have [[RoundingMode]], see https://github.com/tc39/proposal-intl-numberformat-v3/issues/103 - Optional unsigned_rounding_mode; - if (intl_object.rounding_mode() != NumberFormat::RoundingMode::Invalid) - unsigned_rounding_mode = get_unsigned_rounding_mode(intl_object.rounding_mode(), is_negative); + auto unsigned_rounding_mode = get_unsigned_rounding_mode(intl_object.rounding_mode(), is_negative); RawFormatResult result {}; @@ -1040,7 +1037,7 @@ static ThrowCompletionOr to_raw_precision_function(VM& vm, M // 15.5.8 ToRawPrecision ( x, minPrecision, maxPrecision ), https://tc39.es/ecma402/#sec-torawprecision // 1.5.8 ToRawPrecision ( x, minPrecision, maxPrecision, unsignedRoundingMode ), https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-torawprecision -ThrowCompletionOr to_raw_precision(VM& vm, MathematicalValue const& number, int min_precision, int max_precision, Optional const& unsigned_rounding_mode) +ThrowCompletionOr to_raw_precision(VM& vm, MathematicalValue const& number, int min_precision, int max_precision, NumberFormat::UnsignedRoundingMode unsigned_rounding_mode) { RawFormatResult result {}; @@ -1204,7 +1201,7 @@ static ThrowCompletionOr to_raw_fixed_function(VM& vm, Mathemati // 15.5.9 ToRawFixed ( x, minInteger, minFraction, maxFraction ), https://tc39.es/ecma402/#sec-torawfixed // 1.5.9 ToRawFixed ( x, minFraction, maxFraction, roundingIncrement, unsignedRoundingMode ), https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-torawfixed -ThrowCompletionOr to_raw_fixed(VM& vm, MathematicalValue const& number, int min_fraction, int max_fraction, int rounding_increment, Optional const& unsigned_rounding_mode) +ThrowCompletionOr to_raw_fixed(VM& vm, MathematicalValue const& number, int min_fraction, int max_fraction, int rounding_increment, NumberFormat::UnsignedRoundingMode unsigned_rounding_mode) { RawFormatResult result {}; @@ -1735,7 +1732,7 @@ NumberFormat::UnsignedRoundingMode get_unsigned_rounding_mode(NumberFormat::Roun } // 1.5.18 ApplyUnsignedRoundingMode ( x, r1, r2, unsignedRoundingMode ), https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-applyunsignedroundingmode -RoundingDecision apply_unsigned_rounding_mode(MathematicalValue const& x, MathematicalValue const& r1, MathematicalValue const& r2, Optional const& unsigned_rounding_mode) +RoundingDecision apply_unsigned_rounding_mode(MathematicalValue const& x, MathematicalValue const& r1, MathematicalValue const& r2, NumberFormat::UnsignedRoundingMode unsigned_rounding_mode) { // 1. If x is equal to r1, return r1. if (x.is_equal_to(r1)) @@ -1750,7 +1747,6 @@ RoundingDecision apply_unsigned_rounding_mode(MathematicalValue const& x, Mathem // 2. Assert: r1 < x < r2. // 3. Assert: unsignedRoundingMode is not undefined. - VERIFY(unsigned_rounding_mode.has_value()); // 4. If unsignedRoundingMode is zero, return r1. if (unsigned_rounding_mode == NumberFormat::UnsignedRoundingMode::Zero) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.h b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.h index d112151558..728d1e7d25 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.h @@ -281,15 +281,15 @@ ThrowCompletionOr> partition_number_pattern(VM&, Number ThrowCompletionOr> partition_notation_sub_pattern(VM&, NumberFormat&, MathematicalValue const& number, String formatted_string, int exponent); ThrowCompletionOr format_numeric(VM&, NumberFormat&, MathematicalValue number); ThrowCompletionOr format_numeric_to_parts(VM&, NumberFormat&, MathematicalValue number); -ThrowCompletionOr to_raw_precision(VM&, MathematicalValue const& number, int min_precision, int max_precision, Optional const& unsigned_rounding_mode); -ThrowCompletionOr to_raw_fixed(VM&, MathematicalValue const& number, int min_fraction, int max_fraction, int rounding_increment, Optional const& unsigned_rounding_mode); +ThrowCompletionOr to_raw_precision(VM&, MathematicalValue const& number, int min_precision, int max_precision, NumberFormat::UnsignedRoundingMode unsigned_rounding_mode); +ThrowCompletionOr to_raw_fixed(VM&, MathematicalValue const& number, int min_fraction, int max_fraction, int rounding_increment, NumberFormat::UnsignedRoundingMode unsigned_rounding_mode); ThrowCompletionOr>> get_number_format_pattern(VM&, NumberFormat&, MathematicalValue const& number, ::Locale::NumberFormat& found_pattern); ThrowCompletionOr> get_notation_sub_pattern(VM&, NumberFormat&, int exponent); ThrowCompletionOr compute_exponent(VM&, NumberFormat&, MathematicalValue number); ThrowCompletionOr compute_exponent_for_magnitude(VM&, NumberFormat&, int magnitude); ThrowCompletionOr to_intl_mathematical_value(VM&, Value value); NumberFormat::UnsignedRoundingMode get_unsigned_rounding_mode(NumberFormat::RoundingMode, bool is_negative); -RoundingDecision apply_unsigned_rounding_mode(MathematicalValue const& x, MathematicalValue const& r1, MathematicalValue const& r2, Optional const& unsigned_rounding_mode); +RoundingDecision apply_unsigned_rounding_mode(MathematicalValue const& x, MathematicalValue const& r1, MathematicalValue const& r2, NumberFormat::UnsignedRoundingMode unsigned_rounding_mode); ThrowCompletionOr> partition_number_range_pattern(VM&, NumberFormat&, MathematicalValue start, MathematicalValue end); ThrowCompletionOr> format_approximately(VM&, NumberFormat&, Vector result); Vector collapse_number_range(Vector result);