Skip to content

Commit

Permalink
fixes #13: add String.prototype.toWellFormed
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra committed Aug 26, 2022
1 parent f4de5a8 commit 2696882
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,25 @@ <h1>String.prototype.isWellFormed ( )</h1>
1. Return IsStringWellFormedUnicode(_S_).
</emu-alg>
</emu-clause>

<emu-clause number="11" id="sec-string.prototype.towellformed">
<h1>String.prototype.toWellFormed ( )</h1>
<p>This method returns a String representation of this object with all leading surrogates and trailing surrogates that are not part of a surrogate pair replaced with U+FFFD (REPLACEMENT CHARACTER).</p>
<p>It performs the following steps when called:</p>
<emu-alg>
1. Let _O_ be ? RequireObjectCoercible(*this* value).
1. Let _S_ be ? ToString(_O_).
1. Let _strLen_ be the length of _S_.
1. Let _k_ be 0.
1. Let _result_ be the empty String.
1. Repeat, while _k_ &lt; _strLen_,
1. Let _cp_ be CodePointAt(_S_, _k_).
1. If _cp_.[[IsUnpairedSurrogate]] is *true*, then
1. Append 0xFFFD (REPLACEMENT CHARACTER) to _result_.
1. Else,
1. Set _result_ to the string-concatenation of _result_ and UTF16EncodeCodePoint(_cp_.[[CodePoint]]).
1. Set _k_ to _k_ + _cp_.[[CodeUnitCount]].
1. Return _result_.
</emu-alg>
</emu-clause>
</emu-clause>

0 comments on commit 2696882

Please sign in to comment.