Skip to content

Commit

Permalink
Rename minimumFill to min in ReadableStreamBYOBReaderRead, and make r…
Browse files Browse the repository at this point in the history
…equired
  • Loading branch information
MattiasBuelens committed Sep 16, 2023
1 parent 8f2e4a4 commit d17aeca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 34 deletions.
23 changes: 6 additions & 17 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,20 +1453,14 @@ value: newViewOnSameMemory, done: true }</code> for closed streams. If the strea
with=] a {{TypeError}} exception.
1. If ! [$IsDetachedBuffer$](|view|.\[[ViewedArrayBuffer]]) is true, return
[=a promise rejected with=] a {{TypeError}} exception.
1. Let |minimumFill| be undefined.
1. If |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] is 0, return [=a promise
rejected with=] a {{TypeError}} exception.
1. If |view| has a \[[TypedArrayName]] internal slot,
1. If |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] &gt; |view|.\[[ArrayLength]],
return [=a promise rejected with=] a {{RangeError}} exception.
1. Let |elementSize| be the element size specified in [=the typed array constructors table=] for
|view|.\[[TypedArrayName]].
1. Set |minimumFill| to |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] *
|elementSize|.
1. Otherwise (i.e., it is a {{DataView}}),
1. If |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"] &gt; |view|.\[[ByteLength]],
return [=a promise rejected with=] a {{RangeError}} exception.
1. Set |minimumFill| to |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"].
1. If [=this=].[=ReadableStreamGenericReader/[[stream]]=] is undefined, return [=a promise rejected
with=] a {{TypeError}} exception.
1. Let |promise| be [=a new promise=].
Expand All @@ -1482,7 +1476,7 @@ value: newViewOnSameMemory, done: true }</code> for closed streams. If the strea
: [=read-into request/error steps=], given |e|
::
1. [=Reject=] |promise| with |e|.
1. Perform ! [$ReadableStreamBYOBReaderRead$]([=this=], |view|, |readIntoRequest|, |minimumFill|).
1. Perform ! [$ReadableStreamBYOBReaderRead$]([=this=], |view|, |readIntoRequest|, |options|["{{ReadableStreamBYOBReaderReadOptions/min}}"]).
1. Return |promise|.
</div>

Expand Down Expand Up @@ -2587,7 +2581,7 @@ create them does not matter.
: [=read-into request/error steps=]
::
1. Set |reading| to false.
1. Perform ! [$ReadableStreamBYOBReaderRead$](|reader|, |view|, |readIntoRequest|).
1. Perform ! [$ReadableStreamBYOBReaderRead$](|reader|, |view|, |readIntoRequest|, 1).
1. Let |pull1Algorithm| be the following steps:
1. If |reading| is true,
1. Set |readAgainForBranch1| to true.
Expand Down Expand Up @@ -2888,21 +2882,15 @@ The following abstract operations support the implementation and manipulation of
<div algorithm>
<dfn abstract-op lt="ReadableStreamBYOBReaderRead"
id="readable-stream-byob-reader-read">ReadableStreamBYOBReaderRead(|reader|, |view|,
|readIntoRequest|[, |minimumFill|])</dfn> performs the following steps:
|readIntoRequest|, |min|)</dfn> performs the following steps:

1. Let |stream| be |reader|.[=ReadableStreamGenericReader/[[stream]]=].
1. Assert: |stream| is not undefined.
1. Set |stream|.[=ReadableStream/[[disturbed]]=] to true.
1. If |minimumFill| was not given,
1. Let |elementSize| be 1.
1. If |view| has a \[[TypedArrayName]] internal slot (i.e., it is not a {{DataView}}), set
|elementSize| to the element size specified in [=the typed array constructors table=] for
|view|.\[[TypedArrayName]].
1. Set |minimumFill| to |elementSize|.
1. If |stream|.[=ReadableStream/[[state]]=] is "`errored`", perform |readIntoRequest|'s [=read-into
request/error steps=] given |stream|.[=ReadableStream/[[storedError]]=].
1. Otherwise, perform ! [$ReadableByteStreamControllerPullInto$](|stream|.[=ReadableStream/[[controller]]=],
|view|, |readIntoRequest|, |minimumFill|).
|view|, |readIntoRequest|, |min|).
</div>

