Skip to content

Commit ce6c33e

Browse files
committed
[402-rebase] Move InitializeNumberFormat
1 parent 82e2f92 commit ce6c33e

File tree

3 files changed

+185
-185
lines changed

3 files changed

+185
-185
lines changed

numberformat/base.emu

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,59 @@
3535
</emu-alg>
3636
</emu-clause>
3737
<emu-note>See <emu-xref href="#legacy-constructor"></emu-xref> for the motivation of the normative optional text.</emu-note>
38+
39+
<emu-clause id="sec-initializenumberformat" aoid="InitializeNumberFormat">
40+
<h1>InitializeNumberFormat ( _numberFormat_, _locales_, _options_ )</h1>
41+
42+
<p>
43+
The abstract operation InitializeNumberFormat accepts the arguments _numberFormat_ (which must be an object), _locales_, and _options_. It initializes _numberFormat_ as a NumberFormat object. The following steps are taken:
44+
</p>
45+
46+
<p>
47+
The following algorithm refers to the `type` nonterminal from <a href="https://www.unicode.org/reports/tr35/#Unicode_locale_identifier">UTS 35's Unicode Locale Identifier grammar</a>.
48+
</p>
49+
50+
<emu-alg>
51+
1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_).
52+
1. Set _options_ to ? CoerceOptionsToObject(_options_).
53+
1. Let _opt_ be a new Record.
54+
1. Let _matcher_ be ? GetOption(_options_, *"localeMatcher"*, *"string"*, &laquo; *"lookup"*, *"best fit"* &raquo;, *"best fit"*).
55+
1. Set _opt_.[[localeMatcher]] to _matcher_.
56+
1. Let _numberingSystem_ be ? GetOption(_options_, *"numberingSystem"*, *"string"*, *undefined*, *undefined*).
57+
1. If _numberingSystem_ is not *undefined*, then
58+
1. If _numberingSystem_ does not match the Unicode Locale Identifier `type` nonterminal, throw a *RangeError* exception.
59+
1. Set _opt_.[[nu]] to _numberingSystem_.
60+
1. Let _localeData_ be %NumberFormat%.[[LocaleData]].
61+
1. Let _r_ be ResolveLocale(%NumberFormat%.[[AvailableLocales]], _requestedLocales_, _opt_, %NumberFormat%.[[RelevantExtensionKeys]], _localeData_).
62+
1. Set _numberFormat_.[[Locale]] to _r_.[[locale]].
63+
1. Set _numberFormat_.[[DataLocale]] to _r_.[[dataLocale]].
64+
1. Set _numberFormat_.[[NumberingSystem]] to _r_.[[nu]].
65+
1. Perform ? SetNumberFormatUnitOptions(_numberFormat_, _options_).
66+
1. Let _style_ be _numberFormat_.[[Style]].
67+
1. If _style_ is *"currency"*, then
68+
1. Let _currency_ be _numberFormat_.[[Currency]].
69+
1. Let _cDigits_ be CurrencyDigits(_currency_).
70+
1. Let _mnfdDefault_ be _cDigits_.
71+
1. Let _mxfdDefault_ be _cDigits_.
72+
1. Else,
73+
1. Let _mnfdDefault_ be 0.
74+
1. If _style_ is *"percent"*, then
75+
1. Let _mxfdDefault_ be 0.
76+
1. Else,
77+
1. Let _mxfdDefault_ be 3.
78+
1. Let _notation_ be ? GetOption(_options_, *"notation"*, *"string"*, &laquo; *"standard"*, *"scientific"*, *"engineering"*, *"compact"* &raquo;, *"standard"*).
79+
1. Set _numberFormat_.[[Notation]] to _notation_.
80+
1. Perform ? SetNumberFormatDigitOptions(_numberFormat_, _options_, _mnfdDefault_, _mxfdDefault_, _notation_).
81+
1. Let _compactDisplay_ be ? GetOption(_options_, *"compactDisplay"*, *"string"*, &laquo; *"short"*, *"long"* &raquo;, *"short"*).
82+
1. If _notation_ is *"compact"*, then
83+
1. Set _numberFormat_.[[CompactDisplay]] to _compactDisplay_.
84+
1. Let _useGrouping_ be ? GetOption(_options_, *"useGrouping"*, *"boolean"*, *undefined*, *true*).
85+
1. Set _numberFormat_.[[UseGrouping]] to _useGrouping_.
86+
1. Let _signDisplay_ be ? GetOption(_options_, *"signDisplay"*, *"string"*, &laquo; *"auto"*, *"never"*, *"always"*, *"exceptZero"* &raquo;, *"auto"*).
87+
1. Set _numberFormat_.[[SignDisplay]] to _signDisplay_.
88+
1. Return _numberFormat_.
89+
</emu-alg>
90+
</emu-clause>
3891
</emu-clause>
3992

