summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2023-10-19 15:46:27 +0200
committerMoonchild <moonchild@palemoon.org>2023-10-19 15:46:27 +0200
commit3e71cd6b93edaf7362e2635a38675bb843cd402a (patch)
tree7ec250ca2a32f7dc03dd64100aef9810b1f3ae8d
parent6c6c16b7f012b301af8ebc1aa0808017d631b56d (diff)
downloaduxp-3e71cd6b93edaf7362e2635a38675bb843cd402a.tar.gz
Issue #2350 - Part 2: Allow "maximumFractionDigits" option in
Intl.NumberFormat to be less than the default minimum fraction digits. This implements the changes from the "has consensus" PR in TC39 The second pair of `DefaultNumberOption()` calls was inlined, because only the fallback case is relevant anyway. Steps 12.d and 12.e from the spec PR were combined into a single `if`-block. That way it also matches step 12.f more closely. Also changed the single `if` steps into an `if-else if` chain, because the steps are mutually exclusive.
-rw-r--r--js/src/builtin/intl/NumberFormat.js27
1 files changed, 21 insertions, 6 deletions
diff --git a/js/src/builtin/intl/NumberFormat.js b/js/src/builtin/intl/NumberFormat.js
index 60d423efd9..85fac41e01 100644
--- a/js/src/builtin/intl/NumberFormat.js
+++ b/js/src/builtin/intl/NumberFormat.js
@@ -170,18 +170,33 @@ function SetNumberFormatDigitOptions(lazyData, options, mnfdDefault, mxfdDefault
// Step 12.a (Omitted).
// Step 12.b.
- mnfd = DefaultNumberOption(mnfd, 0, 20, mnfdDefault);
+ mnfd = DefaultNumberOption(mnfd, 0, 20, undefined);
// Step 12.c.
- const mxfdActualDefault = std_Math_max(mnfd, mxfdDefault);
+ mxfd = DefaultNumberOption(mxfd, 0, 20, undefined);
- // Step 12.d.
- mxfd = DefaultNumberOption(mxfd, mnfd, 20, mxfdActualDefault);
+ // Steps 12.d-e.
+ // Inlined DefaultNumberOption, only the fallback case applies here.
+ if (mnfd === undefined) {
+ assert(mxfd !== undefined, "mxfd isn't undefined when mnfd is undefined");
+ mnfd = std_Math_min(mnfdDefault, mxfd);
+ }
+
+ // Step 12.f.
+ // Inlined DefaultNumberOption, only the fallback case applies here.
+ else if (mxfd === undefined) {
+ mxfd = std_Math_max(mxfdDefault, mnfd);
+ }
- // Step 12.e.
+ // Step 12.g.
+ else if (mnfd > mxfd) {
+ ThrowRangeError(JSMSG_INVALID_DIGITS_VALUE, mxfd);
+ }
+
+ // Step 12.h.
lazyData.minimumFractionDigits = mnfd;
- // Step 12.f.
+ // Step 12.i.
lazyData.maximumFractionDigits = mxfd;
}