diff --git a/lib/internal/abort_controller.js b/lib/internal/abort_controller.js index f047a878ffedd0..a834b76b459227 100644 --- a/lib/internal/abort_controller.js +++ b/lib/internal/abort_controller.js @@ -6,7 +6,9 @@ const { Object, ObjectSetPrototypeOf, + ObjectDefineProperty, Symbol, + SymbolToStringTag, TypeError, } = primordials; @@ -54,6 +56,13 @@ Object.defineProperties(AbortSignal.prototype, { aborted: { enumerable: true } }); +ObjectDefineProperty(AbortSignal.prototype, SymbolToStringTag, { + writable: false, + enumerable: false, + configurable: true, + value: 'AbortSignal', +}); + defineEventHandler(AbortSignal.prototype, 'abort'); function createAbortSignal() { @@ -97,6 +106,13 @@ Object.defineProperties(AbortController.prototype, { abort: { enumerable: true } }); +ObjectDefineProperty(AbortController.prototype, SymbolToStringTag, { + writable: false, + enumerable: false, + configurable: true, + value: 'AbortController', +}); + module.exports = { AbortController, AbortSignal, diff --git a/test/parallel/test-abortcontroller.js b/test/parallel/test-abortcontroller.js index 3eba5fff051512..051b07ba389c2f 100644 --- a/test/parallel/test-abortcontroller.js +++ b/test/parallel/test-abortcontroller.js @@ -61,3 +61,10 @@ const { Event } = require('internal/event_target'); /^TypeError: Illegal constructor$/ ); } +{ + // Symbol.toStringTag + const toString = (o) => Object.prototype.toString.call(o); + const ac = new AbortController(); + strictEqual(toString(ac), '[object AbortController]'); + strictEqual(toString(ac.signal), '[object AbortSignal]'); +} diff --git a/test/parallel/test-eventtarget-memoryleakwarning.js b/test/parallel/test-eventtarget-memoryleakwarning.js index e6932320cf4b14..46c68b9979cfcb 100644 --- a/test/parallel/test-eventtarget-memoryleakwarning.js +++ b/test/parallel/test-eventtarget-memoryleakwarning.js @@ -23,7 +23,7 @@ common.expectWarning({ 'Use events.setMaxListeners() to increase ' + 'limit'], ['Possible EventTarget memory leak detected. 3 foo listeners added to ' + - '[AbortSignal [EventTarget]]. ' + + '[AbortSignal]. ' + 'Use events.setMaxListeners() to increase ' + 'limit'], ],