Skip to content

Commit

Permalink
Bug 1662977: Allow "maximumFractionDigits" option in Intl.NumberForma…
Browse files Browse the repository at this point in the history
…t to be less than the default minimum fraction digits. r=yulia

Implements the changes from the "has consensus" PR <tc39/ecma402#471>.

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.

Depends on D95734

Differential Revision: https://phabricator.services.mozilla.com/D95735
  • Loading branch information
anba committed Nov 24, 2020
1 parent 30a7c54 commit feb86ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
27 changes: 21 additions & 6 deletions js/src/builtin/intl/NumberFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,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.e.
// Step 12.f.
// Inlined DefaultNumberOption, only the fallback case applies here.
else if (mxfd === undefined) {
mxfd = std_Math_max(mxfdDefault, mnfd);
}

// 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;
}

Expand Down
3 changes: 0 additions & 3 deletions js/src/tests/jstests.list
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,6 @@ skip script test262/language/expressions/compound-assignment/compound-assignment
skip script test262/language/expressions/compound-assignment/compound-assignment-operator-calls-putvalue-lref--v-.js
skip script test262/language/expressions/compound-assignment/compound-assignment-operator-calls-putvalue-lref--v--20.js

# https://bugzilla.mozilla.org/show_bug.cgi?id=1662977
skip script test262/intl402/NumberFormat/dft-currency-mnfd-range-check-mxfd.js

# https://bugzilla.mozilla.org/show_bug.cgi?id=1670502
skip script test262/built-ins/Function/prototype/toString/built-in-function-object.js

Expand Down

0 comments on commit feb86ac

Please sign in to comment.