Skip to content
Merged
Changes from 2 commits
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
72 changes: 47 additions & 25 deletions encoding.bs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ Translate IDs: dictdef-textdecoderoptions textdecoderoptions,dictdef-textdecodeo
}
</pre>

<pre class=anchors>
urlPrefix: https://tc39.es/ecma262/#; spec: ECMA-262;
type: dfn
text: realm; url: realm
</pre>

<link rel=stylesheet href=visualization-colors.css>


Expand Down Expand Up @@ -234,8 +240,8 @@ items, in the given order, before the first item in the queue.
<a>byte sequence</a> <var>input</var> into an <a for=/>I/O queue</a>, run these steps:

<ol>
<li><p>Assert: if <var>input</var> is a <a for=/>list</a>, then it does not <a for=list>contain</a>
<a>end-of-queue</a>.
<li><p><a for=/>Assert</a>: <var>input</var> is not a <a for=/>list</a> or it does not
<a for=list>contain</a> <a>end-of-queue</a>.

<li><p>Return an <a for=/>I/O queue</a> containing the <a for=list>items</a> in <var>input</var>,
in order, followed by <a>end-of-queue</a>.
Expand All @@ -259,6 +265,21 @@ algorithms, as detailed in [[#implementation-considerations]].
0x10000 + ((<var>leading</var> &minus; 0xD800) &lt;&lt; 10) + (<var>trailing</var> &minus; 0xDC00).
</div>

<hr>

<div algorithm>
<p>To <dfn>create a <code>Uint8Array</code> object</dfn>, given an <a for=/>I/O queue</a>
<var>ioQueue</var> and a <a for=/>realm</a> <var>realm</var>:

<ol>
<li><p>Let <var>bytes</var> be the result of <a for="from I/O queue">converting</a>
<var>ioQueue</var> into a byte sequence.

<li><p>Return the result of <a for=ArrayBufferView>creating</a> a {{Uint8Array}} object from
<var>bytes</var> in <var>realm</var>.
</ol>
</div>



<h2 id=encodings>Encodings</h2>
Expand Down Expand Up @@ -332,14 +353,14 @@ given an <a for=list>item</a> <var>item</var>, <a for=/>encoding</a>'s <a for=/>
<a for=/>I/O queue</a> <var>output</var>, and <a for=/>error mode</a> <var>mode</var>:

<ol>
<li><p>Assert: if <var>encoderDecoder</var> is an <a for=/>encoder</a> instance, <var>mode</var> is
not "<code>replacement</code>".
<li><p><a for=/>Assert</a>: if <var>encoderDecoder</var> is an <a for=/>encoder</a> instance,
<var>mode</var> is not "<code>replacement</code>".

<li><p>Assert: if <var>encoderDecoder</var> is a <a for=/>decoder</a> instance, <var>mode</var> is
not "<code>html</code>".
<li><p><a for=/>Assert</a>: if <var>encoderDecoder</var> is a <a for=/>decoder</a> instance,
<var>mode</var> is not "<code>html</code>".

<li><p>Assert: if <var>encoderDecoder</var> is an <a for=/>encoder</a> instance, <var>item</var> is
not a <a>surrogate</a>.
<li><p><a for=/>Assert</a>: if <var>encoderDecoder</var> is an <a for=/>encoder</a> instance,
<var>item</var> is not a <a>surrogate</a>.

<li><p>Let <var>result</var> be the result of running <var>encoderDecoder</var>'s <a>handler</a> on
<var>input</var> and <var>item</var>.
Expand All @@ -358,8 +379,8 @@ given an <a for=list>item</a> <var>item</var>, <a for=/>encoding</a>'s <a for=/>
<p>Otherwise, if <var>result</var> is one or more <a for=list>items</a>:

<ol>
<li><p>Assert: if <var>encoderDecoder</var> is a <a for=/>decoder</a> instance, <var>result</var>
does not contain any <a>surrogates</a>.
<li><p><a for=/>Assert</a>: if <var>encoderDecoder</var> is a <a for=/>decoder</a> instance,
<var>result</var> does not contain any <a>surrogates</a>.

<li><p><a>Push</a> <var>result</var> to <var>output</var>.
</ol>
Expand Down Expand Up @@ -1216,7 +1237,7 @@ is safe as it never triggers <a>errors</a>. [[HTML]]
<a for=/>encoding</a> <var>encoding</var>:

<ol>
<li><p>Assert: <var>encoding</var> is not <a>replacement</a> or <a>UTF-16BE/LE</a>.
<li><p><a for=/>Assert</a>: <var>encoding</var> is not <a>replacement</a> or <a>UTF-16BE/LE</a>.

<li><p>Return an instance of <var>encoding</var>'s <a for=/>encoder</a>.
</ol>
Expand Down Expand Up @@ -1660,14 +1681,13 @@ constructor steps are to do nothing.
"<code>fatal</code>".

<li>
<p>Assert: <var>result</var> is not an <a>error</a>.
<p><a for=/>Assert</a>: <var>result</var> is not an <a>error</a>.

<p class=note>The <a>UTF-8 encoder</a> cannot return <a>error</a>.

<li><p>If <var>result</var> is <a>finished</a>, then <a for="from I/O queue">convert</a>
<var>output</var> into a byte sequence and return a {{Uint8Array}} object wrapping an
{{ArrayBuffer}} containing <var>output</var>.
<!-- XXX https://www.w3.org/Bugs/Public/show_bug.cgi?id=26966 -->
<li><p>If <var>result</var> is <a>finished</a>, then return the result of
<a>creating a <code>Uint8Array</code> object</a> given <var>output</var> and <a>this</a>'s
<a>relevant realm</a>.
</ol>
</ol>
</div>
Expand Down Expand Up @@ -1898,8 +1918,9 @@ constructor steps are:
<li><p>Let <var>outputChunk</var> be the result of running <a>serialize I/O queue</a> with
<var>decoder</var> and <var>output</var>.

<li><p>If <var>outputChunk</var> is non-empty, then <a for=TransformStream>enqueue</a>
<var>outputChunk</var> in <var>decoder</var>'s <a for=GenericTransformStream>transform</a>.
<li><p>If <var>outputChunk</var> is not the empty string, then
<a for=TransformStream>enqueue</a> <var>outputChunk</var> in <var>decoder</var>'s
<a for=GenericTransformStream>transform</a>.

<li><p>Return.
</ol>
Expand Down Expand Up @@ -1942,8 +1963,9 @@ steps:
<li><p>Let <var>outputChunk</var> be the result of running <a>serialize I/O queue</a> with
<var>decoder</var> and <var>output</var>.

<li><p>If <var>outputChunk</var> is non-empty, then <a for=TransformStream>enqueue</a>
<var>outputChunk</var> in <var>decoder</var>'s <a for=GenericTransformStream>transform</a>.
<li><p>If <var>outputChunk</var> is not the empty string, then
<a for=TransformStream>enqueue</a> <var>outputChunk</var> in <var>decoder</var>'s
<a for=GenericTransformStream>transform</a>.

<li><p>Return.
</ol>
Expand Down Expand Up @@ -2067,11 +2089,11 @@ constructor steps are:
<li><p><a for="from I/O queue">Convert</a> <var>output</var> into a byte sequence.

<li>
<p>If <var>output</var> is non-empty:
<p>If <var>output</var> <a for=list>is not empty</a>:

<ol>
<li><p>Let <var>chunk</var> be a {{Uint8Array}} object wrapping an {{ArrayBuffer}} containing
<var>output</var>.
<li><p>Let <var>chunk</var> be the result of <a>creating a <code>Uint8Array</code> object</a>
given <var>output</var> and <var>encoder</var>'s <a>relevant realm</a>.

<li><p><a for=TransformStream>Enqueue</a> <var>chunk</var> into <var>encoder</var>'s
<a for=GenericTransformStream>transform</a>.
Expand Down Expand Up @@ -2136,8 +2158,8 @@ that are split between strings. [[!INFRA]]

<ol>
<li>
<p>Let <var>chunk</var> be a {{Uint8Array}} object wrapping an {{ArrayBuffer}} containing
0xEF 0xBF 0xBD.
<p>Let <var>chunk</var> be the result of <a>creating a <code>Uint8Array</code> object</a> given
« 0xEF, 0xBF, 0xBD » and <var>encoder</var>'s <a>relevant realm</a>.

<p class=note>This is U+FFFD (�) in <a>UTF-8</a> bytes.

Expand Down