Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 113 additions & 44 deletions intl.emu
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,126 @@

<emu-clause id="sup-amount.prototype.tolocalestring">
<h1>Amount.prototype.toLocaleString ( [ _locales_ [ , _options_ ] ] )</h1>
<p>This definition supersedes the definition provided in es2025, <emu-xref href="#sec-amount.prototype.tolocalestring"></emu-xref>.</p>

<p>
This definition supersedes the definition provided in es2025, <emu-xref href="#sec-amount.prototype.tolocalestring"></emu-xref>.
</p>
<p>This function performs the following steps when called:</p>

<p>
This function performs the following steps when called:
</p>
<emu-alg>
1. Let _O_ be the *this* value.
1. Perform ? RequireInternalSlot(_O_, [[AmountValue]]).
1. Let _v_ be _O_.[[AmountValue]].
1. If _v_ is a String, then
1. Let _numValue_ be _v_.
1. Else if _v_ is a BigInt, then
1. Let _numValue_ be BigInt::toString(_v_, 10).
1. Else,
1. Assert: _v_ is a Number.
1. Let _numValue_ be _v_.
1. Let _unit_ be _O_.[[Unit]].
1. Let _mergedOptions_ be OrdinaryObjectCreate(*null*).
1. If _options_ is not *undefined*, then
1. Let _optionsObj_ be ? GetOptionsObject(_options_).
1. Perform ? CopyDataProperties(_mergedOptions_, _optionsObj_, « »).
1. If _unit_ is not *undefined*, then
1. If ? HasProperty(_mergedOptions_, *"style"*) is *false*, then
1. If IsWellFormedCurrencyCode(_unit_) is *true*, then
1. Perform ! CreateDataPropertyOrThrow(_mergedOptions_, *"style"*, *"currency"*).
1. If ? HasProperty(_mergedOptions_, *"currency"*) is *false*, then
1. Perform ! CreateDataPropertyOrThrow(_mergedOptions_, *"currency"*, _unit_).
1. Else,
1. Perform ! CreateDataPropertyOrThrow(_mergedOptions_, *"style"*, *"unit"*).
1. If ? HasProperty(_mergedOptions_, *"unit"*) is *false*, then
1. Perform ! CreateDataPropertyOrThrow(_mergedOptions_, *"unit"*, _unit_).
1. Let _numberFormat_ be ? Construct(%Intl.NumberFormat%, « _locales_, _mergedOptions_ »).
1. Return FormatNumeric(_numberFormat_, _numValue_).
</emu-alg>
</emu-clause>

<emu-clause id="sup-amount.prototype.convertto">
<h1>Amount.prototype.convertTo ( _options_ )</h1>

<p>This definition supersedes the definition provided in es2025, <emu-xref href="#sec-amount.prototype.convertto"></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%, &laquo; _locales_, _options_ &raquo;).
1. Return FormatNumeric(_numberFormat_, _O_.[[AmountData]]).
1. Perform ? RequireInternalSlot(_O_, [[AmountValue]]).
1. Let _sourceUnit_ be _O_.[[Unit]].
1. If _sourceUnit_ is *undefined*, throw a *TypeError* exception.
1. Let _validatedOpts_ be ? GetAmountConvertToOptions(_options_).
1. Let _targetUnit_ be _validatedOpts_.[[Unit]].
1. Let _roundingMode_ be _validatedOpts_.[[RoundingMode]].
1. Let _roundingPriority_ be _validatedOpts_.[[RoundingPriority]].
1. Let _minFractionDigits_ be _validatedOpts_.[[MiniumumFractionDigits]].
1. Let _maxFractionDigits_ be _validatedOpts_.[[MaximumFractionDigits]].
1. Let _minSignificantDigits_ be _validatedOpts_.[[MinimumSignificantDigits]].
1. Let _maxSignificantDigits_ be _validatedOpts_.[[MaximumSignificantDigits]].
1. Let _locale_ be _validatedOpts_.[[Locale]].
1. Let _usage_ be _validatedOpts_.[[Usage]].
1. If _targetUnit_ is *undefined* and _locale_ is *undefined* and _usage_ is *undefined*, throw a *TypeError* exception.
1. Let _v_ be _O_.[[AmountValue]].
1. If _v_ is a Number, then
1. Let _sourceValue_ be _v_.
1. Else if _v_ is a BigInt, then
1. Let _sourceValue_ be 𝔽(ℝ(_v_)).
1. Else,
1. Assert: _v_ is a String.
1. Let _sourceValue_ be StringToNumber(_v_).
1. If _targetUnit_ is not *undefined*, then
1. If _locale_ is not *undefined* or _usage_ is not *undefined*, throw a *TypeError* exception.
1. Else,
1. Let _matcher_ be ? GetOption(_validatedOpts_, *"localeMatcher"*, ~string~, « *"lookup"*, *"best fit"* », *"best fit"*).
1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locale_).
1. If _usage_ is *undefined*, set _usage_ to *"default"*.
1. Set _targetUnit_ to ? ResolveUnitPreference(_sourceUnit_, _sourceValue_, _requestedLocales_, _usage_, _matcher_).
1. Let _convertedValue_ be ? ConvertUnitValue(_sourceValue_, _sourceUnit_, _targetUnit_).
1. Let _result_ be OrdinaryObjectCreate(%Amount.prototype%, « [[AmountValue]], [[Unit]] »).
1. TODO Let _intlObject_ be an Object suitable for use as the first argument of a call to <emu-xref href="#sec-formatnumerictostring">FormatNumericToString</emu-xref> that uses _minSignificantDigits_, _maxSignificantDigits_, _minFractionDigits_, _maxFractionDigits_, _roundingPriority_, and _roundingMode_.
1. Let _formatted_ be FormatNumericToString(_intlObject_, _convertedValue_, 0).
1. Set _result_.[[AmountValue]] to _formatted_.[[FormattedString]].
1. Set _result_.[[Unit]] to _targetUnit_.
1. Return _result_.
</emu-alg>
</emu-clause>

