Skip to content

Commit

Permalink
lib: set abort-controller toStringTag
Browse files Browse the repository at this point in the history
PR-URL: #36115
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
benjamingr authored and nodejs-github-bot committed Nov 19, 2020
1 parent 2097ffd commit d7bfa58
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/internal/abort_controller.js
Expand Up @@ -7,7 +7,9 @@ const {
ObjectAssign,
ObjectDefineProperties,
ObjectSetPrototypeOf,
ObjectDefineProperty,
Symbol,
SymbolToStringTag,
TypeError,
} = primordials;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-abortcontroller.js
Expand Up @@ -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]');
}
2 changes: 1 addition & 1 deletion test/parallel/test-eventtarget-memoryleakwarning.js
Expand Up @@ -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'],
],
Expand Down

0 comments on commit d7bfa58

Please sign in to comment.