<div algorithm>
Expand Down Expand Up @@ -3582,7 +3570,7 @@ The following abstract operations support the implementation of the
<div algorithm>
<dfn abstract-op lt="ReadableByteStreamControllerPullInto"
id="readable-byte-stream-controller-pull-into">ReadableByteStreamControllerPullInto(|controller|,
|view|, |readIntoRequest|, |minimumFill|)</dfn> performs the following steps:
|view|, |readIntoRequest|, |min|)</dfn> performs the following steps:

1. Let |stream| be |controller|.[=ReadableByteStreamController/[[stream]]=].
1. Let |elementSize| be 1.
Expand All @@ -3592,6 +3580,7 @@ The following abstract operations support the implementation of the
|view|.\[[TypedArrayName]].
1. Set |ctor| to the constructor specified in [=the typed array constructors table=] for
|view|.\[[TypedArrayName]].
1. Let |minimumFill| be |min| * |elementSize|.
1. Assert: |minimumFill| ≥ 0 and |minimumFill| ≤ |view|.\[[ByteLength]].
1. Assert: |minimumFill| mod |elementSize| is 0.
1. Let |byteOffset| be |view|.\[[ByteOffset]].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class ReadableStreamBYOBReaderImpl {
return promiseRejectedWith(new TypeError('view\'s buffer has been detached'));
}

let minimumFill;
if (options.min === 0) {
return promiseRejectedWith(
new TypeError('options.min must be greater than 0')
Expand All @@ -34,15 +33,12 @@ class ReadableStreamBYOBReaderImpl {
new RangeError('options.min must be less than or equal to view\'s length')
);
}
const elementSize = view.constructor.BYTES_PER_ELEMENT;
minimumFill = options.min * elementSize;
} else {
if (options.min > view.byteLength) {
return promiseRejectedWith(
new RangeError('options.min must be less than or equal to view\'s byteLength')
);
}
minimumFill = options.min;
}

if (this._stream === undefined) {
Expand All @@ -55,7 +51,7 @@ class ReadableStreamBYOBReaderImpl {
closeSteps: chunk => resolvePromise(promise, { value: chunk, done: true }),
errorSteps: e => rejectPromise(promise, e)
};
aos.ReadableStreamBYOBReaderRead(this, view, readIntoRequest, minimumFill);
aos.ReadableStreamBYOBReaderRead(this, view, readIntoRequest, options.min);
return promise;
}

Expand Down
17 changes: 5 additions & 12 deletions reference-implementation/lib/abstract-ops/readable-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ function ReadableByteStreamTee(stream) {
reading = false;
}
};
ReadableStreamBYOBReaderRead(reader, view, readIntoRequest);
ReadableStreamBYOBReaderRead(reader, view, readIntoRequest, 1);
}

function pull1Algorithm() {
Expand Down Expand Up @@ -913,25 +913,17 @@ function ReadableStreamReaderGenericRelease(reader) {
reader._stream = undefined;
}

function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest, minimumFill) {
function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest, min) {
const stream = reader._stream;

assert(stream !== undefined);

stream._disturbed = true;

if (minimumFill === undefined) {
let elementSize = 1;
if (view.constructor !== DataView) {
elementSize = view.constructor.BYTES_PER_ELEMENT;
}
minimumFill = elementSize;
}

if (stream._state === 'errored') {
readIntoRequest.errorSteps(stream._storedError);
} else {
ReadableByteStreamControllerPullInto(stream._controller, view, readIntoRequest, minimumFill);
ReadableByteStreamControllerPullInto(stream._controller, view, readIntoRequest, min);
}
}

Expand Down Expand Up @@ -1570,14 +1562,15 @@ function ReadableByteStreamControllerProcessReadRequestsUsingQueue(controller) {
}
}

function ReadableByteStreamControllerPullInto(controller, view, readIntoRequest, minimumFill) {
function ReadableByteStreamControllerPullInto(controller, view, readIntoRequest, min) {
const stream = controller._stream;

let elementSize = 1;
if (view.constructor !== DataView) {
elementSize = view.constructor.BYTES_PER_ELEMENT;
}

const minimumFill = min * elementSize;
assert(minimumFill >= elementSize && minimumFill <= view.byteLength);
assert(minimumFill % elementSize === 0);

Expand Down

0 comments on commit d17aeca

Please sign in to comment.