4093
<emu-clause id="sec-numberformat-abstracts">
@@ -101,59 +154,6 @@
101154
</emu-alg>
102155
</emu-clause>
103156

104-
<emu-clause id="sec-initializenumberformat" aoid="InitializeNumberFormat">
105-
<h1>InitializeNumberFormat ( _numberFormat_, _locales_, _options_ )</h1>
106-
107-
<p>
108-
The abstract operation InitializeNumberFormat accepts the arguments _numberFormat_ (which must be an object), _locales_, and _options_. It initializes _numberFormat_ as a NumberFormat object. The following steps are taken:
109-
</p>
110-
111-
<p>
112-
The following algorithm refers to the `type` nonterminal from <a href="https://www.unicode.org/reports/tr35/#Unicode_locale_identifier">UTS 35's Unicode Locale Identifier grammar</a>.
113-
</p>
114-
115-
<emu-alg>
116-
1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_).
117-
1. Set _options_ to ? CoerceOptionsToObject(_options_).
118-
1. Let _opt_ be a new Record.
119-
1. Let _matcher_ be ? GetOption(_options_, *"localeMatcher"*, *"string"*, &laquo; *"lookup"*, *"best fit"* &raquo;, *"best fit"*).
120-
1. Set _opt_.[[localeMatcher]] to _matcher_.
121-
1. Let _numberingSystem_ be ? GetOption(_options_, *"numberingSystem"*, *"string"*, *undefined*, *undefined*).
122-
1. If _numberingSystem_ is not *undefined*, then
123-
1. If _numberingSystem_ does not match the Unicode Locale Identifier `type` nonterminal, throw a *RangeError* exception.
124-
1. Set _opt_.[[nu]] to _numberingSystem_.
125-
1. Let _localeData_ be %NumberFormat%.[[LocaleData]].
126-
1. Let _r_ be ResolveLocale(%NumberFormat%.[[AvailableLocales]], _requestedLocales_, _opt_, %NumberFormat%.[[RelevantExtensionKeys]], _localeData_).
127-
1. Set _numberFormat_.[[Locale]] to _r_.[[locale]].
128-
1. Set _numberFormat_.[[DataLocale]] to _r_.[[dataLocale]].
129-
1. Set _numberFormat_.[[NumberingSystem]] to _r_.[[nu]].
130-
1. Perform ? SetNumberFormatUnitOptions(_numberFormat_, _options_).
131-
1. Let _style_ be _numberFormat_.[[Style]].
132-
1. If _style_ is *"currency"*, then
133-
1. Let _currency_ be _numberFormat_.[[Currency]].
134-
1. Let _cDigits_ be CurrencyDigits(_currency_).
135-
1. Let _mnfdDefault_ be _cDigits_.
136-
1. Let _mxfdDefault_ be _cDigits_.
137-
1. Else,
138-
1. Let _mnfdDefault_ be 0.
139-
1. If _style_ is *"percent"*, then
140-
1. Let _mxfdDefault_ be 0.
141-
1. Else,
142-
1. Let _mxfdDefault_ be 3.
143-
1. Let _notation_ be ? GetOption(_options_, *"notation"*, *"string"*, &laquo; *"standard"*, *"scientific"*, *"engineering"*, *"compact"* &raquo;, *"standard"*).
144-
1. Set _numberFormat_.[[Notation]] to _notation_.
145-
1. Perform ? SetNumberFormatDigitOptions(_numberFormat_, _options_, _mnfdDefault_, _mxfdDefault_, _notation_).
146-
1. Let _compactDisplay_ be ? GetOption(_options_, *"compactDisplay"*, *"string"*, &laquo; *"short"*, *"long"* &raquo;, *"short"*).
147-
1. If _notation_ is *"compact"*, then
148-
1. Set _numberFormat_.[[CompactDisplay]] to _compactDisplay_.
149-
1. Let _useGrouping_ be ? GetOption(_options_, *"useGrouping"*, *"boolean"*, *undefined*, *true*).
150-
1. Set _numberFormat_.[[UseGrouping]] to _useGrouping_.
151-
1. Let _signDisplay_ be ? GetOption(_options_, *"signDisplay"*, *"string"*, &laquo; *"auto"*, *"never"*, *"always"*, *"exceptZero"* &raquo;, *"auto"*).
152-
1. Set _numberFormat_.[[SignDisplay]] to _signDisplay_.
153-
1. Return _numberFormat_.
154-
</emu-alg>
155-
</emu-clause>
156-
157157
<emu-clause id="sec-currencydigits" aoid="CurrencyDigits">
158158
<h1>CurrencyDigits ( _currency_ )</h1>
159159

