-
Notifications
You must be signed in to change notification settings - Fork 18
/
intl.emu
155 lines (142 loc) · 8.6 KB
/
intl.emu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<emu-clause id="sec-decimal-intl">
<h1>Amendments to the ECMAScript® 2024 Internationalization API Specification</h1>
<emu-note type="editor">
<p>
This section lists amendments which must be made to <a href="https://tc39.es/ecma402/">ECMA-402, the ECMAScript® 2024 Internationalization API Specification</a>.
Text to be added is marked <ins>like this</ins>, and text to be deleted is marked <del>like this</del>.
Blocks of unmodified text between modified sections are marked by [...].
</p>
</emu-note>
<emu-clause id="sup-properties-of-the-decimal128-prototype-object">
<h1>Properties of the Decimal128 Prototype Object</h1>
<emu-clause id="sup-decimal128.prototype.tolocalestring">
<h1>Decimal128.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )</h1>
<p>
This definition supersedes the definition provided in es2024, <emu-xref href="#sec-decimal128.prototype.tolocalestring"></emu-xref>.
</p>
<p>
This function performs the following steps when called:
</p>
<emu-alg>
1. Let _O_ be the *this* value.
1. Perform ? RequireInternalSlot(_O_, [[Decimal128Data]]).
1. Let _numberFormat_ be ? Construct(%Intl.NumberFormat%, « _locales_, _options_ »).
1. Return FormatNumeric(_numberFormat_, _O_.[[Decimal128Data]]).
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="numberformat-objects">
<h1>NumberFormat Objects</h1>
<emu-clause id="sec-numberformat-abstracts">
<h1>Abstract Operations for NumberFormat Objects</h1>
<emu-clause id="sec-tointlmathematicalvalue" type="abstract operation">
<h1>
ToIntlMathematicalValue (
_value_: an ECMAScript language value,
): either a normal completion containing an Intl mathematical value or a throw completion
</h1>
<dl class="header">
<dt>skip global checks</dt> <!-- this can be presumably deleted when merged in to 402. It it present only because ecmarkup complains about the totality of ToIntlMathematicalValue. Here's what ecmarkup says: -->
<dd>true</dd> <!-- warning: every call site of ToIntlMathematicalValue asserts the return value is a normal completion; it should be refactored to not return a completion record at all. if this AO is called in ways ecmarkup cannot analyze, add the "skip global checks" attribute to the header (always-asserted-normal) at intl.emu:46:7: -->
<dt>description</dt>
<dd>
It returns _value_ converted to an <dfn id="intl-mathematical-value">Intl mathematical value</dfn>, which is either a mathematical value, or one of ~positive-infinity~, ~negative-infinity~, ~not-a-number~, and ~negative-zero~.
This abstract operation is similar to <emu-xref href="#sec-tonumeric"></emu-xref>, but a mathematical value can be returned instead of a Number or BigInt, so that exact decimal values can be represented.
</dd>
</dl>
<emu-alg>
1. <ins>If _value_ has a [[Decimal128Data]] internal slot, then</ins>
1. <ins>Let _d_ be _value_.[[Decimal128Data]].</ins>
1. <ins>If _d_ is *NaN*<sub>𝔻</sub>, return ~not-a-number~.</ins>
1. <ins>If _d_ is *+∞*<sub>𝔻</sub>, return ~positive-infinity~.</ins>
1. <ins>If _d_ is *-∞*<sub>𝔻</sub>, return ~negative-infinity~.</ins>
1. <ins>Return _d_.</ins>
1. Let _primValue_ be ? ToPrimitive(_value_, ~number~).
1. If Type(_primValue_) is BigInt, return ℝ(_primValue_).
1. If Type(_primValue_) is String, then
1. Let _str_ be _primValue_.
1. Else,
1. Let _x_ be ? ToNumber(_primValue_).
1. If _x_ is *-0*<sub>𝔽</sub>, return ~negative-zero~.
1. Let _str_ be Number::toString(_x_, 10).
1. Let _text_ be StringToCodePoints(_str_).
1. Let _literal_ be ParseText(_text_, |StringNumericLiteral|).
1. If _literal_ is a List of errors, return ~not-a-number~.
1. Let _intlMV_ be the StringIntlMV of _literal_.
1. If _intlMV_ is a mathematical value, then
1. Let _rounded_ be RoundMVResult(abs(_intlMV_)).
1. If _rounded_ is *+∞*<sub>𝔽</sub> and _intlMV_ < 0, return ~negative-infinity~.
1. If _rounded_ is *+∞*<sub>𝔽</sub>, return ~positive-infinity~.
1. If _rounded_ is *+0*<sub>𝔽</sub> and _intlMV_ < 0, return ~negative-zero~.
1. If _rounded_ is *+0*<sub>𝔽</sub>, return 0.
1. Return _intlMV_.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
<emu-clause id="pluralrules-objects">
<h1>PluralRules Objects</h1>
<emu-clause id="sec-intl-pluralrules-abstracts">
<h1>Abstract Operations for PluralRules Objects</h1>
<emu-clause id="sec-resolveplural" type="abstract operation">
<h1>
ResolvePlural (
_pluralRules_: an Intl.PluralRules,
_n_: a Number<ins> or an Object with an [[Decimal128Data]] internal slot</ins>,
): a Record with fields [[PluralCategory]] (*"zero"*, *"one"*, *"two"*, *"few"*, *"many"*, or *"other"*) and [[FormattedString]] (a String)
</h1>
<dl class="header">
<dt>description</dt>
<dd>The returned Record contains two string-valued fields describing _n_ according to the effective locale and the options of _pluralRules_: [[PluralCategory]] characterizing its <emu-xref href="#sec-pluralruleselect">plural category</emu-xref>, and [[FormattedString]] containing its formatted representation.</dd>
</dl>
<emu-alg>
1. <ins>If _n_ is *+∞*<sub>𝔽</sub> or *-∞*<sub>𝔽</sub>, then</ins>
1. Let _s_ be ! ToString(_n_).
1. Return the Record { [[PluralCategory]]: *"other"*, [[FormattedString]]: _s_ }.
1. <ins>If _n_ is an Object with a [[Decimal128Data]] internal slot, then</ins>
1. <ins>Let _d_ be _n_.[[Decimal128Data]].</ins>
1. <ins>If _d_ is *NaN*<sub>𝔻</sub>, return the Record { [[PluralCategory]]: *"other"*, [[FormattedString]]: *"NaN"* } .</ins>
1. <ins>If _d_ is *+∞*<sub>𝔻</sub> or *-∞*<sub>𝔻</sub>, then</ins>
1. <ins>If _n_ is *+∞*<sub>𝔻</sub>, let _s_ be *"Infinity"*, otherwise let _s_ be *"-Infinity"*.</ins>
1. <ins>Return the Record { [[PluralCategory]]: *"other"*, [[FormattedString]]: _s_ }.</ins>
1. <ins>Let _n_ be 𝔽(_n_).</ins>
1. <ins>Let _s_ be ! ToString(_n_).</ins>
1. Let _locale_ be _pluralRules_.[[Locale]].
1. Let _type_ be _pluralRules_.[[Type]].
1. <ins>If _n_ is a Number, then</ins>
1. Let _res_ be FormatNumericToString(_pluralRules_, ℝ(_n_)).
1. <ins>Else,</ins>
1. <ins>Let _res_ be FormatNumericToString(_pluralRules_, _n_).</ins>
1. Let _s_ be _res_.[[FormattedString]].
1. Let _operands_ be GetOperands(_s_).
1. Let _p_ be PluralRuleSelect(_locale_, _type_, _n_, _operands_).
1. Return the Record { [[PluralCategory]]: _p_, [[FormattedString]]: _s_ }.
</emu-alg>
</emu-clause>
<emu-clause id="sec-resolvepluralrange" type="abstract operation">
<h1>
ResolvePluralRange (
_pluralRules_: an Intl.PluralRules,
_x_: a Number<ins> or an Object with a [[Decimal128Data]] internal slot</ins>,
_y_: a Number<ins> or an Object with a [[Decimal128Data]] internal slot</ins>,
): either a normal completion containing either *"zero"*, *"one"*, *"two"*, *"few"*, *"many"*, or *"other"*, or a throw completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>The returned String value represents the plural form of the range starting from _x_ and ending at _y_ according to the effective locale and the options of _pluralRules_.</dd>
</dl>
<emu-alg>
1. If _x_ is *NaN* <ins>or *NaN*<sub>𝔻</sub></ins> or _y_ is *NaN*<ins>or *NaN*<sub>𝔻</sub></ins>, throw a *RangeError* exception.
1. Let _xp_ be ResolvePlural(_pluralRules_, _x_).
1. Let _yp_ be ResolvePlural(_pluralRules_, _y_).
1. If _xp_.[[FormattedString]] is _yp_.[[FormattedString]], then
1. Return _xp_.[[PluralCategory]].
1. Let _locale_ be _pluralRules_.[[Locale]].
1. Let _type_ be _pluralRules_.[[Type]].
1. Return PluralRuleSelectRange(_locale_, _type_, _xp_.[[PluralCategory]], _yp_.[[PluralCategory]]).
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
</emu-clause>