From e8af6134a1eb292b97819e12a899747571af8b0c Mon Sep 17 00:00:00 2001 From: Michael Dyck Date: Mon, 19 Jul 2021 11:22:53 -0700 Subject: [PATCH 1/2] Editorial: Remove ToNumber's note re surrogates (#1554) The note says that "the result of ToNumber will be *NaN* if the string contains any [surrogate] code units, whether paired or unpaired." However, if Unicode were to define a non-BMP code point with General_Category=Zs, that would qualify as and thus WhiteSpace and StrWhiteSpaceChar, in which case the note would be rendered false. That is, the ToNumber procedure would continue to work, and would result in non-NaN values for some strings containing surrogates. (And if you think that the ES spec doesn't need to concern itself with such future possibilities, note that ES 6 (2015) changed/clarified the semantics of String.p.trim et al for precisely this case, to say how they would deal with non-BMP white space.) Given that the note could be invalidated by a future edition of Unicode, I think it's a bit risky to keep it in. --- spec.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/spec.html b/spec.html index c61653bf38..ac02a6a2df 100644 --- a/spec.html +++ b/spec.html @@ -4831,9 +4831,6 @@

ToNumber Applied to the String Type

ToNumber applied to Strings applies the following grammar to the input String interpreted as a sequence of UTF-16 encoded code points (). If the grammar cannot interpret the String as an expansion of |StringNumericLiteral|, then the result of ToNumber is *NaN*.

- -

The terminal symbols of this grammar are all composed of characters in the Unicode Basic Multilingual Plane (BMP). Therefore, the result of ToNumber will be *NaN* if the string contains any or code units, whether paired or unpaired.

-

Syntax

StringNumericLiteral ::: From 37d6204945862d0a1379e771b1352a1eb158618e Mon Sep 17 00:00:00 2001 From: Michael Dyck Date: Mon, 19 Jul 2021 11:23:04 -0700 Subject: [PATCH 2/2] Editorial: Define + use StringToNumber (#1554) Introduce the abstract operation StringToNumber to replace the prose that expressed the procedure for applying ToNumber to String values. --- spec.html | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/spec.html b/spec.html index ac02a6a2df..cb67acb432 100644 --- a/spec.html +++ b/spec.html @@ -4793,7 +4793,7 @@

String - See grammar and conversion algorithm below. + Return ! StringToNumber(_argument_). @@ -4830,7 +4830,7 @@

ToNumber Applied to the String Type

-

ToNumber applied to Strings applies the following grammar to the input String interpreted as a sequence of UTF-16 encoded code points (). If the grammar cannot interpret the String as an expansion of |StringNumericLiteral|, then the result of ToNumber is *NaN*.

+

The abstract operation StringToNumber specifies how to convert a String value to a Number value, using the following grammar.

Syntax

StringNumericLiteral ::: @@ -4884,9 +4884,27 @@

Syntax

+ +

+ StringToNumber ( + _str_: a String, + ) +

+
+
description
+
It returns a Number.
+
+ + 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_. + +
+

Runtime Semantics: StringNumericValue

-

The conversion of a String to a Number value is similar overall to the determination of the Number value for a numeric literal (see ), 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.

+

The conversion of a |StringNumericLiteral| to a Number value is similar overall to the determination of the NumericValue of a |NumericLiteral| (see ), but some of the details are different.

StringNumericLiteral ::: StrWhiteSpace? 1. Return *+0*𝔽.