Skip to content

Commit 2f2e812

Browse files
authored
Properly create Uint8Array objects
Also address a couple additional Infra nits I noticed along the way. Fixes #150 (finally) and helps with #334.
1 parent 5d723d2 commit 2f2e812

File tree

1 file changed

+41
-25
lines changed

1 file changed

+41
-25
lines changed

encoding.bs

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ items, in the given order, before the first item in the queue.
235235
<a>byte sequence</a> <var>input</var> into an <a for=/>I/O queue</a>, run these steps:
236236

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

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

263+
<hr>
264+
265+
<div algorithm>
266+
<p>To <dfn>create a <code>Uint8Array</code> object</dfn>, given an <a for=/>I/O queue</a>
267+
<var>ioQueue</var> and a <a for=ECMAScript>realm</a> <var>realm</var>:
268+
269+
<ol>
270+
<li><p>Let <var>bytes</var> be the result of <a for="from I/O queue">converting</a>
271+
<var>ioQueue</var> into a byte sequence.
272+
273+
<li><p>Return the result of <a for=ArrayBufferView>creating</a> a {{Uint8Array}} object from
274+
<var>bytes</var> in <var>realm</var>.
275+
</ol>
276+
</div>
277+
263278

264279

265280
<h2 id=encodings>Encodings</h2>
@@ -333,14 +348,14 @@ given an <a for=list>item</a> <var>item</var>, <a for=/>encoding</a>'s <a for=/>
333348
<a for=/>I/O queue</a> <var>output</var>, and <a for=/>error mode</a> <var>mode</var>:
334349

335350
<ol>
336-
<li><p>Assert: if <var>encoderDecoder</var> is an <a for=/>encoder</a> instance, <var>mode</var> is
337-
not "<code>replacement</code>".
351+
<li><p><a for=/>Assert</a>: <var>encoderDecoder</var> is not an <a for=/>encoder</a> instance or
352+
<var>mode</var> is not "<code>replacement</code>".
338353

339-
<li><p>Assert: if <var>encoderDecoder</var> is a <a for=/>decoder</a> instance, <var>mode</var> is
340-
not "<code>html</code>".
354+
<li><p><a for=/>Assert</a>: <var>encoderDecoder</var> is not a <a for=/>decoder</a> instance or
355+
<var>mode</var> is not "<code>html</code>".
341356

342-
<li><p>Assert: if <var>encoderDecoder</var> is an <a for=/>encoder</a> instance, <var>item</var> is
343-
not a <a>surrogate</a>.
357+
<li><p><a for=/>Assert</a>: <var>encoderDecoder</var> is not an <a for=/>encoder</a> instance or
358+
<var>item</var> is not a <a>surrogate</a>.
344359

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

361376
<ol>
362-
<li><p>Assert: if <var>encoderDecoder</var> is a <a for=/>decoder</a> instance, <var>result</var>
363-
does not contain any <a>surrogates</a>.
377+
<li><p><a for=/>Assert</a>: <var>encoderDecoder</var> is not a <a for=/>decoder</a> instance or
378+
<var>result</var> does not contain any <a>surrogates</a>.
364379

365380
<li><p><a>Push</a> <var>result</var> to <var>output</var>.
366381
</ol>
@@ -1216,7 +1231,7 @@ is safe as it never triggers <a>errors</a>. [[HTML]]
12161231
<a for=/>encoding</a> <var>encoding</var>:
12171232

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

12211236
<li><p>Return an instance of <var>encoding</var>'s <a for=/>encoder</a>.
12221237
</ol>
@@ -1660,14 +1675,13 @@ constructor steps are to do nothing.
16601675
"<code>fatal</code>".
16611676

16621677
<li>
1663-
<p>Assert: <var>result</var> is not an <a>error</a>.
1678+
<p><a for=/>Assert</a>: <var>result</var> is not an <a>error</a>.
16641679

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

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

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

19041919
<li><p>Return.
19051920
</ol>
@@ -1942,8 +1957,9 @@ steps:
19421957
<li><p>Let <var>outputChunk</var> be the result of running <a>serialize I/O queue</a> with
19431958
<var>decoder</var> and <var>output</var>.
19441959

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

19481964
<li><p>Return.
19491965
</ol>
@@ -2067,11 +2083,11 @@ constructor steps are:
20672083
<li><p><a for="from I/O queue">Convert</a> <var>output</var> into a byte sequence.
20682084

20692085
<li>
2070-
<p>If <var>output</var> is non-empty:
2086+
<p>If <var>output</var> <a for=list>is not empty</a>:
20712087

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

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

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

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

0 commit comments

Comments
 (0)