forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
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 [email protected] PR-URL: nodejs#44418 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
- 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