-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: fix setting abort reason in
ReadableStream.pipeTo()
In 14.2 in the specification, `error` should be signal’s abort reason. The current behavior seems to assume that only an `AbortError` instance is given as signal’s abort reason. Refs: https://streams.spec.whatwg.org/#readable-stream-pipe-to Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com PR-URL: #44418 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
- Loading branch information
Showing
3 changed files
with
33 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('node:assert'); | ||
const { AbortError } = require('internal/errors'); | ||
|
||
// Purpose: pass an AbortError instance, which isn't the DOMException, as an | ||
// abort reason. | ||
|
||
for (const message of [undefined, 'abc']) { | ||
const rs = new ReadableStream(); | ||
const ws = new WritableStream(); | ||
const ac = new AbortController(); | ||
const reason = new AbortError(message); | ||
ac.abort(reason); | ||
|
||
assert.rejects(rs.pipeTo(ws, { signal: ac.signal }), (e) => { | ||
assert(e instanceof DOMException); | ||
assert.strictEqual(e.name, 'AbortError'); | ||
assert.strictEqual(e.message, reason.message); | ||
return true; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters