Skip to content

Commit 7deeb91

Browse files
gibson042ljharb
authored andcommitted
Editorial: Reference leading/trailing surrogate definitions more (#1532)
1 parent 857153d commit 7deeb91

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

spec.html

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28300,7 +28300,7 @@ <h1>String.prototype.charCodeAt ( _pos_ )</h1>
2830028300
<emu-clause id="sec-string.prototype.codepointat">
2830128301
<h1>String.prototype.codePointAt ( _pos_ )</h1>
2830228302
<emu-note>
28303-
<p>Returns a nonnegative integer Number less than 0x110000 that is the code point value of the UTF-16 encoded code point (<emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>) starting at the string element at index _pos_ within the String resulting from converting this object to a String. If there is no element at that index, the result is *undefined*. If a valid UTF-16 <emu-xref href="#surrogate-pair"></emu-xref> does not begin at _pos_, the result is the code unit at _pos_.</p>
28303+
<p>Returns a nonnegative integer Number less than or equal to 0x10FFFF that is the code point value of the UTF-16 encoded code point (<emu-xref href="#sec-ecmascript-language-types-string-type"></emu-xref>) starting at the string element at index _pos_ within the String resulting from converting this object to a String. If there is no element at that index, the result is *undefined*. If a valid UTF-16 <emu-xref href="#surrogate-pair"></emu-xref> does not begin at _pos_, the result is the code unit at _pos_.</p>
2830428304
</emu-note>
2830528305
<p>When the `codePointAt` method is called with one argument _pos_, the following steps are taken:</p>
2830628306
<emu-alg>
@@ -28309,11 +28309,12 @@ <h1>String.prototype.codePointAt ( _pos_ )</h1>
2830928309
1. Let _position_ be ? ToInteger(_pos_).
2831028310
1. Let _size_ be the length of _S_.
2831128311
1. If _position_ &lt; 0 or _position_ &ge; _size_, return *undefined*.
28312-
1. Let _first_ be the numeric value of the code unit at index _position_ within the String _S_.
28313-
1. If _first_ &lt; 0xD800 or _first_ &gt; 0xDBFF or _position_ + 1 = _size_, return _first_.
28314-
1. Let _second_ be the numeric value of the code unit at index _position_ + 1 within the String _S_.
28315-
1. If _second_ &lt; 0xDC00 or _second_ &gt; 0xDFFF, return _first_.
28316-
1. Return UTF16Decode(_first_, _second_).
28312+
1. Let _first_ be the code unit at index _position_ within the String _S_.
28313+
1. If _first_ is not a <emu-xref href="#leading-surrogate"></emu-xref> or if _position_ + 1 = _size_, return the numeric value of _first_.
28314+
1. Let _second_ be the code unit at index _position_ + 1 within the String _S_.
28315+
1. If _second_ is not a <emu-xref href="#trailing-surrogate"></emu-xref>, return the numeric value of _first_.
28316+
1. Let _cp_ be UTF16Decode(_first_, _second_).
28317+
1. Return the code point value of _cp_.
2831728318
</emu-alg>
2831828319
<emu-note>
2831928320
<p>The `codePointAt` function is intentionally generic; it does not require that its *this* value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.</p>
@@ -29112,11 +29113,11 @@ <h1>%StringIteratorPrototype%.next ( )</h1>
2911229113
1. If _position_ &ge; _len_, then
2911329114
1. Set _O_.[[IteratedString]] to *undefined*.
2911429115
1. Return CreateIterResultObject(*undefined*, *true*).
29115-
1. Let _first_ be the numeric value of the code unit at index _position_ within _s_.
29116-
1. If _first_ &lt; 0xD800 or _first_ &gt; 0xDBFF or _position_ + 1 = _len_, let _resultString_ be the String value consisting of the single code unit _first_.
29116+
1. Let _first_ be the code unit at index _position_ within _s_.
29117+
1. If _first_ is not a <emu-xref href="#leading-surrogate"></emu-xref> or if _position_ + 1 = _len_, let _resultString_ be the String value consisting of the single code unit _first_.
2911729118
1. Else,
29118-
1. Let _second_ be the numeric value of the code unit at index _position_ + 1 within the String _s_.
29119-
1. If _second_ &lt; 0xDC00 or _second_ &gt; 0xDFFF, let _resultString_ be the String value consisting of the single code unit _first_.
29119+
1. Let _second_ be the code unit at index _position_ + 1 within the String _s_.
29120+
1. If _second_ is not a <emu-xref href="#trailing-surrogate"></emu-xref>, let _resultString_ be the String value consisting of the single code unit _first_.
2912029121
1. Else, let _resultString_ be the string-concatenation of the code unit _first_ and the code unit _second_.
2912129122
1. Let _resultSize_ be the number of code units in _resultString_.
2912229123
1. Set _O_.[[StringIteratorNextIndex]] to _position_ + _resultSize_.
@@ -31015,10 +31016,10 @@ <h1>AdvanceStringIndex ( _S_, _index_, _unicode_ )</h1>
3101531016
1. If _unicode_ is *false*, return _index_ + 1.
3101631017
1. Let _length_ be the number of code units in _S_.
3101731018
1. If _index_ + 1 &ge; _length_, return _index_ + 1.
31018-
1. Let _first_ be the numeric value of the code unit at index _index_ within _S_.
31019-
1. If _first_ &lt; 0xD800 or _first_ &gt; 0xDBFF, return _index_ + 1.
31020-
1. Let _second_ be the numeric value of the code unit at index _index_ + 1 within _S_.
31021-
1. If _second_ &lt; 0xDC00 or _second_ &gt; 0xDFFF, return _index_ + 1.
31019+
1. Let _first_ be the code unit at index _index_ within _S_.
31020+
1. If _first_ is not a <emu-xref href="#leading-surrogate"></emu-xref>, return _index_ + 1.
31021+
1. Let _second_ be the code unit at index _index_ + 1 within _S_.
31022+
1. If _second_ is not a <emu-xref href="#trailing-surrogate"></emu-xref>, return _index_ + 1.
3102231023
1. Return _index_ + 2.
3102331024
</emu-alg>
3102431025
</emu-clause>

0 commit comments

Comments
 (0)