diff --git a/lib/internal/abort_controller.js b/lib/internal/abort_controller.js index 37001dc733982b..6ac0122637e09c 100644 --- a/lib/internal/abort_controller.js +++ b/lib/internal/abort_controller.js @@ -7,7 +7,9 @@ const { ObjectAssign, ObjectDefineProperties, ObjectSetPrototypeOf, + ObjectDefineProperty, Symbol, + SymbolToStringTag, TypeError, } = primordials; @@ -55,6 +57,13 @@ ObjectDefineProperties(AbortSignal.prototype, { aborted: { enumerable: true } }); +ObjectDefineProperty(AbortSignal.prototype, SymbolToStringTag, { + writable: false, + enumerable: false, + configurable: true, + value: 'AbortSignal', +}); + defineEventHandler(AbortSignal.prototype, 'abort'); function createAbortSignal() { @@ -98,6 +107,13 @@ ObjectDefineProperties(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 673a774ef148c3..283aaa93fc7fca 100644 --- a/test/parallel/test-abortcontroller.js +++ b/test/parallel/test-abortcontroller.js @@ -60,3 +60,10 @@ const { ok, strictEqual, throws } = require('assert'); /^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 bcd355c11b8d8d..5989f6cc7f86ab 100644 --- a/test/parallel/test-eventtarget-memoryleakwarning.js +++ b/test/parallel/test-eventtarget-memoryleakwarning.js @@ -21,7 +21,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'], ],