Skip to content

Commit 29acfc6

Browse files
authored
[Normative] Consolidate option reading into SetNumberFormatDigitOptions so it can be leveraged in PluralRules (#130)
1 parent b755dd4 commit 29acfc6

File tree

4 files changed

+60
-26
lines changed

4 files changed

+60
-26
lines changed

numberformat/diff.emu

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,9 @@
7777
1. Let _mxfdDefault_ be 0.
7878
1. Else,
7979
1. Let _mxfdDefault_ be 3.
80-
1. <ins class="block">Let _roundingIncrement_ be ? GetNumberOption(_options_, *"roundingIncrement"*, 1, 5000, 1).</ins>
81-
1. <ins class="block">If _roundingIncrement_ is not in « 1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000 », throw a *RangeError* exception.</ins>
82-
1. <ins class="block">If _roundingIncrement_ is not 1, set _mxfdDefault_ to _mnfdDefault_.</ins>
8380
1. Let _notation_ be ? GetOption(_options_, *"notation"*, ~string~, &laquo; *"standard"*, *"scientific"*, *"engineering"*, *"compact"* &raquo;, *"standard"*).
8481
1. Set _numberFormat_.[[Notation]] to _notation_.
8582
1. Perform ? SetNumberFormatDigitOptions(_numberFormat_, _options_, _mnfdDefault_, _mxfdDefault_, _notation_).
86-
1. <ins class="block">If _roundingIncrement_ is not 1, then</ins>
87-
1. <ins class="block">If _numberFormat_.[[RoundingType]] is not ~fractionDigits~, throw a *TypeError* exception.</ins>
88-
1. <ins class="block">If _numberFormat_.[[MaximumFractionDigits]] is not equal to _numberFormat_.[[MinimumFractionDigits]], throw a *RangeError* exception.</ins>
89-
1. <ins class="block">Set _numberFormat_.[[RoundingIncrement]] to _roundingIncrement_.</ins>
90-
1. <ins class="block">Let _trailingZeroDisplay_ be ? GetOption(_options_, *"trailingZeroDisplay"*, ~string~, &laquo; *"auto"*, *"stripIfInteger"* &raquo;, *"auto"*).</ins>
91-
1. <ins class="block">Set _numberFormat_.[[TrailingZeroDisplay]] to _trailingZeroDisplay_.</ins>
9283
1. Let _compactDisplay_ be ? GetOption(_options_, *"compactDisplay"*, ~string~, &laquo; *"short"*, *"long"* &raquo;, *"short"*).
9384
1. <ins class="block">Let _defaultUseGrouping_ be *"auto"*.</ins>
9485
1. If _notation_ is *"compact"*, then
@@ -98,8 +89,6 @@
9889
1. Set _numberFormat_.[[UseGrouping]] to _useGrouping_.
9990
1. Let _signDisplay_ be ? GetOption(_options_, *"signDisplay"*, ~string~, &laquo; *"auto"*, *"never"*, *"always"*, *"exceptZero"*<ins>, *"negative"*</ins> &raquo;, *"auto"*).
10091
1. Set _numberFormat_.[[SignDisplay]] to _signDisplay_.
101-
1. <ins class="block">Let _roundingMode_ be ? GetOption(_options_, *"roundingMode"*, ~string~, &laquo; *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, *"halfEven"* &raquo;, *"halfExpand"*).</ins>
102-
1. <ins class="block">Set _numberFormat_.[[RoundingMode]] to _roundingMode_.</ins>
10392
1. Return _numberFormat_.
10493
</emu-alg>
10594
</emu-clause>
@@ -110,6 +99,7 @@
11099
<p>
111100
The abstract operation SetNumberFormatDigitOptions applies digit
112101
options used for number formatting onto the intl object.
102+
<ins>It is used by both Intl.NumberFormat and Intl.PluralRules.</ins>
113103
</p>
114104
<emu-alg>
115105
1. Let _mnid_ be ? GetNumberOption(_options_, *"minimumIntegerDigits,"*, 1, 21, 1).
@@ -119,6 +109,15 @@
119109
1. Let _mxsd_ be ? Get(_options_, *"maximumSignificantDigits"*).
120110
1. Set _intlObj_.[[MinimumIntegerDigits]] to _mnid_.
121111
1. <ins class="block">Let _roundingPriority_ be ? GetOption(_options_, *"roundingPriority"*, ~string~, &laquo; *"auto"*, *"morePrecision"*, *"lessPrecision"* &raquo;, *"auto"*).</ins>
112+
1. <ins class="block">Let _roundingIncrement_ be ? GetNumberOption(_options_, *"roundingIncrement"*, 1, 5000, 1).</ins>
113+
1. <ins class="block">If _roundingIncrement_ is not in « 1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000 », throw a *RangeError* exception.</ins>
114+
1. <ins class="block">Let _roundingMode_ be ? GetOption(_options_, *"roundingMode"*, ~string~, &laquo; *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, *"halfEven"* &raquo;, *"halfExpand"*).</ins>
115+
1. <ins class="block">Let _trailingZeroDisplay_ be ? GetOption(_options_, *"trailingZeroDisplay"*, ~string~, &laquo; *"auto"*, *"stripIfInteger"* &raquo;, *"auto"*).</ins>
116+
1. <ins class="block">NOTE: All fields required by SetNumberFormatDigitOptions have now been read from _options_. The remainder of this AO interprets the options and may throw exceptions.</ins>
117+
1. <ins class="block">If _roundingIncrement_ is not 1, set _mxfdDefault_ to _mnfdDefault_.</ins>
118+
1. <ins class="block">Set _intlObj_.[[RoundingIncrement]] to _roundingIncrement_.</ins>
119+
1. <ins class="block">Set _intlObj_.[[RoundingMode]] to _roundingMode_.</ins>
120+
1. <ins class="block">Set _intlObj_.[[TrailingZeroDisplay]] to _trailingZeroDisplay_.</ins>
122121
1. If _mnsd_ is not *undefined* or _mxsd_ is not *undefined*, then
123122
1. Let _hasSd_ be *true*.
124123
1. Else,
@@ -181,6 +180,9 @@
181180
1. <ins class="block">Set _intlObj_.[[MaximumFractionDigits]] to 0.</ins>
182181
1. <ins class="block">Set _intlObj_.[[MinimumSignificantDigits]] to 1.</ins>
183182
1. <ins class="block">Set _intlObj_.[[MaximumSignificantDigits]] to 2.</ins>
183+
1. <ins class="block">If _roundingIncrement_ is not 1, then</ins>
184+
1. <ins class="block">If _intlObj_.[[RoundingType]] is not ~fractionDigits~, throw a *TypeError* exception.</ins>
185+
1. <ins class="block">If _intlObj_.[[MaximumFractionDigits]] is not equal to _intlObj_.[[MinimumFractionDigits]], throw a *RangeError* exception.</ins>
184186
</emu-alg>
185187
</emu-clause>
186188

@@ -554,7 +556,7 @@
554556
[[SignDisplay]] is one of the String values *"auto"*, *"always"*, *"never"*, <del>or</del> *"exceptZero"*, <ins>or *"negative"*</ins>, specifying <del>whether to show the sign on negative numbers only, positive and negative numbers including zero, neither positive nor negative numbers, or positive and negative numbers but not zero</del> <ins>when to include a sign (with non-*"auto"* options respectively corresponding with inclusion always, never, only for nonzero numbers, or only for nonzero negative numbers)</ins>.
555557
In scientific notation, this slot affects the sign display of the mantissa but not the exponent.
556558
</li>
557-
<li><ins class="block">[[RoundingMode]] is one of the String values in the *Identifier* column of <emu-xref href="#table-intl-rounding-modes"></emu-xref>, specifying the rounding strategy for the number.</ins></li>
559+
<li><ins class="block">[[RoundingMode]] is one of the String values in the Identifier column of <emu-xref href="#table-intl-rounding-modes"></emu-xref>, specifying which rounding mode to use.</ins></li>
558560
<li><ins class="block">[[RoundingIncrement]] is an integer-valued Number that evenly divides 10, 100, 1000, or 10000 into tenths, fifths, quarters, or halves. It indicates the increment at which rounding should take place relative to the calculated rounding magnitude. For example, if [[MaximumFractionDigits]] is 2 and [[RoundingIncrement]] is 5, then the number is rounded to the nearest 0.05 ("nickel rounding").</ins></li>
559561
<li><ins class="block">[[TrailingZeroDisplay]] is one of the String values *"auto"* or *"stripIfInteger"*, indicating whether to strip trailing zeros if the formatted number is an integer (i.e., has no nonzero fraction digit).</ins></li>
560562
</ul>

numberformat/proposed.emu

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,9 @@
7777
1. Let _mxfdDefault_ be 0.
7878
1. Else,
7979
1. Let _mxfdDefault_ be 3.
80-
1. Let _roundingIncrement_ be ? GetNumberOption(_options_, *"roundingIncrement"*, 1, 5000, 1).
81-
1. If _roundingIncrement_ is not in « 1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000 », throw a *RangeError* exception.
82-
1. If _roundingIncrement_ is not 1, set _mxfdDefault_ to _mnfdDefault_.
8380
1. Let _notation_ be ? GetOption(_options_, *"notation"*, ~string~, &laquo; *"standard"*, *"scientific"*, *"engineering"*, *"compact"* &raquo;, *"standard"*).
8481
1. Set _numberFormat_.[[Notation]] to _notation_.
8582
1. Perform ? SetNumberFormatDigitOptions(_numberFormat_, _options_, _mnfdDefault_, _mxfdDefault_, _notation_).
86-
1. If _roundingIncrement_ is not 1, then
87-
1. If _numberFormat_.[[RoundingType]] is not ~fractionDigits~, throw a *TypeError* exception.
88-
1. If _numberFormat_.[[MaximumFractionDigits]] is not equal to _numberFormat_.[[MinimumFractionDigits]], throw a *RangeError* exception.
89-
1. Set _numberFormat_.[[RoundingIncrement]] to _roundingIncrement_.
90-
1. Let _trailingZeroDisplay_ be ? GetOption(_options_, *"trailingZeroDisplay"*, ~string~, &laquo; *"auto"*, *"stripIfInteger"* &raquo;, *"auto"*).
91-
1. Set _numberFormat_.[[TrailingZeroDisplay]] to _trailingZeroDisplay_.
9283
1. Let _compactDisplay_ be ? GetOption(_options_, *"compactDisplay"*, ~string~, &laquo; *"short"*, *"long"* &raquo;, *"short"*).
9384
1. Let _defaultUseGrouping_ be *"auto"*.
9485
1. If _notation_ is *"compact"*, then
@@ -98,8 +89,6 @@
9889
1. Set _numberFormat_.[[UseGrouping]] to _useGrouping_.
9990
1. Let _signDisplay_ be ? GetOption(_options_, *"signDisplay"*, ~string~, &laquo; *"auto"*, *"never"*, *"always"*, *"exceptZero"*, *"negative"* &raquo;, *"auto"*).
10091
1. Set _numberFormat_.[[SignDisplay]] to _signDisplay_.
101-
1. Let _roundingMode_ be ? GetOption(_options_, *"roundingMode"*, ~string~, &laquo; *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, *"halfEven"* &raquo;, *"halfExpand"*).
102-
1. Set _numberFormat_.[[RoundingMode]] to _roundingMode_.
10392
1. Return _numberFormat_.
10493
</emu-alg>
10594
</emu-clause>
@@ -110,6 +99,7 @@
11099
<p>
111100
The abstract operation SetNumberFormatDigitOptions applies digit
112101
options used for number formatting onto the intl object.
102+
It is used by both Intl.NumberFormat and Intl.PluralRules.
113103
</p>
114104
<emu-alg>
115105
1. Let _mnid_ be ? GetNumberOption(_options_, *"minimumIntegerDigits,"*, 1, 21, 1).
@@ -119,6 +109,15 @@
119109
1. Let _mxsd_ be ? Get(_options_, *"maximumSignificantDigits"*).
120110
1. Set _intlObj_.[[MinimumIntegerDigits]] to _mnid_.
121111
1. Let _roundingPriority_ be ? GetOption(_options_, *"roundingPriority"*, ~string~, &laquo; *"auto"*, *"morePrecision"*, *"lessPrecision"* &raquo;, *"auto"*).
112+
1. Let _roundingIncrement_ be ? GetNumberOption(_options_, *"roundingIncrement"*, 1, 5000, 1).
113+
1. If _roundingIncrement_ is not in « 1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000 », throw a *RangeError* exception.
114+
1. Let _roundingMode_ be ? GetOption(_options_, *"roundingMode"*, ~string~, &laquo; *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, *"halfEven"* &raquo;, *"halfExpand"*).
115+
1. Let _trailingZeroDisplay_ be ? GetOption(_options_, *"trailingZeroDisplay"*, ~string~, &laquo; *"auto"*, *"stripIfInteger"* &raquo;, *"auto"*).
116+
1. NOTE: All fields required by SetNumberFormatDigitOptions have now been read from _options_. The remainder of this AO interprets the options and may throw exceptions.
117+
1. If _roundingIncrement_ is not 1, set _mxfdDefault_ to _mnfdDefault_.
118+
1. Set _intlObj_.[[RoundingIncrement]] to _roundingIncrement_.
119+
1. Set _intlObj_.[[RoundingMode]] to _roundingMode_.
120+
1. Set _intlObj_.[[TrailingZeroDisplay]] to _trailingZeroDisplay_.
122121
1. If _mnsd_ is not *undefined* or _mxsd_ is not *undefined*, then
123122
1. Let _hasSd_ be *true*.
124123
1. Else,
@@ -169,6 +168,9 @@
169168
1. Set _intlObj_.[[MaximumFractionDigits]] to 0.
170169
1. Set _intlObj_.[[MinimumSignificantDigits]] to 1.
171170
1. Set _intlObj_.[[MaximumSignificantDigits]] to 2.
171+
1. If _roundingIncrement_ is not 1, then
172+
1. If _intlObj_.[[RoundingType]] is not ~fractionDigits~, throw a *TypeError* exception.
173+
1. If _intlObj_.[[MaximumFractionDigits]] is not equal to _intlObj_.[[MinimumFractionDigits]], throw a *RangeError* exception.
172174
</emu-alg>
173175
</emu-clause>
174176

@@ -540,7 +542,7 @@
540542
[[SignDisplay]] is one of the String values *"auto"*, *"always"*, *"never"*, *"exceptZero"*, or *"negative"*, specifying when to include a sign (with non-*"auto"* options respectively corresponding with inclusion always, never, only for nonzero numbers, or only for nonzero negative numbers).
541543
In scientific notation, this slot affects the sign display of the mantissa but not the exponent.
542544
</li>
543-
<li>[[RoundingMode]] is one of the String values in the *Identifier* column of <emu-xref href="#table-intl-rounding-modes"></emu-xref>, specifying the rounding strategy for the number.</li>
545+
<li>[[RoundingMode]] is one of the String values in the Identifier column of <emu-xref href="#table-intl-rounding-modes"></emu-xref>, specifying which rounding mode to use.</li>
544546
<li>[[RoundingIncrement]] is an integer-valued Number that evenly divides 10, 100, 1000, or 10000 into tenths, fifths, quarters, or halves. It indicates the increment at which rounding should take place relative to the calculated rounding magnitude. For example, if [[MaximumFractionDigits]] is 2 and [[RoundingIncrement]] is 5, then the number is rounded to the nearest 0.05 ("nickel rounding").</li>
545547
<li>[[TrailingZeroDisplay]] is one of the String values *"auto"* or *"stripIfInteger"*, indicating whether to strip trailing zeros if the formatted number is an integer (i.e., has no nonzero fraction digit).</li>
546548
</ul>

pluralrules/diff.emu

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<emu-alg>
1919
1. If NewTarget is *undefined*, throw a *TypeError* exception.
20-
1. Let _pluralRules_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%PluralRules.prototype%"*, &laquo; [[InitializedPluralRules]], [[Locale]], [[Type]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]] &raquo;).
20+
1. Let _pluralRules_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%PluralRules.prototype%"*, &laquo; [[InitializedPluralRules]], [[Locale]], [[Type]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]]<ins>, [[RoundingMode]], [[RoundingIncrement]], [[TrailingZeroDisplay]]</ins> &raquo;).
2121
1. Return ? InitializePluralRules(_pluralRules_, _locales_, _options_).
2222
</emu-alg>
2323
</emu-clause>
@@ -227,6 +227,18 @@
227227
<td>[[MaximumSignificantDigits]]</td>
228228
<td>*"maximumSignificantDigits"*</td>
229229
</tr>
230+
<tr>
231+
<td><ins>[[RoundingMode]]</ins></td>
232+
<td><ins>*"roundingMode"*</ins></td>
233+
</tr>
234+
<tr>
235+
<td><ins>[[RoundingIncrement]]</ins></td>
236+
<td><ins>*"roundingIncrement"*</ins></td>
237+
</tr>
238+
<tr>
239+
<td><ins>[[TrailingZeroDisplay]]</ins></td>
240+
<td><ins>*"trailingZeroDisplay"*</ins></td>
241+
</tr>
230242
</table>
231243
</emu-table>
232244
</emu-clause>
@@ -254,6 +266,9 @@
254266
<li>[[MinimumFractionDigits]] and [[MaximumFractionDigits]] are non-negative integer Number values indicating the minimum and maximum fraction digits to be used. Numbers will be rounded or padded with trailing zeroes if necessary.</li>
255267
<li>[[MinimumSignificantDigits]] and [[MaximumSignificantDigits]] are positive integer Number values indicating the minimum and maximum fraction digits to be used. Either none or both of these properties are present; if they are, they override minimum and maximum integer and fraction digits.</li>
256268
<li>[[RoundingType]] is one of the values ~fractionDigits~, <del>or</del> ~significantDigits~, <ins>~morePrecision~, or ~lessPrecision~</ins>, indicating which rounding strategy to use, as discussed in <emu-xref href="#sec-properties-of-intl-numberformat-instances"></emu-xref>.</li>
269+
<li><ins class="block">[[RoundingMode]] is one of the String values in the Identifier column of <emu-xref href="#table-intl-rounding-modes"></emu-xref>, specifying which rounding mode to use.</ins></li>
270+
<li><ins class="block">[[RoundingIncrement]] is an integer-valued Number that evenly divides 10, 100, 1000, or 10000 into tenths, fifths, quarters, or halves. It indicates the increment at which rounding should take place relative to the calculated rounding magnitude. For example, if [[MaximumFractionDigits]] is 2 and [[RoundingIncrement]] is 5, then the number is rounded to the nearest 0.05 ("nickel rounding").</ins></li>
271+
<li><ins class="block">[[TrailingZeroDisplay]] is one of the String values *"auto"* or *"stripIfInteger"*, indicating whether to strip trailing zeros if the formatted number is an integer (i.e., has no nonzero fraction digit).</ins></li>
257272
</ul>
258273
</emu-clause>
259274

pluralrules/proposed.emu

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<emu-alg>
1919
1. If NewTarget is *undefined*, throw a *TypeError* exception.
20-
1. Let _pluralRules_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%PluralRules.prototype%"*, &laquo; [[InitializedPluralRules]], [[Locale]], [[Type]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]] &raquo;).
20+
1. Let _pluralRules_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%PluralRules.prototype%"*, &laquo; [[InitializedPluralRules]], [[Locale]], [[Type]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]], [[RoundingMode]], [[RoundingIncrement]], [[TrailingZeroDisplay]] &raquo;).
2121
1. Return ? InitializePluralRules(_pluralRules_, _locales_, _options_).
2222
</emu-alg>
2323
</emu-clause>
@@ -225,6 +225,18 @@
225225
<td>[[MaximumSignificantDigits]]</td>
226226
<td>*"maximumSignificantDigits"*</td>
227227
</tr>
228+
<tr>
229+
<td>[[RoundingMode]]</td>
230+
<td>*"roundingMode"*</td>
231+
</tr>
232+
<tr>
233+
<td>[[RoundingIncrement]]</td>
234+
<td>*"roundingIncrement"*</td>
235+
</tr>
236+
<tr>
237+
<td>[[TrailingZeroDisplay]]</td>
238+
<td>*"trailingZeroDisplay"*</td>
239+
</tr>
228240
</table>
229241
</emu-table>
230242
</emu-clause>
@@ -252,6 +264,9 @@
252264
<li>[[MinimumFractionDigits]] and [[MaximumFractionDigits]] are non-negative integer Number values indicating the minimum and maximum fraction digits to be used. Numbers will be rounded or padded with trailing zeroes if necessary.</li>
253265
<li>[[MinimumSignificantDigits]] and [[MaximumSignificantDigits]] are positive integer Number values indicating the minimum and maximum fraction digits to be used. Either none or both of these properties are present; if they are, they override minimum and maximum integer and fraction digits.</li>
254266
<li>[[RoundingType]] is one of the values ~fractionDigits~, ~significantDigits~, ~morePrecision~, or ~lessPrecision~, indicating which rounding strategy to use, as discussed in <emu-xref href="#sec-properties-of-intl-numberformat-instances"></emu-xref>.</li>
267+
<li>[[RoundingMode]] is one of the String values in the Identifier column of <emu-xref href="#table-intl-rounding-modes"></emu-xref>, specifying which rounding mode to use.</li>
268+
<li>[[RoundingIncrement]] is an integer-valued Number that evenly divides 10, 100, 1000, or 10000 into tenths, fifths, quarters, or halves. It indicates the increment at which rounding should take place relative to the calculated rounding magnitude. For example, if [[MaximumFractionDigits]] is 2 and [[RoundingIncrement]] is 5, then the number is rounded to the nearest 0.05 ("nickel rounding").</li>
269+
<li>[[TrailingZeroDisplay]] is one of the String values *"auto"* or *"stripIfInteger"*, indicating whether to strip trailing zeros if the formatted number is an integer (i.e., has no nonzero fraction digit).</li>
255270
</ul>
256271
</emu-clause>
257272

0 commit comments

Comments
 (0)