Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1550073

Browse filesBrowse files
RaisinTencodebytere
authored andcommitted
events: disabled manual construction AbortSignal
Fixes: #36064 PR-URL: #36094 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent f7b2fce commit 1550073
Copy full SHA for 1550073

File tree

Expand file treeCollapse file tree

2 files changed

+25
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+25
-2
lines changed
Open diff view settings
Collapse file

‎lib/internal/abort_controller.js‎

Copy file name to clipboardExpand all lines: lib/internal/abort_controller.js
+15-1Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
const {
77
ObjectAssign,
88
ObjectDefineProperties,
9+
ObjectSetPrototypeOf,
910
Symbol,
11+
TypeError,
1012
} = primordials;
1113

1214
const {
@@ -35,6 +37,11 @@ function customInspect(self, obj, depth, options) {
3537
}
3638

3739
class AbortSignal extends EventTarget {
40+
constructor() {
41+
// eslint-disable-next-line no-restricted-syntax
42+
throw new TypeError('Illegal constructor');
43+
}
44+
3845
get aborted() { return !!this[kAborted]; }
3946

4047
[customInspectSymbol](depth, options) {
@@ -50,6 +57,13 @@ ObjectDefineProperties(AbortSignal.prototype, {
5057

5158
defineEventHandler(AbortSignal.prototype, 'abort');
5259

60+
function createAbortSignal() {
61+
const signal = new EventTarget();
62+
ObjectSetPrototypeOf(signal, AbortSignal.prototype);
63+
signal[kAborted] = false;
64+
return signal;
65+
}
66+
5367
function abortSignal(signal) {
5468
if (signal[kAborted]) return;
5569
signal[kAborted] = true;
@@ -65,7 +79,7 @@ function abortSignal(signal) {
6579
const kSignal = Symbol('signal');
6680
class AbortController {
6781
constructor() {
68-
this[kSignal] = new AbortSignal();
82+
this[kSignal] = createAbortSignal();
6983
emitExperimentalWarning('AbortController');
7084
}
7185

Collapse file

‎test/parallel/test-abortcontroller.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-abortcontroller.js
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
const common = require('../common');
55

6-
const { ok, strictEqual } = require('assert');
6+
const { ok, strictEqual, throws } = require('assert');
77

88
{
99
// Tests that abort is fired with the correct event type on AbortControllers
@@ -51,3 +51,12 @@ const { ok, strictEqual } = require('assert');
5151
strictEqual(firstTrusted, secondTrusted);
5252
strictEqual(untrusted, firstTrusted);
5353
}
54+
55+
{
56+
// Tests that AbortSignal is impossible to construct manually
57+
const ac = new AbortController();
58+
throws(
59+
() => new ac.signal.constructor(),
60+
/^TypeError: Illegal constructor$/
61+
);
62+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.