numberformat/diff.emu

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,72 @@
3535
</emu-alg>
3636
</emu-clause>
3737
<emu-note>See <emu-xref href="#legacy-constructor"></emu-xref> for the motivation of the normative optional text.</emu-note>
38+
39+
<emu-clause id="sec-initializenumberformat" aoid="InitializeNumberFormat">
40+
<h1>InitializeNumberFormat ( _numberFormat_, _locales_, _options_ )</h1>
41+
42+
<p>
43+
The abstract operation InitializeNumberFormat accepts the arguments _numberFormat_ (which must be an object), _locales_, and _options_. It initializes _numberFormat_ as a NumberFormat object. The following steps are taken:
44+
</p>
45+
46+
<p>
47+
The following algorithm refers to the `type` nonterminal from <a href="https://www.unicode.org/reports/tr35/#Unicode_locale_identifier">UTS 35's Unicode Locale Identifier grammar</a>.
48+
</p>
49+
50+
<emu-alg>
51+
1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_).
52+
1. Set _options_ to ? CoerceOptionsToObject(_options_).
53+
1. Let _opt_ be a new Record.
54+
1. Let _matcher_ be ? GetOption(_options_, *"localeMatcher"*, *"string"*, &laquo; *"lookup"*, *"best fit"* &raquo;, *"best fit"*).
55+
1. Set _opt_.[[localeMatcher]] to _matcher_.
56+
1. Let _numberingSystem_ be ? GetOption(_options_, *"numberingSystem"*, *"string"*, *undefined*, *undefined*).
57+
1. If _numberingSystem_ is not *undefined*, then
58+
1. If _numberingSystem_ does not match the Unicode Locale Identifier `type` nonterminal, throw a *RangeError* exception.
59+
1. Set _opt_.[[nu]] to _numberingSystem_.
60+
1. Let _localeData_ be %NumberFormat%.[[LocaleData]].
61+
1. Let _r_ be ResolveLocale(%NumberFormat%.[[AvailableLocales]], _requestedLocales_, _opt_, %NumberFormat%.[[RelevantExtensionKeys]], _localeData_).
62+
1. Set _numberFormat_.[[Locale]] to _r_.[[locale]].
63+
1. Set _numberFormat_.[[DataLocale]] to _r_.[[dataLocale]].
64+
1. Set _numberFormat_.[[NumberingSystem]] to _r_.[[nu]].
65+
1. Perform ? SetNumberFormatUnitOptions(_numberFormat_, _options_).
66+
1. Let _style_ be _numberFormat_.[[Style]].
67+
1. If _style_ is *"currency"*, then
68+
1. Let _currency_ be _numberFormat_.[[Currency]].
69+
1. Let _cDigits_ be CurrencyDigits(_currency_).
70+
1. Let _mnfdDefault_ be _cDigits_.
71+
1. Let _mxfdDefault_ be _cDigits_.
72+
1. Else,
73+
1. Let _mnfdDefault_ be 0.
74+
1. If _style_ is *"percent"*, then
75+
1. Let _mxfdDefault_ be 0.
76+
1. Else,
77+
1. Let _mxfdDefault_ be 3.
78+
1. <ins class="block">Let _roundingIncrement_ be ? GetNumberOption(_options_, *"roundingIncrement"*, 1, 5000, 1).</ins>
79+
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>
80+
1. <ins class="block">If _roundingIncrement_ is not 1, set _mxfdDefault_ to _mnfdDefault_.</ins>
81+
1. Let _notation_ be ? GetOption(_options_, *"notation"*, *"string"*, &laquo; *"standard"*, *"scientific"*, *"engineering"*, *"compact"* &raquo;, *"standard"*).
82+
1. Set _numberFormat_.[[Notation]] to _notation_.
83+
1. Perform ? SetNumberFormatDigitOptions(_numberFormat_, _options_, _mnfdDefault_, _mxfdDefault_, _notation_).
84+
1. <ins class="block">If _roundingIncrement_ is not 1, then</ins>
85+
1. <ins class="block">If _numberFormat_.[[RoundingType]] is not ~fractionDigits~, throw a *TypeError* exception.</ins>
86+
1. <ins class="block">If _numberFormat_.[[MaximumFractionDigits]] is not equal to _numberFormat_.[[MinimumFractionDigits]], throw a *RangeError* exception.</ins>
87+
1. <ins class="block">Set _numberFormat_.[[RoundingIncrement]] to _roundingIncrement_.</ins>
88+
1. <ins class="block">Let _trailingZeroDisplay_ be ? GetOption(_options_, *"trailingZeroDisplay"*, *"string"*, &laquo; *"auto"*, *"stripIfInteger"* &raquo;, *"auto"*).</ins>
89+
1. <ins class="block">Set _numberFormat_.[[TrailingZeroDisplay]] to _trailingZeroDisplay_.</ins>
90+
1. Let _compactDisplay_ be ? GetOption(_options_, *"compactDisplay"*, *"string"*, &laquo; *"short"*, *"long"* &raquo;, *"short"*).
91+
1. <ins class="block">Let _defaultUseGrouping_ be *"auto"*.</ins>
92+
1. If _notation_ is *"compact"*, then
93+
1. Set _numberFormat_.[[CompactDisplay]] to _compactDisplay_.
94+
1. <ins class="block">Set _defaultUseGrouping_ to *"min2"*.</ins>
95+
1. Let _useGrouping_ be ? Get<ins>StringOrBoolean</ins>Option(_options_, *"useGrouping"*, <del>*"boolean"*, *undefined*, *true*</del> <ins>&laquo; *"min2"*, *"auto"*, *"always"* &raquo;, *"always"*, *false*, _defaultUseGrouping_</ins>).
96+
1. Set _numberFormat_.[[UseGrouping]] to _useGrouping_.
97+
1. Let _signDisplay_ be ? GetOption(_options_, *"signDisplay"*, *"string"*, &laquo; *"auto"*, *"never"*, *"always"*, *"exceptZero"*<ins>, *"negative"*</ins> &raquo;, *"auto"*).
98+
1. Set _numberFormat_.[[SignDisplay]] to _signDisplay_.
99+
1. <ins class="block">Let _roundingMode_ be ? GetOption(_options_, *"roundingMode"*, *"string"*, &laquo; *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, *"halfEven"* &raquo;, *"halfExpand"*).</ins>
100+
1. <ins class="block">Set _numberFormat_.[[RoundingMode]] to _roundingMode_.</ins>
101+
1. Return _numberFormat_.
102+
</emu-alg>
103+
</emu-clause>
38104
</emu-clause>
39105

40106
<emu-clause id="sec-numberformat-abstracts">
@@ -119,72 +185,6 @@
119185
</emu-alg>
120186
</emu-clause>
121187

122-
<emu-clause id="sec-initializenumberformat" aoid="InitializeNumberFormat">
123-
<h1>InitializeNumberFormat ( _numberFormat_, _locales_, _options_ )</h1>
124-
125-
<p>
126-
The abstract operation InitializeNumberFormat accepts the arguments _numberFormat_ (which must be an object), _locales_, and _options_. It initializes _numberFormat_ as a NumberFormat object. The following steps are taken:
127-
</p>
128-
129-
<p>
130-
The following algorithm refers to the `type` nonterminal from <a href="https://www.unicode.org/reports/tr35/#Unicode_locale_identifier">UTS 35's Unicode Locale Identifier grammar</a>.
131-
</p>
132-
133-
<emu-alg>
134-
1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_).
135-
1. Set _options_ to ? CoerceOptionsToObject(_options_).
136-
1. Let _opt_ be a new Record.
137-
1. Let _matcher_ be ? GetOption(_options_, *"localeMatcher"*, *"string"*, &laquo; *"lookup"*, *"best fit"* &raquo;, *"best fit"*).
138-
1. Set _opt_.[[localeMatcher]] to _matcher_.
139-
1. Let _numberingSystem_ be ? GetOption(_options_, *"numberingSystem"*, *"string"*, *undefined*, *undefined*).
140-
1. If _numberingSystem_ is not *undefined*, then
141-
1. If _numberingSystem_ does not match the Unicode Locale Identifier `type` nonterminal, throw a *RangeError* exception.
142-
1. Set _opt_.[[nu]] to _numberingSystem_.
143-
1. Let _localeData_ be %NumberFormat%.[[LocaleData]].
144-
1. Let _r_ be ResolveLocale(%NumberFormat%.[[AvailableLocales]], _requestedLocales_, _opt_, %NumberFormat%.[[RelevantExtensionKeys]], _localeData_).
145-
1. Set _numberFormat_.[[Locale]] to _r_.[[locale]].
146-
1. Set _numberFormat_.[[DataLocale]] to _r_.[[dataLocale]].
147-
1. Set _numberFormat_.[[NumberingSystem]] to _r_.[[nu]].
148-
1. Perform ? SetNumberFormatUnitOptions(_numberFormat_, _options_).
149-
1. Let _style_ be _numberFormat_.[[Style]].
150-
1. If _style_ is *"currency"*, then
151-
1. Let _currency_ be _numberFormat_.[[Currency]].
152-
1. Let _cDigits_ be CurrencyDigits(_currency_).
153-
1. Let _mnfdDefault_ be _cDigits_.
154-
1. Let _mxfdDefault_ be _cDigits_.
155-
1. Else,
156-
1. Let _mnfdDefault_ be 0.
157-
1. If _style_ is *"percent"*, then
158-
1. Let _mxfdDefault_ be 0.
159-
1. Else,
160-
1. Let _mxfdDefault_ be 3.
161-
1. <ins class="block">Let _roundingIncrement_ be ? GetNumberOption(_options_, *"roundingIncrement"*, 1, 5000, 1).</ins>
162-
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>
163-
1. <ins class="block">If _roundingIncrement_ is not 1, set _mxfdDefault_ to _mnfdDefault_.</ins>
164-
1. Let _notation_ be ? GetOption(_options_, *"notation"*, *"string"*, &laquo; *"standard"*, *"scientific"*, *"engineering"*, *"compact"* &raquo;, *"standard"*).
165-
1. Set _numberFormat_.[[Notation]] to _notation_.
166-
1. Perform ? SetNumberFormatDigitOptions(_numberFormat_, _options_, _mnfdDefault_, _mxfdDefault_, _notation_).
167-
1. <ins class="block">If _roundingIncrement_ is not 1, then</ins>
168-
1. <ins class="block">If _numberFormat_.[[RoundingType]] is not ~fractionDigits~, throw a *TypeError* exception.</ins>
169-
1. <ins class="block">If _numberFormat_.[[MaximumFractionDigits]] is not equal to _numberFormat_.[[MinimumFractionDigits]], throw a *RangeError* exception.</ins>
170-
1. <ins class="block">Set _numberFormat_.[[RoundingIncrement]] to _roundingIncrement_.</ins>
171-
1. <ins class="block">Let _trailingZeroDisplay_ be ? GetOption(_options_, *"trailingZeroDisplay"*, *"string"*, &laquo; *"auto"*, *"stripIfInteger"* &raquo;, *"auto"*).</ins>
172-
1. <ins class="block">Set _numberFormat_.[[TrailingZeroDisplay]] to _trailingZeroDisplay_.</ins>
173-
1. Let _compactDisplay_ be ? GetOption(_options_, *"compactDisplay"*, *"string"*, &laquo; *"short"*, *"long"* &raquo;, *"short"*).
174-
1. <ins class="block">Let _defaultUseGrouping_ be *"auto"*.</ins>
175-
1. If _notation_ is *"compact"*, then
176-
1. Set _numberFormat_.[[CompactDisplay]] to _compactDisplay_.
177-
1. <ins class="block">Set _defaultUseGrouping_ to *"min2"*.</ins>
178-
1. Let _useGrouping_ be ? Get<ins>StringOrBoolean</ins>Option(_options_, *"useGrouping"*, <del>*"boolean"*, *undefined*, *true*</del> <ins>&laquo; *"min2"*, *"auto"*, *"always"* &raquo;, *"always"*, *false*, _defaultUseGrouping_</ins>).
179-
1. Set _numberFormat_.[[UseGrouping]] to _useGrouping_.
180-
1. Let _signDisplay_ be ? GetOption(_options_, *"signDisplay"*, *"string"*, &laquo; *"auto"*, *"never"*, *"always"*, *"exceptZero"*<ins>, *"negative"*</ins> &raquo;, *"auto"*).
181-
1. Set _numberFormat_.[[SignDisplay]] to _signDisplay_.
182-
1. <ins class="block">Let _roundingMode_ be ? GetOption(_options_, *"roundingMode"*, *"string"*, &laquo; *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, *"halfEven"* &raquo;, *"halfExpand"*).</ins>
183-
1. <ins class="block">Set _numberFormat_.[[RoundingMode]] to _roundingMode_.</ins>
184-
1. Return _numberFormat_.
185-
</emu-alg>
186-
</emu-clause>
187-
188188
<emu-clause id="sec-currencydigits" aoid="CurrencyDigits">
189189
<h1>CurrencyDigits ( _currency_ )</h1>
190190

0 commit comments

Comments
 (0)