Skip to content

Commit

Permalink
Editorial: Define + use StringToNumber (#1554)
Browse files Browse the repository at this point in the history
Introduce the abstract operation StringToNumber
to replace the prose that expressed the procedure
for applying ToNumber to String values.
  • Loading branch information
jmdyck committed Jul 11, 2021
1 parent 7faf6a6 commit 5319884
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -4364,7 +4364,7 @@ <h1>ToNumber ( _argument_ )</h1>
String
</td>
<td>
See grammar and conversion algorithm below.
Return ! StringToNumber(_argument_).
</td>
</tr>
<tr>
Expand Down Expand Up @@ -4401,7 +4401,7 @@ <h1>ToNumber ( _argument_ )</h1>

<emu-clause id="sec-tonumber-applied-to-the-string-type">
<h1>ToNumber Applied to the String Type</h1>
<p>ToNumber applied to Strings applies the following grammar to the input String interpreted as a sequence of UTF-16 encoded code points (<emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>). If the grammar cannot interpret the String as an expansion of |StringNumericLiteral|, then the result of ToNumber is *NaN*.</p>
<p>The abstract operation StringToNumber specifies how to convert a String value to a Number value, using the following grammar.</p>
<h2>Syntax</h2>
<emu-grammar type="definition">
StringNumericLiteral :::
Expand Down Expand Up @@ -4455,9 +4455,20 @@ <h2>Syntax</h2>
</ul>
</emu-note>

<emu-clause id="sec-stringtonumber" aoid="StringToNumber">
<h1>StringToNumber ( _str_ )</h1>
<p>The abstract operation StringToNumber takes argument _str_ (a String) and returns a Number. It performs the following steps when called:</p>
<emu-alg>
1. Let _text_ be ! StringToCodePoints(_str_).
1. Let _literal_ be ParseText(_text_, |StringNumericLiteral|).
1. If _literal_ is a List of errors, return *NaN*.
1. Return StringNumericValue of _literal_.
</emu-alg>
</emu-clause>

<emu-clause id="sec-runtime-semantics-stringnumericvalue" type="sdo" aoid="StringNumericValue" oldids="sec-runtime-semantics-mv-s">
<h1>Runtime Semantics: StringNumericValue</h1>
<p>The conversion of a String to a Number value is similar overall to the determination of the Number value for a numeric literal (see <emu-xref href="#sec-literals-numeric-literals"></emu-xref>), but some of the details are different, so the process for converting a String numeric literal to a value of the Number type is given here.</p>
<p>The conversion of a |StringNumericLiteral| to a Number value is similar overall to the determination of the NumericValue of a |NumericLiteral| (see <emu-xref href="#sec-literals-numeric-literals"></emu-xref>), but some of the details are different.</p>
<emu-grammar>StringNumericLiteral ::: StrWhiteSpace?</emu-grammar>
<emu-alg>
1. Return *+0*<sub>𝔽</sub>.
Expand Down

0 comments on commit 5319884

Please sign in to comment.