Skip to content

Commit

Permalink
Normative: Avoid reading options twice
Browse files Browse the repository at this point in the history
This patch refactors NumberFormat's option parsing code to avoid
redundant Get calls for {minimum,maximum}SignificantDigits .

Fixes tc39#131
  • Loading branch information
littledan committed Mar 18, 2017
1 parent 3f63d93 commit 0b8ca35
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 17 additions & 5 deletions spec/negotiation.html
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,14 @@ <h1>GetOption ( _options_, _property_, _type_, _values_, _fallback_ )</h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-getnumberoption" aoid="GetNumberOption">
<h1>GetNumberOption ( _options_, _property_, _minimum_, _maximum_, _fallback_ )</h1>
<emu-clause id="sec-defaultnumberoption" aoid="DefaultNumberOption">
<h1>DefaultNumberOption ( _value_, _minimum_, _maximum_, _fallback_ )</h1>

<p>
The abstract operation GetNumberOption extracts the value of the property named _property_ from the provided _options_ object, converts it to a Number value, checks whether it is in the allowed range, and fills in a _fallback_ value if necessary.
The abstract operation DefaultNumberOption converts _value_ to a Number value, checks whether it is in the allowed range, and fills in a _fallback_ value if necessary.
</p>

<emu-alg>
1. Let _opts_ be ? ToObject(_options_).
1. Let _value_ be ? Get(_opts_, _property_).
1. If _value_ is not *undefined*, then
1. Let _value_ be ? ToNumber(_value_).
1. If _value_ is *NaN* or less than _minimum_ or greater than _maximum_, throw a *RangeError* exception.
Expand All @@ -338,5 +336,19 @@ <h1>GetNumberOption ( _options_, _property_, _minimum_, _maximum_, _fallback_ )<
</emu-alg>
</emu-clause>

<emu-clause id="sec-getnumberoption" aoid="GetNumberOption">
<h1>GetNumberOption ( _options_, _property_, _minimum_, _maximum_, _fallback_ )</h1>

<p>
The abstract operation GetNumberOption extracts the value of the property named _property_ from the provided _options_ object, converts it to a Number value, checks whether it is in the allowed range, and fills in a _fallback_ value if necessary.
</p>

<emu-alg>
1. Let _opts_ be ? ToObject(_options_).
1. Let _value_ be ? Get(_opts_, _property_).
1. Return ? DefaultNumberOption(_value_, _minimum_, _maximum_, _fallback_).
</emu-alg>
</emu-clause>

</emu-clause>
</emu-clause>
4 changes: 2 additions & 2 deletions spec/numberformat.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ <h1>SetNumberFormatDigitOptions ( _intlObj_, _options_, _mnfdDefault_, _mxfdDefa
1. Set _intlObj_.[[MinimumFractionDigits]] to mnfd.
1. Set _intlObj_.[[MaximumFractionDigits]] to mxfd.
1. If _mnsd_ is not *undefined* or _mxsd_ is not *undefined*, then
1. Let _mnsd_ be ? GetNumberOption(_options_, *"minimumSignificantDigits"*, 1, 21, 1).
1. Let _mxsd_ be ? GetNumberOption(_options_, *"maximumSignificantDigits"*, _mnsd_, 21, 21).
1. Let _mnsd_ be ? DefaultNumberOption(_mnsd_, 1, 21, 1).
1. Let _mxsd_ be ? DefaultNumberOption(_mxsd_, _mnsd_, 21, 21).
1. Set _intlObj_.[[MinimumSignificantDigits]] to mnsd.
1. Set _intlObj_.[[MaximumSignificantDigits]] to mxsd.
</emu-alg>
Expand Down

0 comments on commit 0b8ca35

Please sign in to comment.