- <emu-alg><ol><li>If <var>cp</var> is matched by <emu-nt id="_ref_23671"><a href="text-processing.html#prod-SyntaxCharacter">SyntaxCharacter</a></emu-nt> or <var>cp</var> is U+002F (SOLIDUS), then<ol><li>Return the <emu-xref href="#string-concatenation" id="_ref_11840"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of 0x005C (REVERSE SOLIDUS) and <emu-xref aoid="UTF16EncodeCodePoint" id="_ref_11841"><a href="ecmascript-language-source-code.html#sec-utf16encodecodepoint">UTF16EncodeCodePoint</a></emu-xref>(<var>cp</var>).</li></ol></li><li>Else if <var>cp</var> is a code point listed in the “Code Point” column of <emu-xref href="#table-controlescape-code-point-values" id="_ref_698"><a href="text-processing.html#table-controlescape-code-point-values">Table 67</a></emu-xref>, then<ol><li>Return the <emu-xref href="#string-concatenation" id="_ref_11842"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of 0x005C (REVERSE SOLIDUS) and the string in the “ControlEscape” column of the row whose “Code Point” column contains <var>c</var>.</li></ol></li><li>Let <var>otherPunctuators</var> be the <emu-xref href="#string-concatenation" id="_ref_11843"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of <emu-val>",-=<>#&!%:;@~'`"</emu-val> and the code unit 0x0022 (QUOTATION MARK).</li><li>Let <var>toEscape</var> be <emu-xref aoid="StringToCodePoints" id="_ref_11844"><a href="ecmascript-language-source-code.html#sec-stringtocodepoints">StringToCodePoints</a></emu-xref>(<var>otherPunctuators</var>).</li><li>If <var>toEscape</var> contains <var>cp</var>, <var>cp</var> is matched by either <emu-nt id="_ref_23672"><a href="ecmascript-language-lexical-grammar.html#prod-WhiteSpace">WhiteSpace</a></emu-nt> or <emu-nt id="_ref_23673"><a href="ecmascript-language-lexical-grammar.html#prod-LineTerminator">LineTerminator</a></emu-nt>, or <var>cp</var> has the same numeric value as a <emu-xref href="#leading-surrogate" id="_ref_11845"><a href="ecmascript-data-types-and-values.html#leading-surrogate">leading surrogate</a></emu-xref> or <emu-xref href="#trailing-surrogate" id="_ref_11846"><a href="ecmascript-data-types-and-values.html#trailing-surrogate">trailing surrogate</a></emu-xref>, then<ol><li>Let <var>cpNum</var> be the numeric value of <var>cp</var>.</li><li>If <var>cpNum</var> ≤ 0xFF, then<ol><li>Let <var>hex</var> be <emu-xref aoid="Number::toString" id="_ref_11847"><a href="ecmascript-data-types-and-values.html#sec-numeric-types-number-tostring">Number::toString</a></emu-xref>(<emu-xref aoid="𝔽" id="_ref_11848"><a href="notational-conventions.html#%F0%9D%94%BD">𝔽</a></emu-xref>(<var>cpNum</var>), 16).</li><li>Return the <emu-xref href="#string-concatenation" id="_ref_11849"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of the code unit 0x005C (REVERSE SOLIDUS), <emu-val>"x"</emu-val>, and <emu-xref aoid="StringPad" id="_ref_11850"><a href="text-processing.html#sec-stringpad">StringPad</a></emu-xref>(<var>hex</var>, 2, <emu-val>"0"</emu-val>, <emu-const>start</emu-const>).</li></ol></li><li>Let <var>escaped</var> be the empty String.</li><li>Let <var>codeUnits</var> be <emu-xref aoid="UTF16EncodeCodePoint" id="_ref_11851"><a href="ecmascript-language-source-code.html#sec-utf16encodecodepoint">UTF16EncodeCodePoint</a></emu-xref>(<var>cp</var>).</li><li>For each code unit <var>cu</var> of <var>codeUnits</var>, do<ol><li>Set <var>escaped</var> to the <emu-xref href="#string-concatenation" id="_ref_11852"><a href="ecmascript-data-types-and-values.html#string-concatenation">string-concatenation</a></emu-xref> of <var>escaped</var> and <emu-xref aoid="UnicodeEscape" id="_ref_11853"><a href="structured-data.html#sec-unicodeescape">UnicodeEscape</a></emu-xref>(<var>cu</var>).</li></ol></li><li>Return <var>escaped</var>.</li></ol></li><li>Return <emu-xref aoid="UTF16EncodeCodePoint" id="_ref_11854"><a href="ecmascript-language-source-code.html#sec-utf16encodecodepoint">UTF16EncodeCodePoint</a></emu-xref>(<var>cp</var>).</li></ol></emu-alg>
0 commit comments