- From: Domenic Denicola <notifications@github.com>
- Date: Thu, 01 Jul 2021 15:47:58 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/streams/pull/1130/review/697705983@github.com>
@domenic commented on this pull request. @yutakahirano, can you take a look at the latest commit? I should also update the Fetch and Web Serial PRs to make sure this works well for them too. > + 1. If |byobRequest| is null, then return null. + 1. Return |byobRequest|.[=ReadableStreamBYOBRequest/[[view]]=]. +</div> + +<div algorithm> + To <dfn export for="ReadableStream">enqueue bytes</dfn> into a {{ReadableStream}} |stream| given an + {{ArrayBufferView}} |view|: + + 1. Assert: |stream|.[=ReadableStream/[[controller]]=] [=implements=] + {{ReadableByteStreamController}}. + 1. Let |byobRequest| be ! + [$ReadableByteStreamControllerGetBYOBRequest$](|stream|.[=ReadableStream/[[controller]]=]). + 1. If |byobRequest| is non-null, and |view|.\[[ViewedArrayBuffer]].\[[ArrayBufferData]] is the same + [=Data Block=] as |byobRequest|.\[[view]].\[[ViewedArrayBuffer]].\[[ArrayBufferData]], then: + 1. Assert: |view|.\[[ByteOffset]] is |byobRequest|.\[[view]].\[[ByteOffset]]. + 1. Assert: |view|.\[[ByteLength]] ≤ |byobRequest|.\[[view]].\[[ByteLength]]. I made these asserts instead of if tests (compared to https://github.com/w3c/webtransport/pull/297#discussion_r661130619) since it seems like it would be bad if the caller used the view but went past the requested bounds. > + 1. Assert: |stream|.[=ReadableStream/[[controller]]=] [=implements=] + {{ReadableByteStreamController}}. + 1. Let |byobRequest| be ! + [$ReadableByteStreamControllerGetBYOBRequest$](|stream|.[=ReadableStream/[[controller]]=]). + 1. If |byobRequest| is non-null, and |view|.\[[ViewedArrayBuffer]].\[[ArrayBufferData]] is the same + [=Data Block=] as |byobRequest|.\[[view]].\[[ViewedArrayBuffer]].\[[ArrayBufferData]], then: + 1. Assert: |view|.\[[ByteOffset]] is |byobRequest|.\[[view]].\[[ByteOffset]]. + 1. Assert: |view|.\[[ByteLength]] ≤ |byobRequest|.\[[view]].\[[ByteLength]]. + <p class="note">These asserts ensure that the caller does not write outside the requested + range in the [=ReadableStream/current BYOB request view=]. + 1. If |view|.\[[ViewedArrayBuffer]] equals |byobRequest|.\[[view]].\[[ViewedArrayBuffer]], then + perform ? [$ReadableByteStreamControllerRespond$](|stream|.[=ReadableStream/[[controller]]=], + |view|.\[[ByteLength]]). + 1. Otherwise, perform ? + [$ReadableByteStreamControllerRespondWithNewView$](|stream|.[=ReadableStream/[[controller]]=], + |view|). I handled the case where you transfer the backing Data Block here, which goes a bit beyond https://github.com/w3c/webtransport/pull/297#discussion_r661130619 but seems like a good idea. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/streams/pull/1130#pullrequestreview-697705983
Received on Thursday, 1 July 2021 22:48:10 UTC