File tree 3 files changed +33
-11
lines changed
3 files changed +33
-11
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ const {
28
28
} = primordials ;
29
29
30
30
const {
31
+ AbortError,
31
32
codes : {
32
33
ERR_ILLEGAL_CONSTRUCTOR ,
33
34
ERR_INVALID_ARG_VALUE ,
@@ -1303,8 +1304,14 @@ function readableStreamPipeTo(
1303
1304
}
1304
1305
1305
1306
function abortAlgorithm ( ) {
1306
- // Cannot use the AbortError class here. It must be a DOMException
1307
- const error = new DOMException ( 'The operation was aborted' , 'AbortError' ) ;
1307
+ let error ;
1308
+ if ( signal . reason instanceof AbortError ) {
1309
+ // Cannot use the AbortError class here. It must be a DOMException.
1310
+ error = new DOMException ( signal . reason . message , 'AbortError' ) ;
1311
+ } else {
1312
+ error = signal . reason ;
1313
+ }
1314
+
1308
1315
const actions = [ ] ;
1309
1316
if ( ! preventAbort ) {
1310
1317
ArrayPrototypePush (
Original file line number Diff line number Diff line change
1
+ // Flags: --expose-internals
2
+ 'use strict' ;
3
+
4
+ require ( '../common' ) ;
5
+ const assert = require ( 'node:assert' ) ;
6
+ const { AbortError } = require ( 'internal/errors' ) ;
7
+
8
+ // Purpose: pass an AbortError instance, which isn't the DOMException, as an
9
+ // abort reason.
10
+
11
+ for ( const message of [ undefined , 'abc' ] ) {
12
+ const rs = new ReadableStream ( ) ;
13
+ const ws = new WritableStream ( ) ;
14
+ const ac = new AbortController ( ) ;
15
+ const reason = new AbortError ( message ) ;
16
+ ac . abort ( reason ) ;
17
+
18
+ assert . rejects ( rs . pipeTo ( ws , { signal : ac . signal } ) , ( e ) => {
19
+ assert ( e instanceof DOMException ) ;
20
+ assert . strictEqual ( e . name , 'AbortError' ) ;
21
+ assert . strictEqual ( e . message , reason . message ) ;
22
+ return true ;
23
+ } ) ;
24
+ }
Original file line number Diff line number Diff line change 2
2
"piping/abort.any.js" : {
3
3
"fail" : {
4
4
"expected" : [
5
- " (reason: 'null') all the error objects should be the same object" ,
6
- " (reason: 'undefined') all the error objects should be the same object" ,
7
- " (reason: 'error1: error1') all the error objects should be the same object" ,
8
- " (reason: 'null') abort should prevent further reads" ,
9
- " (reason: 'undefined') abort should prevent further reads" ,
10
- " (reason: 'error1: error1') abort should prevent further reads" ,
11
- " (reason: 'null') all pending writes should complete on abort" ,
12
- " (reason: 'undefined') all pending writes should complete on abort" ,
13
- " (reason: 'error1: error1') all pending writes should complete on abort" ,
14
5
" pipeTo on a teed readable byte stream should only be aborted when both branches are aborted"
15
6
]
16
7
}
You can’t perform that action at this time.
0 commit comments