Skip to content

Commit 02de71a

Browse files
Discard auto-allocated BYOB request on enqueue
As discovered in #1170 (comment): if a BYOB request was auto-allocated, but then you call controller.enqueue() instead of byobRequest.respond(), then the auto-allocated pull-into descriptor stays in the queue. If you later on switch from a default reader to a BYOB reader, you run into trouble because the list of read-into requests no longer matches up with the list of pending pull-into descriptors. This PR fixes it by making enqueue() discard that auto-allocated BYOB request.
1 parent c079d53 commit 02de71a

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

index.bs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,10 +3137,17 @@ The following abstract operations support the implementation of the
31373137
1. Perform ! [$ReadableByteStreamControllerInvalidateBYOBRequest$](|controller|).
31383138
1. If ! [$ReadableStreamHasDefaultReader$](|stream|) is true
31393139
1. If ! [$ReadableStreamGetNumReadRequests$](|stream|) is 0,
3140+
1. Assert: |controller|.[=ReadableByteStreamController/[[pendingPullIntos]]=] is
3141+
[=list/is empty|empty=].
31403142
1. Perform ! [$ReadableByteStreamControllerEnqueueChunkToQueue$](|controller|,
31413143
|transferredBuffer|, |byteOffset|, |byteLength|).
31423144
1. Otherwise,
31433145
1. Assert: |controller|.[=ReadableByteStreamController/[[queue]]=] [=list/is empty=].
3146+
1. If |controller|.[=ReadableByteStreamController/[[pendingPullIntos]]=] is not
3147+
[=list/is empty|empty=],
3148+
1. Assert: |controller|.[=ReadableByteStreamController/[[pendingPullIntos]]=][0]'s [=pull-into
3149+
descriptor/reader type=] is "`default`".
3150+
1. Perform ! [$ReadableByteStreamControllerShiftPendingPullInto$](|controller|).
31443151
1. Let |transferredView| be ! [$Construct$]({{%Uint8Array%}}, « |transferredBuffer|,
31453152
|byteOffset|, |byteLength| »).
31463153
1. Perform ! [$ReadableStreamFulfillReadRequest$](|stream|, |transferredView|, false).

reference-implementation/lib/abstract-ops/readable-streams.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,10 +1289,14 @@ function ReadableByteStreamControllerEnqueue(controller, chunk) {
12891289

12901290
if (ReadableStreamHasDefaultReader(stream) === true) {
12911291
if (ReadableStreamGetNumReadRequests(stream) === 0) {
1292+
assert(controller._pendingPullIntos.length === 0);
12921293
ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength);
12931294
} else {
12941295
assert(controller._queue.length === 0);
1295-
1296+
if (controller._pendingPullIntos.length > 0) {
1297+
assert(controller._pendingPullIntos[0].readerType === 'default');
1298+
ReadableByteStreamControllerShiftPendingPullInto(controller);
1299+
}
12961300
const transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength);
12971301
ReadableStreamFulfillReadRequest(stream, transferredView, false);
12981302
}

0 commit comments

Comments
 (0)