Skip to content

Commit 29b5236

Browse files
benjamingrdanielleadams
authored andcommitted
timers: reject with AbortError on cancellation
PR-URL: #36317 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
1 parent 4127eb2 commit 29b5236

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

lib/timers/promises.js

+4-14
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,14 @@ const {
1414
} = require('internal/timers');
1515

1616
const {
17-
hideStackFrames,
17+
AbortError,
1818
codes: { ERR_INVALID_ARG_TYPE }
1919
} = require('internal/errors');
2020

21-
let DOMException;
22-
23-
const lazyDOMException = hideStackFrames((message, name) => {
24-
if (DOMException === undefined)
25-
DOMException = internalBinding('messaging').DOMException;
26-
return new DOMException(message, name);
27-
});
28-
2921
function cancelListenerHandler(clear, reject) {
3022
if (!this._destroyed) {
3123
clear(this);
32-
reject(lazyDOMException('The operation was aborted', 'AbortError'));
24+
reject(new AbortError());
3325
}
3426
}
3527

@@ -64,8 +56,7 @@ function setTimeout(after, value, options = {}) {
6456
// to 12.x, then this can be converted to use optional chaining to
6557
// simplify the check.
6658
if (signal && signal.aborted) {
67-
return PromiseReject(
68-
lazyDOMException('The operation was aborted', 'AbortError'));
59+
return PromiseReject(new AbortError());
6960
}
7061
let oncancel;
7162
const ret = new Promise((resolve, reject) => {
@@ -115,8 +106,7 @@ function setImmediate(value, options = {}) {
115106
// to 12.x, then this can be converted to use optional chaining to
116107
// simplify the check.
117108
if (signal && signal.aborted) {
118-
return PromiseReject(
119-
lazyDOMException('The operation was aborted', 'AbortError'));
109+
return PromiseReject(new AbortError());
120110
}
121111
let oncancel;
122112
const ret = new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)