mirror of https://github.com/nodejs/node.git
timers: use AbortController with correct name/message
On the web, `AbortError` is the error name, not the error message. Change the code to match that. PR-URL: https://github.com/nodejs/node/pull/34763 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>pull/34769/head
parent
ba5c64bf45
commit
5d179cb2ec
|
@ -18,10 +18,10 @@ const {
|
||||||
|
|
||||||
let DOMException;
|
let DOMException;
|
||||||
|
|
||||||
const lazyDOMException = hideStackFrames((message) => {
|
const lazyDOMException = hideStackFrames((message, name) => {
|
||||||
if (DOMException === undefined)
|
if (DOMException === undefined)
|
||||||
DOMException = internalBinding('messaging').DOMException;
|
DOMException = internalBinding('messaging').DOMException;
|
||||||
return new DOMException(message);
|
return new DOMException(message, name);
|
||||||
});
|
});
|
||||||
|
|
||||||
function setTimeout(after, value, options = {}) {
|
function setTimeout(after, value, options = {}) {
|
||||||
|
@ -54,8 +54,10 @@ function setTimeout(after, value, options = {}) {
|
||||||
// TODO(@jasnell): If a decision is made that this cannot be backported
|
// TODO(@jasnell): If a decision is made that this cannot be backported
|
||||||
// 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(lazyDOMException('AbortError'));
|
return PromiseReject(
|
||||||
|
lazyDOMException('The operation was aborted', 'AbortError'));
|
||||||
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const timeout = new Timeout(resolve, after, args, false, true);
|
const timeout = new Timeout(resolve, after, args, false, true);
|
||||||
if (!ref) timeout.unref();
|
if (!ref) timeout.unref();
|
||||||
|
@ -65,7 +67,7 @@ function setTimeout(after, value, options = {}) {
|
||||||
if (!timeout._destroyed) {
|
if (!timeout._destroyed) {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
reject(lazyDOMException('AbortError'));
|
reject(lazyDOMException('The operation was aborted', 'AbortError'));
|
||||||
}
|
}
|
||||||
}, { once: true });
|
}, { once: true });
|
||||||
}
|
}
|
||||||
|
@ -101,8 +103,10 @@ function setImmediate(value, options = {}) {
|
||||||
// TODO(@jasnell): If a decision is made that this cannot be backported
|
// TODO(@jasnell): If a decision is made that this cannot be backported
|
||||||
// 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(lazyDOMException('AbortError'));
|
return PromiseReject(
|
||||||
|
lazyDOMException('The operation was aborted', 'AbortError'));
|
||||||
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const immediate = new Immediate(resolve, [value]);
|
const immediate = new Immediate(resolve, [value]);
|
||||||
if (!ref) immediate.unref();
|
if (!ref) immediate.unref();
|
||||||
|
@ -111,7 +115,7 @@ function setImmediate(value, options = {}) {
|
||||||
if (!immediate._destroyed) {
|
if (!immediate._destroyed) {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
clearImmediate(immediate);
|
clearImmediate(immediate);
|
||||||
reject(lazyDOMException('AbortError'));
|
reject(lazyDOMException('The operation was aborted', 'AbortError'));
|
||||||
}
|
}
|
||||||
}, { once: true });
|
}, { once: true });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue