mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
timers: reject with AbortError on cancellation
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
780fcb4249
commit
1ed72f67f5
|
|
@ -14,22 +14,14 @@ const {
|
||||||
} = require('internal/timers');
|
} = require('internal/timers');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
hideStackFrames,
|
AbortError,
|
||||||
codes: { ERR_INVALID_ARG_TYPE }
|
codes: { ERR_INVALID_ARG_TYPE }
|
||||||
} = require('internal/errors');
|
} = require('internal/errors');
|
||||||
|
|
||||||
let DOMException;
|
|
||||||
|
|
||||||
const lazyDOMException = hideStackFrames((message, name) => {
|
|
||||||
if (DOMException === undefined)
|
|
||||||
DOMException = internalBinding('messaging').DOMException;
|
|
||||||
return new DOMException(message, name);
|
|
||||||
});
|
|
||||||
|
|
||||||
function cancelListenerHandler(clear, reject) {
|
function cancelListenerHandler(clear, reject) {
|
||||||
if (!this._destroyed) {
|
if (!this._destroyed) {
|
||||||
clear(this);
|
clear(this);
|
||||||
reject(lazyDOMException('The operation was aborted', 'AbortError'));
|
reject(new AbortError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,8 +56,7 @@ function setTimeout(after, value, options = {}) {
|
||||||
// to 12.x, then this can be converted to use optional chaining to
|
// to 12.x, then this can be converted to use optional chaining to
|
||||||
// simplify the check.
|
// simplify the check.
|
||||||
if (signal && signal.aborted) {
|
if (signal && signal.aborted) {
|
||||||
return PromiseReject(
|
return PromiseReject(new AbortError());
|
||||||
lazyDOMException('The operation was aborted', 'AbortError'));
|
|
||||||
}
|
}
|
||||||
let oncancel;
|
let oncancel;
|
||||||
const ret = new Promise((resolve, reject) => {
|
const ret = new Promise((resolve, reject) => {
|
||||||
|
|
@ -115,8 +106,7 @@ function setImmediate(value, options = {}) {
|
||||||
// to 12.x, then this can be converted to use optional chaining to
|
// to 12.x, then this can be converted to use optional chaining to
|
||||||
// simplify the check.
|
// simplify the check.
|
||||||
if (signal && signal.aborted) {
|
if (signal && signal.aborted) {
|
||||||
return PromiseReject(
|
return PromiseReject(new AbortError());
|
||||||
lazyDOMException('The operation was aborted', 'AbortError'));
|
|
||||||
}
|
}
|
||||||
let oncancel;
|
let oncancel;
|
||||||
const ret = new Promise((resolve, reject) => {
|
const ret = new Promise((resolve, reject) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user