Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial: Define + use StringToNumber #1554

Merged
merged 2 commits into from
Jul 19, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Editorial: Define + use StringToNumber (#1554)
Introduce the abstract operation StringToNumber
to replace the prose that expressed the procedure
for applying ToNumber to String values.
jmdyck authored and ljharb committed Jul 19, 2021
commit 37d6204945862d0a1379e771b1352a1eb158618e
24 changes: 21 additions & 3 deletions spec.html
Original file line number Diff line number Diff line change
@@ -4793,7 +4793,7 @@ <h1>
String
</td>
<td>
See grammar and conversion algorithm below.
Return ! StringToNumber(_argument_).
</td>
</tr>
<tr>
@@ -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 :::
@@ -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>.