Skip to content

Commit d6ea12e

Browse files
benjamingrcodebytere
authored andcommittedNov 22, 2020
lib: set abort-controller toStringTag
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>
1 parent 8390f8a commit d6ea12e

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
@@ -7,7 +7,9 @@ const {
77
ObjectAssign,
88
ObjectDefineProperties,
99
ObjectSetPrototypeOf,
10+
ObjectDefineProperty,
1011
Symbol,
12+
SymbolToStringTag,
1113
TypeError,
1214
} = primordials;
1315

@@ -55,6 +57,13 @@ ObjectDefineProperties(AbortSignal.prototype, {
5557
aborted: { enumerable: true }
5658
});
5759

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

6069
function createAbortSignal() {
@@ -98,6 +107,13 @@ ObjectDefineProperties(AbortController.prototype, {
98107
abort: { enumerable: true }
99108
});
100109

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

‎test/parallel/test-abortcontroller.js

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

‎test/parallel/test-eventtarget-memoryleakwarning.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ common.expectWarning({
2121
'Use events.setMaxListeners() to increase ' +
2222
'limit'],
2323
['Possible EventTarget memory leak detected. 3 foo listeners added to ' +
24-
'[AbortSignal [EventTarget]]. ' +
24+
'[AbortSignal]. ' +
2525
'Use events.setMaxListeners() to increase ' +
2626
'limit'],
2727
],

0 commit comments

Comments
 (0)
Please sign in to comment.