<emu-clause id="sec-resolveunitpreference" type="implementation-defined abstract operation">
<h1>ResolveUnitPreference (
_sourceUnit_: a String,
_sourceValue_: a Number,
_requestedLocales_: a Language Priority List,
_usage_: a String,
_localeMatcher_: a String,
): either a normal completion containing a String or a throw completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>It determines the preferred target unit for _sourceUnit_ in the locale best matching _requestedLocales_ and _usage_ context, based on CLDR unit preferences data.</dd>
</dl>
<emu-alg>
1. Let _sourceConv_ be ? GetUnitConversionFactor(_sourceUnit_).
1. Let _category_ be _sourceConv_.[[Category]].
1. Let _availableLocales_ be the Available Locales List for locales for which the <code>&lt;unitPreferences></code> element data of <a href="https://unicode.org/reports/tr35/tr35-info.html#Unit_Preferences">UTS #35 Part 6 Supplemental, Unit Preferences</a> includes data.
1. Let _localeData_ be a Record whose field names are the elements of _availableLocales_ and whose values are Records.
1. Let _r_ be ResolveLocale(_availableLocales_, _requestedLocales_, the Record { [[localeMatcher]]: _localeMatcher_ }, « », _localeData_).
1. Let _locale_ be _r_.[[Locale]].
1. Let _preferredUnit_ be the preferred unit for _category_, _locale_, _usage_, and _sourceValue_ as specified by the <code>&lt;unitPreferences></code> element data of <a href="https://unicode.org/reports/tr35/tr35-info.html#Unit_Preferences">UTS #35 Part 6 Supplemental, Unit Preferences</a>.
1. If _preferredUnit_ is *undefined*, throw a *RangeError* exception.
1. Return _preferredUnit_.
</emu-alg>
</emu-clause>
</emu-clause>

<emu-clause id="sec-amount-intl-normative-references">
<h1>Amendment to the Normative References of ECMA-402</h1>
<emu-note type="editor">
<p>The following entry is to be added to ECMA-402's list of referenced parts of Unicode Technical Standard #35.</p>
</emu-note>
<ul>
<li>
<a href="https://unicode.org/reports/tr35/tr35-info.html#Unit_Preferences">Part 6 Supplemental, Unit Preferences</a>
</li>
</ul>
</emu-clause>
</emu-clause>

Expand Down Expand Up @@ -138,41 +242,6 @@
</emu-alg>
</emu-clause>

<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>description</dt>
<dd>
It returns _value_ converted to an <dfn id="intl-mathematical-value">Intl mathematical value</dfn>, which is a mathematical value together with ~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 the [[Value]] and [[FractionDigits]] internal slots, let _primValue_ be RenderAmountValueWithFractionDigits(_value_.[[Value]], _value_.[[FractionDigits]]) else</ins><del>Let</del> <ins>let</ins _primValue_ be ? ToPrimitive(_value_, ~number~).
1. If _primValue_ is a BigInt, return ℝ(_primValue_).
1. If _primValue_ is a 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_ &lt; 0, return ~negative-infinity~.
1. If _rounded_ is *+∞*<sub>𝔽</sub>, return ~positive-infinity~.
1. If _rounded_ is *+0*<sub>𝔽</sub> and _intlMV_ &lt; 0, return ~negative-zero~.
1. If _rounded_ is *+0*<sub>𝔽</sub>, return 0.
1. Return _intlMV_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-setnumberformatunitoptions" type="abstract operation">
<h1>
SetNumberFormatUnitOptions (
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"start": "npm run build-loose -- --watch",
"build": "npm run build-loose -- --strict",
"build-loose": "ecmarkup --load-biblio @tc39/ecma262-biblio --load-biblio @tc39/ecma402-biblio --verbose --lint-spec spec.emu index.html"
"build-loose": "ecmarkup --load-biblio @tc39/ecma262-biblio --load-biblio @tc39/ecma402-biblio --load-biblio ./proposal-intl-keep-trailing-zeros-biblio.json --verbose --lint-spec spec.emu index.html"
},
"homepage": "https://github.com/tc39/template-for-proposals#readme",
"repository": {
Expand Down
Loading