Skip to content

Commit

Permalink
lib: set abort-controller toStringTag
Browse files Browse the repository at this point in the history
PR-URL: nodejs#36115
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
benjamingr authored and targos committed Apr 26, 2021
1 parent 89d15fe commit 4f6e727
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
const {
Object,
ObjectSetPrototypeOf,
ObjectDefineProperty,
Symbol,
SymbolToStringTag,
TypeError,
} = primordials;

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

0 comments on commit 4f6e727

Please sign in to comment.