@@ -24,10 +24,10 @@ const {
24
24
validateObject,
25
25
} = require ( 'internal/validators' ) ;
26
26
27
- function cancelListenerHandler ( clear , reject ) {
27
+ function cancelListenerHandler ( clear , reject , signal ) {
28
28
if ( ! this . _destroyed ) {
29
29
clear ( this ) ;
30
- reject ( new AbortError ( ) ) ;
30
+ reject ( new AbortError ( undefined , { cause : signal ?. reason } ) ) ;
31
31
}
32
32
}
33
33
@@ -57,7 +57,7 @@ function setTimeout(after, value, options = {}) {
57
57
// to 12.x, then this can be converted to use optional chaining to
58
58
// simplify the check.
59
59
if ( signal && signal . aborted ) {
60
- return PromiseReject ( new AbortError ( ) ) ;
60
+ return PromiseReject ( new AbortError ( undefined , { cause : signal . reason } ) ) ;
61
61
}
62
62
let oncancel ;
63
63
const ret = new Promise ( ( resolve , reject ) => {
@@ -66,7 +66,7 @@ function setTimeout(after, value, options = {}) {
66
66
if ( signal ) {
67
67
oncancel = FunctionPrototypeBind ( cancelListenerHandler ,
68
68
// eslint-disable-next-line no-undef
69
- timeout , clearTimeout , reject ) ;
69
+ timeout , clearTimeout , reject , signal ) ;
70
70
signal . addEventListener ( 'abort' , oncancel ) ;
71
71
}
72
72
} ) ;
@@ -101,7 +101,7 @@ function setImmediate(value, options = {}) {
101
101
// to 12.x, then this can be converted to use optional chaining to
102
102
// simplify the check.
103
103
if ( signal && signal . aborted ) {
104
- return PromiseReject ( new AbortError ( ) ) ;
104
+ return PromiseReject ( new AbortError ( undefined , { cause : signal . reason } ) ) ;
105
105
}
106
106
let oncancel ;
107
107
const ret = new Promise ( ( resolve , reject ) => {
@@ -110,7 +110,8 @@ function setImmediate(value, options = {}) {
110
110
if ( signal ) {
111
111
oncancel = FunctionPrototypeBind ( cancelListenerHandler ,
112
112
// eslint-disable-next-line no-undef
113
- immediate , clearImmediate , reject ) ;
113
+ immediate , clearImmediate , reject ,
114
+ signal ) ;
114
115
signal . addEventListener ( 'abort' , oncancel ) ;
115
116
}
116
117
} ) ;
@@ -127,7 +128,7 @@ async function* setInterval(after, value, options = {}) {
127
128
validateBoolean ( ref , 'options.ref' ) ;
128
129
129
130
if ( signal ?. aborted )
130
- throw new AbortError ( ) ;
131
+ throw new AbortError ( undefined , { cause : signal ?. reason } ) ;
131
132
132
133
let onCancel ;
133
134
let interval ;
@@ -147,7 +148,9 @@ async function* setInterval(after, value, options = {}) {
147
148
// eslint-disable-next-line no-undef
148
149
clearInterval ( interval ) ;
149
150
if ( callback ) {
150
- callback ( PromiseReject ( new AbortError ( ) ) ) ;
151
+ callback (
152
+ PromiseReject (
153
+ new AbortError ( undefined , { cause : signal . reason } ) ) ) ;
151
154
callback = undefined ;
152
155
}
153
156
} ;
@@ -162,7 +165,7 @@ async function* setInterval(after, value, options = {}) {
162
165
yield value ;
163
166
}
164
167
}
165
- throw new AbortError ( ) ;
168
+ throw new AbortError ( undefined , { cause : signal ?. reason } ) ;
166
169
} finally {
167
170
// eslint-disable-next-line no-undef
168
171
clearInterval ( interval ) ;
0 commit comments