Skip to content

Commit

Permalink
Fix bug with readable streams that have been detached (oven-sh#7308)
Browse files Browse the repository at this point in the history
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
  • Loading branch information
2 people authored and ryoppippi committed Feb 1, 2024
1 parent 1d1f1c0 commit 15f6461
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/js/builtins/ReadableStreamInternals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1259,10 +1259,11 @@ export function readableStreamError(stream, error) {
}

export function readableStreamDefaultControllerShouldCallPull(controller) {
const stream = $getByIdDirectPrivate(controller, "controlledReadableStream");

if (!$readableStreamDefaultControllerCanCloseOrEnqueue(controller)) return false;
if (!($getByIdDirectPrivate(controller, "started") === 1)) return false;

const stream = $getByIdDirectPrivate(controller, "controlledReadableStream");

if (
(!$isReadableStreamLocked(stream) ||
!$getByIdDirectPrivate($getByIdDirectPrivate(stream, "reader"), "readRequests")?.isNotEmpty()) &&
Expand Down Expand Up @@ -1482,10 +1483,17 @@ export function readableStreamReaderGenericRelease(reader) {
}

export function readableStreamDefaultControllerCanCloseOrEnqueue(controller) {
return (
!$getByIdDirectPrivate(controller, "closeRequested") &&
$getByIdDirectPrivate($getByIdDirectPrivate(controller, "controlledReadableStream"), "state") === $streamReadable
);
if ($getByIdDirectPrivate(controller, "closeRequested")) {
return false;
}

const controlledReadableStream = $getByIdDirectPrivate(controller, "controlledReadableStream");

if (!$isObject(controlledReadableStream)) {
return false;
}

return $getByIdDirectPrivate(controlledReadableStream, "state") === $streamReadable;
}

export function lazyLoadStream(stream, autoAllocateChunkSize) {
Expand Down

0 comments on commit 15f6461

Please sign in to comment.