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 35570e9

Browse filesBrowse files
aduh95MylesBorins
authored andcommitted
lib: tighten AbortSignal.prototype.throwIfAborted implementation
PR-URL: #46521 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent f91260b commit 35570e9
Copy full SHA for 35570e9

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+20
-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
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ class AbortSignal extends EventTarget {
150150
}
151151

152152
throwIfAborted() {
153-
if (this.aborted) {
154-
throw this.reason;
153+
validateThisAbortSignal(this);
154+
if (this[kAborted]) {
155+
throw this[kReason];
155156
}
156157
}
157158

Collapse file

‎test/parallel/test-abortcontroller.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-abortcontroller.js
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,20 @@ const { setTimeout: sleep } = require('timers/promises');
254254
const ac = new AbortController();
255255
ac.signal.throwIfAborted();
256256
}
257+
258+
{
259+
const originalDesc = Reflect.getOwnPropertyDescriptor(AbortSignal.prototype, 'aborted');
260+
const actualReason = new Error();
261+
Reflect.defineProperty(AbortSignal.prototype, 'aborted', { value: false });
262+
throws(() => AbortSignal.abort(actualReason).throwIfAborted(), actualReason);
263+
Reflect.defineProperty(AbortSignal.prototype, 'aborted', originalDesc);
264+
}
265+
266+
{
267+
const originalDesc = Reflect.getOwnPropertyDescriptor(AbortSignal.prototype, 'reason');
268+
const actualReason = new Error();
269+
const fakeExcuse = new Error();
270+
Reflect.defineProperty(AbortSignal.prototype, 'reason', { value: fakeExcuse });
271+
throws(() => AbortSignal.abort(actualReason).throwIfAborted(), actualReason);
272+
Reflect.defineProperty(AbortSignal.prototype, 'reason', originalDesc);
273+
}

0 commit comments

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