@@ -30,6 +30,7 @@ const {
3030 customInspectSymbol,
3131 kEmptyObject,
3232 kEnumerableProperty,
33+ SideEffectFreeRegExpPrototypeSymbolReplace,
3334} = require ( 'internal/util' ) ;
3435const { inspect } = require ( 'internal/util/inspect' ) ;
3536const {
@@ -63,11 +64,14 @@ const {
6364
6465let _MessageChannel ;
6566let makeTransferable ;
67+ let defaultDOMException ;
6668
6769// Loading the MessageChannel and makeTransferable have to be done lazily
6870// because otherwise we'll end up with a require cycle that ends up with
6971// an incomplete initialization of abort_controller.
7072
73+ const userModuleRegExp = / ^ { 4 } a t (?: [ ^ / \\ ( ] + \( ) (? ! n o d e : ( .+ ) : \d + : \d + \) $ ) .* / gm;
74+
7175function lazyMessageChannel ( ) {
7276 _MessageChannel ??= require ( 'internal/worker/io' ) . MessageChannel ;
7377 return new _MessageChannel ( ) ;
@@ -79,6 +83,21 @@ function lazyMakeTransferable(obj) {
7983 return makeTransferable ( obj ) ;
8084}
8185
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+
82101const clearTimeoutRegistry = new SafeFinalizationRegistry ( clearTimeout ) ;
83102const timeOutSignals = new SafeSet ( ) ;
84103
@@ -166,8 +185,10 @@ class AbortSignal extends EventTarget {
166185 * @param {any } [reason]
167186 * @returns {AbortSignal }
168187 */
169- static abort (
170- reason = new DOMException ( 'This operation was aborted' , 'AbortError' ) ) {
188+ static abort ( reason ) {
189+ if ( reason === undefined ) {
190+ reason = lazyDOMException ( ) ;
191+ }
171192 return createAbortSignal ( { aborted : true , reason } ) ;
172193 }
173194
@@ -328,7 +349,10 @@ class AbortController {
328349 /**
329350 * @param {any } [reason]
330351 */
331- abort ( reason = new DOMException ( 'This operation was aborted' , 'AbortError' ) ) {
352+ abort ( reason ) {
353+ if ( reason === undefined ) {
354+ reason = lazyDOMException ( ) ;
355+ }
332356 abortSignal ( this . #signal ??= createAbortSignal ( ) , reason ) ;
333357 }
334358
0 commit comments