Skip to content

Commit

Permalink
Fix bug with readable streams that have been detached (#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
Jarred-Sumner and Jarred-Sumner authored Nov 26, 2023
1 parent 22818e6 commit 5c23d67
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 5c23d67

Please sign in to comment.