Skip to content

Commit

Permalink
[JSC] Increase minimumFractionDigits / maximumFractionDigits limit fr…
Browse files Browse the repository at this point in the history
…om 20 to 100

https://bugs.webkit.org/show_bug.cgi?id=260169
rdar://113869343

Reviewed by Mark Lam.

This patch aligns the implementation to the latest spec change[1].
Just increasing minimumFractionDigits and maximumFractionDigits limit from 20 to 100.

[1]: tc39/ecma402@f6d2945

* JSTests/test262/expectations.yaml:
* Source/JavaScriptCore/runtime/IntlNumberFormatInlines.h:
(JSC::setNumberFormatDigitOptions):

Canonical link: https://commits.webkit.org/266879@main
  • Loading branch information
Constellation committed Aug 14, 2023
1 parent 2b25eed commit d4b49d3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
4 changes: 2 additions & 2 deletions JSTests/stress/intl-numberformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ shouldBe(testNumberFormat(Intl.NumberFormat('en', {minimumFractionDigits: 0}), [
shouldBe(testNumberFormat(Intl.NumberFormat('en', {style: 'percent', minimumFractionDigits: 0}), [{locale: 'en', style: 'percent', minimumFractionDigits: 0, maximumFractionDigits: 0}]), true);
shouldBe(testNumberFormat(Intl.NumberFormat('en', {minimumFractionDigits: 6}), [{locale: 'en', minimumFractionDigits: 6, maximumFractionDigits: 6}]), true);
shouldThrow(() => Intl.NumberFormat('en', {minimumFractionDigits: -1}), RangeError);
shouldThrow(() => Intl.NumberFormat('en', {minimumFractionDigits: 21}), RangeError);
shouldThrow(() => Intl.NumberFormat('en', {minimumFractionDigits: 101}), RangeError);

// The option maximumFractionDigits is processed correctly.
shouldBe(testNumberFormat(Intl.NumberFormat('en', {maximumFractionDigits: 6}), [{locale: 'en', maximumFractionDigits: 6}]), true);
shouldThrow(() => Intl.NumberFormat('en', {minimumFractionDigits: 7, maximumFractionDigits: 6}), RangeError);
shouldThrow(() => Intl.NumberFormat('en', {maximumFractionDigits: -1}), RangeError);
shouldThrow(() => Intl.NumberFormat('en', {maximumFractionDigits: 21}), RangeError);
shouldThrow(() => Intl.NumberFormat('en', {maximumFractionDigits: 101}), RangeError);

// The option minimumSignificantDigits is processed correctly.
shouldBe(testNumberFormat(Intl.NumberFormat('en', {minimumSignificantDigits: 6}), [{locale: 'en', minimumFractionDigits: undefined, maximumFractionDigits: undefined, minimumSignificantDigits: 6, maximumSignificantDigits: 21}]), true);
Expand Down
4 changes: 2 additions & 2 deletions JSTests/stress/intl-pluralrules.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ shouldBe(new Intl.PluralRules('en', {minimumFractionDigits: 0}).resolvedOptions(
shouldBe(new Intl.PluralRules('en', {minimumFractionDigits: 6}).resolvedOptions().minimumFractionDigits, 6);
shouldBe(new Intl.PluralRules('en', {minimumFractionDigits: 6}).resolvedOptions().maximumFractionDigits, 6);
shouldThrow(() => new Intl.PluralRules('en', {minimumFractionDigits: -1}), RangeError);
shouldThrow(() => new Intl.PluralRules('en', {minimumFractionDigits: 21}), RangeError);
shouldThrow(() => new Intl.PluralRules('en', {minimumFractionDigits: 101}), RangeError);

// The option maximumFractionDigits is processed correctly.
shouldBe(new Intl.PluralRules('en', {maximumFractionDigits: 6}).resolvedOptions().maximumFractionDigits, 6);
shouldThrow(() => new Intl.PluralRules('en', {minimumFractionDigits: 7, maximumFractionDigits: 6}), RangeError);
shouldThrow(() => new Intl.PluralRules('en', {maximumFractionDigits: -1}), RangeError);
shouldThrow(() => new Intl.PluralRules('en', {maximumFractionDigits: 21}), RangeError);
shouldThrow(() => new Intl.PluralRules('en', {maximumFractionDigits: 101}), RangeError);

// The option minimumSignificantDigits is processed correctly.
shouldBe(new Intl.PluralRules('en', {minimumSignificantDigits: 6}).resolvedOptions().minimumSignificantDigits, 6);
Expand Down
6 changes: 0 additions & 6 deletions JSTests/test262/expectations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1744,12 +1744,6 @@ test/intl402/NumberFormat/prototype/format/useGrouping-extended-en-IN.js:
test/intl402/NumberFormat/prototype/format/value-decimal-string.js:
default: 'Test262Error: Expected SameValue(«1», «1.0000000000000001») to be true'
strict mode: 'Test262Error: Expected SameValue(«1», «1.0000000000000001») to be true'
test/intl402/NumberFormat/throws-for-maximumFractionDigits-over-limit.js:
default: 'RangeError: maximumFractionDigits is out of range'
strict mode: 'RangeError: maximumFractionDigits is out of range'
test/intl402/NumberFormat/throws-for-minimumFractionDigits-over-limit.js:
default: 'RangeError: minimumFractionDigits is out of range'
strict mode: 'RangeError: minimumFractionDigits is out of range'
test/intl402/Temporal/Duration/compare/relativeto-sub-minute-offset.js:
default: 'RangeError: Cannot compare a duration of years, months, or weeks without a relativeTo option'
strict mode: 'RangeError: Cannot compare a duration of years, months, or weeks without a relativeTo option'
Expand Down
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/runtime/IntlNumberFormatInlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ void setNumberFormatDigitOptions(JSGlobalObject* globalObject, IntlType* intlIns
if (needFd) {
if (hasFd) {
constexpr unsigned undefinedValue = UINT32_MAX;
unsigned minimumFractionDigits = intlDefaultNumberOption(globalObject, minimumFractionDigitsValue, vm.propertyNames->minimumFractionDigits, 0, 20, undefinedValue);
unsigned minimumFractionDigits = intlDefaultNumberOption(globalObject, minimumFractionDigitsValue, vm.propertyNames->minimumFractionDigits, 0, 100, undefinedValue);
RETURN_IF_EXCEPTION(scope, void());
unsigned maximumFractionDigits = intlDefaultNumberOption(globalObject, maximumFractionDigitsValue, vm.propertyNames->maximumFractionDigits, 0, 20, undefinedValue);
unsigned maximumFractionDigits = intlDefaultNumberOption(globalObject, maximumFractionDigitsValue, vm.propertyNames->maximumFractionDigits, 0, 100, undefinedValue);
RETURN_IF_EXCEPTION(scope, void());

if (minimumFractionDigits == undefinedValue)
Expand Down

0 comments on commit d4b49d3

Please sign in to comment.