Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
22 changes: 15 additions & 7 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1885,13 +1885,7 @@ ReadableByteStreamController(<var>stream</var>, <var>underlyingByteSource</var>,

<emu-alg>
1. If IsReadableByteStreamController(*this*) is *false*, throw a *TypeError* exception.
1. If *this*.[[byobRequest]] is *undefined* and *this*.[[pendingPullIntos]] is not empty,
1. Let _firstDescriptor_ be the first element of *this*.[[pendingPullIntos]].
1. Let _view_ be ! Construct(<a idl>%Uint8Array%</a>, « _firstDescriptor_.[[buffer]],
_firstDescriptor_.[[byteOffset]] + _firstDescriptor_.[[bytesFilled]], _firstDescriptor_.[[byteLength]] −
_firstDescriptor_.[[bytesFilled]] »).
1. Set *this*.[[byobRequest]] to ! Construct(`<a idl>ReadableStreamBYOBRequest</a>`, « *this*, _view_ »).
1. Return *this*.[[byobRequest]].
1. Return ! ReadableByteStreamControllerGetBYOBRequest(*this*).
</emu-alg>

<h5 id="rbs-controller-desired-size" attribute for="ReadableByteStreamController" lt="desiredSize">get desiredSize</h5>
Expand Down Expand Up @@ -2285,6 +2279,20 @@ nothrow>ReadableByteStreamControllerFillPullIntoDescriptorFromQueue ( <var>contr
1. Return _ready_.
</emu-alg>

<h4 id="readable-byte-stream-controller-get-byob-request" aoid="ReadableByteStreamControllerGetBYOBRequest"
nothrow>ReadableByteStreamControllerGetBYOBRequest ( <var>controller</var> )</h4>

<emu-alg>
1. If _controller_.[[byobRequest]] is *undefined* and _controller_.[[pendingPullIntos]] is not empty,
1. Let _firstDescriptor_ be the first element of _controller_.[[pendingPullIntos]].
1. Let _view_ be ! Construct(<a idl>%Uint8Array%</a>, « _firstDescriptor_.[[buffer]],
_firstDescriptor_.[[byteOffset]] + _firstDescriptor_.[[bytesFilled]], _firstDescriptor_.[[byteLength]] −
_firstDescriptor_.[[bytesFilled]] »).
1. Set _controller_.[[byobRequest]] to ! Construct(`<a idl>ReadableStreamBYOBRequest</a>`,
« _controller_, _view_ »).
1. Return _controller_.[[byobRequest]].
</emu-alg>

<h4 id="readable-byte-stream-controller-get-desired-size" aoid="ReadableByteStreamControllerGetDesiredSize"
nothrow>ReadableByteStreamControllerGetDesiredSize ( <var>controller</var> )</h4>

Expand Down
24 changes: 14 additions & 10 deletions reference-implementation/lib/readable-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -1212,16 +1212,7 @@ class ReadableByteStreamController {
throw byteStreamControllerBrandCheckException('byobRequest');
}

if (this._byobRequest === undefined && this._pendingPullIntos.length > 0) {
const firstDescriptor = this._pendingPullIntos[0];
const view = new Uint8Array(firstDescriptor.buffer,
firstDescriptor.byteOffset + firstDescriptor.bytesFilled,
firstDescriptor.byteLength - firstDescriptor.bytesFilled);

this._byobRequest = new ReadableStreamBYOBRequest(this, view);
}

return this._byobRequest;
return ReadableByteStreamControllerGetBYOBRequest(this);
}

get desiredSize() {
Expand Down Expand Up @@ -1772,6 +1763,19 @@ function ReadableByteStreamControllerError(controller, e) {
ReadableStreamError(stream, e);
}

function ReadableByteStreamControllerGetBYOBRequest(controller) {
if (controller._byobRequest === undefined && controller._pendingPullIntos.length > 0) {
const firstDescriptor = controller._pendingPullIntos[0];
const view = new Uint8Array(firstDescriptor.buffer,
firstDescriptor.byteOffset + firstDescriptor.bytesFilled,
firstDescriptor.byteLength - firstDescriptor.bytesFilled);

controller._byobRequest = new ReadableStreamBYOBRequest(controller, view);
}

return controller._byobRequest;
}

function ReadableByteStreamControllerGetDesiredSize(controller) {
return controller._strategyHWM - controller._totalQueuedBytes;
}
Expand Down