Skip to content

Commit 4f6e727

Browse files
benjamingrtargos
authored andcommitted
lib: set abort-controller toStringTag
PR-URL: nodejs#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>
1 parent 89d15fe commit 4f6e727

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

lib/internal/abort_controller.js

+16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
const {
77
Object,
88
ObjectSetPrototypeOf,
9+
ObjectDefineProperty,
910
Symbol,
11+
SymbolToStringTag,
1012
TypeError,
1113
} = primordials;
1214

@@ -54,6 +56,13 @@ Object.defineProperties(AbortSignal.prototype, {
5456
aborted: { enumerable: true }
5557
});
5658

59+
ObjectDefineProperty(AbortSignal.prototype, SymbolToStringTag, {
60+
writable: false,
61+
enumerable: false,
62+
configurable: true,
63+
value: 'AbortSignal',
64+
});
65+
5766
defineEventHandler(AbortSignal.prototype, 'abort');
5867

5968
function createAbortSignal() {
@@ -97,6 +106,13 @@ Object.defineProperties(AbortController.prototype, {
97106
abort: { enumerable: true }
98107
});
99108

109+
ObjectDefineProperty(AbortController.prototype, SymbolToStringTag, {
110+
writable: false,
111+
enumerable: false,
112+
configurable: true,
113+
value: 'AbortController',
114+
});
115+
100116
module.exports = {
101117
AbortController,
102118
AbortSignal,

test/parallel/test-abortcontroller.js

+7
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ const { Event } = require('internal/event_target');
6161
/^TypeError: Illegal constructor$/
6262
);
6363
}
64+
{
65+
// Symbol.toStringTag
66+
const toString = (o) => Object.prototype.toString.call(o);
67+
const ac = new AbortController();
68+
strictEqual(toString(ac), '[object AbortController]');
69+
strictEqual(toString(ac.signal), '[object AbortSignal]');
70+
}

test/parallel/test-eventtarget-memoryleakwarning.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ common.expectWarning({
2323
'Use events.setMaxListeners() to increase ' +
2424
'limit'],
2525
['Possible EventTarget memory leak detected. 3 foo listeners added to ' +
26-
'[AbortSignal [EventTarget]]. ' +
26+
'[AbortSignal]. ' +
2727
'Use events.setMaxListeners() to increase ' +
2828
'limit'],
2929
],

0 commit comments

Comments
 (0)