@@ -30,6 +30,7 @@ const {
30
30
customInspectSymbol,
31
31
kEmptyObject,
32
32
kEnumerableProperty,
33
+ SideEffectFreeRegExpPrototypeSymbolReplace,
33
34
} = require ( 'internal/util' ) ;
34
35
const { inspect } = require ( 'internal/util/inspect' ) ;
35
36
const {
@@ -63,11 +64,14 @@ const {
63
64
64
65
let _MessageChannel ;
65
66
let makeTransferable ;
67
+ let defaultDOMException ;
66
68
67
69
// Loading the MessageChannel and makeTransferable have to be done lazily
68
70
// because otherwise we'll end up with a require cycle that ends up with
69
71
// an incomplete initialization of abort_controller.
70
72
73
+ const userModuleRegExp = / ^ { 4 } a t (?: [ ^ / \\ ( ] + \( ) (? ! n o d e : ( .+ ) : \d + : \d + \) $ ) .* / gm;
74
+
71
75
function lazyMessageChannel ( ) {
72
76
_MessageChannel ??= require ( 'internal/worker/io' ) . MessageChannel ;
73
77
return new _MessageChannel ( ) ;
@@ -79,6 +83,21 @@ function lazyMakeTransferable(obj) {
79
83
return makeTransferable ( obj ) ;
80
84
}
81
85
86
+ function lazyDOMException ( ) {
87
+ if ( defaultDOMException ) {
88
+ return defaultDOMException ;
89
+ }
90
+
91
+ defaultDOMException = new DOMException ( 'This operation was aborted' , 'AbortError' ) ;
92
+
93
+ // Avoid V8 leak and remove userland stackstrace
94
+ defaultDOMException . stack = SideEffectFreeRegExpPrototypeSymbolReplace (
95
+ userModuleRegExp ,
96
+ defaultDOMException . stack ,
97
+ '' ) ;
98
+ return defaultDOMException ;
99
+ }
100
+
82
101
const clearTimeoutRegistry = new SafeFinalizationRegistry ( clearTimeout ) ;
83
102
const timeOutSignals = new SafeSet ( ) ;
84
103
@@ -166,8 +185,10 @@ class AbortSignal extends EventTarget {
166
185
* @param {any } [reason]
167
186
* @returns {AbortSignal }
168
187
*/
169
- static abort (
170
- reason = new DOMException ( 'This operation was aborted' , 'AbortError' ) ) {
188
+ static abort ( reason ) {
189
+ if ( reason === undefined ) {
190
+ reason = lazyDOMException ( ) ;
191
+ }
171
192
return createAbortSignal ( { aborted : true , reason } ) ;
172
193
}
173
194
@@ -328,7 +349,10 @@ class AbortController {
328
349
/**
329
350
* @param {any } [reason]
330
351
*/
331
- abort ( reason = new DOMException ( 'This operation was aborted' , 'AbortError' ) ) {
352
+ abort ( reason ) {
353
+ if ( reason === undefined ) {
354
+ reason = lazyDOMException ( ) ;
355
+ }
332
356
abortSignal ( this . #signal ??= createAbortSignal ( ) , reason ) ;
333
357
}
334
358
0 commit comments