Skip to content

Commit b41bd4f

Browse files
committed
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 9a6e47e commit b41bd4f

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

lib/internal/timers/promises.js

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

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

2121
const { validateAbortSignal } = require('internal/validators');
2222

23-
let DOMException;
24-
25-
const lazyDOMException = hideStackFrames((message, name) => {
26-
if (DOMException === undefined)
27-
DOMException = internalBinding('messaging').DOMException;
28-
return new DOMException(message, name);
29-
});
30-
3123
function cancelListenerHandler(clear, reject) {
3224
if (!this._destroyed) {
3325
clear(this);
34-
reject(lazyDOMException('The operation was aborted', 'AbortError'));
26+
reject(new AbortError());
3527
}
3628
}
3729

@@ -61,8 +53,7 @@ function setTimeout(after, value, options = {}) {
6153
// to 12.x, then this can be converted to use optional chaining to
6254
// simplify the check.
6355
if (signal && signal.aborted) {
64-
return PromiseReject(
65-
lazyDOMException('The operation was aborted', 'AbortError'));
56+
return PromiseReject(new AbortError());
6657
}
6758
let oncancel;
6859
const ret = new Promise((resolve, reject) => {
@@ -107,8 +98,7 @@ function setImmediate(value, options = {}) {
10798
// to 12.x, then this can be converted to use optional chaining to
10899
// simplify the check.
109100
if (signal && signal.aborted) {
110-
return PromiseReject(
111-
lazyDOMException('The operation was aborted', 'AbortError'));
101+
return PromiseReject(new AbortError());
112102
}
113103
let oncancel;
114104
const ret = new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)