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 18, 2021
1 parent 9d542ce commit 4563151
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -4793,7 +4793,7 @@ <h1>
String
</td>
<td>
See grammar and conversion algorithm below.
Return ! StringToNumber(_argument_).
</td>
</tr>
<tr>
Expand Down Expand Up @@ -4830,7 +4830,7 @@ <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 @@ -4884,9 +4884,27 @@ <h2>Syntax</h2>
</ul>
</emu-note>

<emu-clause id="sec-stringtonumber" type="abstract operation">
<h1>
StringToNumber (
_str_: a String,
)
</h1>
<dl class="header">
<dt>description</dt>
<dd>It returns a Number.</dd>
</dl>
<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 4563151

Please sign in to comment.