Skip to content

Commit

Permalink
Use new Web IDL constructs
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Jun 25, 2021
1 parent 7ab47e9 commit 157d374
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -6365,10 +6365,9 @@ The following algorithms must only be used on {{ReadableStream}} instances initi
1. Let |byobRequest| be !
[$ReadableByteStreamControllerGetBYOBRequest$](|stream|.[=ReadableStream/[[controller]]=]).
1. If |byobRequest| is null, then return null.
1. Return |byobRequest|.[=ReadableStreamBYOBRequest/[[view]]=].\[[ByteLength]].
1. Return |byobRequest|.[=ReadableStreamBYOBRequest/[[view]]=]'s [=BufferSource/byte length=].
</div>

<!-- TODO: use https://github.com/heycam/webidl/pull/987's "create" and "write" when they land. -->
<div algorithm>
To <dfn export for="ReadableStream">enqueue bytes</dfn> into a {{ReadableStream}} |stream| given a
[=byte sequence=] |bytes|:
Expand All @@ -6379,17 +6378,16 @@ The following algorithms must only be used on {{ReadableStream}} instances initi
1. Let |byobRequest| be !
[$ReadableByteStreamControllerGetBYOBRequest$](|stream|.[=ReadableStream/[[controller]]=]).
1. If |byobRequest| is null, or |bytes|'s [=byte sequence/length=] >
|byobRequest|.[=ReadableStreamBYOBRequest/[[view]]=].\[[ByteLength]], then:
1. Let |uint8Array| be a new {{Uint8Array}} wrapping an {{ArrayBuffer}} backed by |bytes|.
|byobRequest|.[=ReadableStreamBYOBRequest/[[view]]=]'s [=BufferSource/byte length=], then:
1. Let |uint8Array| be the result of [=ArrayBufferView/creating=] a new {{Uint8Array}} from
|bytes|.
1. Perform ! [$ReadableByteStreamControllerEnqueue$](|stream|.[=ReadableStream/[[controller]]=],
|uint8Array|).
1. Otherwise,
1. Assert: |bytes|'s [=byte sequence/length=] ≤
|byobRequest|.[=ReadableStreamBYOBRequest/[[view]]=].\[[ByteLength]].
1. Write |bytes| into
|byobRequest|.[=ReadableStreamBYOBRequest/[[view]]=].\[[ViewedArrayBuffer]].\[[ArrayBufferData]],
starting at the byte offset given by
|byobRequest|.[=ReadableStreamBYOBRequest/[[view]]=].\[[ByteOffset]].
|byobRequest|.[=ReadableStreamBYOBRequest/[[view]]=]'s [=BufferSource/byte length=].
1. [=ArrayBufferView/Write=] |bytes| into
|byobRequest|.[=ReadableStreamBYOBRequest/[[view]]=].

Implementations are encouraged to, when possible, do this directly from whatever underlying
I/O system is producing |bytes|. In this sense the existence of an intermediate |bytes|
Expand Down

0 comments on commit 157d374

Please sign in to comment.