Skip to content

Commit

Permalink
Add $ERR_STREAM_RELEASE_LOCK
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Sep 12, 2024
1 parent 605f0db commit 5a1c29f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/bun.js/bindings/ErrorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default [
["ERR_ILLEGAL_CONSTRUCTOR", TypeError, "TypeError"],
["ERR_INVALID_URL", TypeError, "TypeError"],
["ERR_BUFFER_TOO_LARGE", RangeError, "RangeError"],
["ERR_STREAM_RELEASE_LOCK", Error, "AbortError"],

// Bun-specific
["ERR_FORMDATA_PARSE_ERROR", TypeError, "TypeError"],
Expand Down
9 changes: 6 additions & 3 deletions src/js/builtins/ReadableStreamInternals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,10 @@ export function isReadableStreamDisturbed(stream) {
$visibility = "Private";
export function readableStreamDefaultReaderRelease(reader) {
$readableStreamReaderGenericRelease(reader);
$readableStreamDefaultReaderErrorReadRequests(reader, $makeTypeError("releasing lock of reader"));
$readableStreamDefaultReaderErrorReadRequests(
reader,
$ERR_STREAM_RELEASE_LOCK("Stream reader cancelled via releaseLock()"),
);
}

$visibility = "Private";
Expand All @@ -1623,11 +1626,11 @@ export function readableStreamReaderGenericRelease(reader) {
if ($getByIdDirectPrivate($getByIdDirectPrivate(reader, "ownerReadableStream"), "state") === $streamReadable)
$getByIdDirectPrivate(reader, "closedPromiseCapability").reject.$call(
undefined,
$makeTypeError("releasing lock of reader whose stream is still in readable state"),
$ERR_STREAM_RELEASE_LOCK("Stream reader cancelled via releaseLock()"),
);
else
$putByIdDirectPrivate(reader, "closedPromiseCapability", {
promise: $newHandledRejectedPromise($makeTypeError("reader released lock")),
promise: $newHandledRejectedPromise($ERR_STREAM_RELEASE_LOCK("Stream reader cancelled via releaseLock()")),
});

const promise = $getByIdDirectPrivate(reader, "closedPromiseCapability").promise;
Expand Down
14 changes: 12 additions & 2 deletions test/js/web/streams/streams.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,18 @@ it("ReadableStream rejects pending reads when the lock is released", async () =>

let read = reader.read();
reader.releaseLock();
expect(read).rejects.toThrow("releasing lock of reader");
expect(reader.closed).rejects.toThrow("releasing lock of reader");
expect(read).rejects.toThrow(
expect.objectContaining({
name: "AbortError",
code: "ERR_STREAM_RELEASE_LOCK",
}),
);
expect(reader.closed).rejects.toThrow(
expect.objectContaining({
name: "AbortError",
code: "ERR_STREAM_RELEASE_LOCK",
}),
);

resolve();

Expand Down

0 comments on commit 5a1c29f

Please sign in to comment.