4
4
// in https://github.com/mysticatea/abort-controller (MIT license)
5
5
6
6
const {
7
+ ErrorCaptureStackTrace,
7
8
ObjectAssign,
8
9
ObjectDefineProperties,
9
10
ObjectSetPrototypeOf,
@@ -30,7 +31,6 @@ const {
30
31
customInspectSymbol,
31
32
kEmptyObject,
32
33
kEnumerableProperty,
33
- SideEffectFreeRegExpPrototypeSymbolReplace,
34
34
} = require ( 'internal/util' ) ;
35
35
const { inspect } = require ( 'internal/util/inspect' ) ;
36
36
const {
@@ -70,8 +70,6 @@ let defaultDOMException;
70
70
// because otherwise we'll end up with a require cycle that ends up with
71
71
// an incomplete initialization of abort_controller.
72
72
73
- const userModuleRegExp = / ^ { 4 } a t (?: [ ^ / \\ ( ] + \( ) (? ! n o d e : ( .+ ) : \d + : \d + \) $ ) .* / gm;
74
-
75
73
function lazyMessageChannel ( ) {
76
74
_MessageChannel ??= require ( 'internal/worker/io' ) . MessageChannel ;
77
75
return new _MessageChannel ( ) ;
@@ -90,11 +88,9 @@ function lazyDOMException() {
90
88
91
89
defaultDOMException = new DOMException ( 'This operation was aborted' , 'AbortError' ) ;
92
90
93
- // Avoid V8 leak and remove userland stackstrace
94
- defaultDOMException . stack = SideEffectFreeRegExpPrototypeSymbolReplace (
95
- userModuleRegExp ,
96
- defaultDOMException . stack ,
97
- '' ) ;
91
+ // Avoid V8 leak
92
+ // eslint-disable-next-line no-unused-vars
93
+ const dummy = defaultDOMException . stack ;
98
94
return defaultDOMException ;
99
95
}
100
96
@@ -185,9 +181,10 @@ class AbortSignal extends EventTarget {
185
181
* @param {any } [reason]
186
182
* @returns {AbortSignal }
187
183
*/
188
- static abort ( reason ) {
184
+ static abort ( reason = undefined ) {
189
185
if ( reason === undefined ) {
190
186
reason = lazyDOMException ( ) ;
187
+ ErrorCaptureStackTrace ( reason ) ;
191
188
}
192
189
return createAbortSignal ( { aborted : true , reason } ) ;
193
190
}
@@ -352,6 +349,7 @@ class AbortController {
352
349
abort ( reason ) {
353
350
if ( reason === undefined ) {
354
351
reason = lazyDOMException ( ) ;
352
+ ErrorCaptureStackTrace ( reason ) ;
355
353
}
356
354
abortSignal ( this . #signal ??= createAbortSignal ( ) , reason ) ;
357
355
}
0 commit comments