Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quic,timers: use AbortController with correct name/message #34763

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/internal/quic/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ let warnedVerifyHostnameIdentity = false;

let DOMException;

const lazyDOMException = hideStackFrames((message) => {
const lazyDOMException = hideStackFrames((message, name) => {
if (DOMException === undefined)
DOMException = internalBinding('messaging').DOMException;
return new DOMException(message);
return new DOMException(message, name);
});

assert(process.versions.ngtcp2 !== undefined);
Expand Down Expand Up @@ -664,10 +664,10 @@ class QuicEndpoint {
if (signal != null && !('aborted' in signal))
throw new ERR_INVALID_ARG_TYPE('options.signal', 'AbortSignal', signal);

// If an AbotSignal was passed in, check to make sure it is not already
// If an AbortSignal was passed in, check to make sure it is not already
// aborted before we continue on to do any work.
if (signal && signal.aborted)
throw new lazyDOMException('AbortError');
throw new lazyDOMException('The operation was aborted', 'AbortError');

state.state = kSocketPending;

Expand All @@ -685,7 +685,7 @@ class QuicEndpoint {
// while we were waiting.
if (signal && signal.aborted) {
state.state = kSocketUnbound;
throw new lazyDOMException('AbortError');
throw new lazyDOMException('The operation was aborted', 'AbortError');
}

// From here on, any errors are fatal for the QuicEndpoint. Keep in
Expand Down Expand Up @@ -1064,7 +1064,7 @@ class QuicSocket extends EventEmitter {
// If an AbotSignal was passed in, check to make sure it is not already
// aborted before we continue on to do any work.
if (signal && signal.aborted)
throw new lazyDOMException('AbortError');
throw new lazyDOMException('The operation was aborted', 'AbortError');

state.state = kSocketPending;

Expand All @@ -1086,7 +1086,7 @@ class QuicSocket extends EventEmitter {
// Some number of endpoints may have successfully bound, while
// others have not
if (signal && signal.aborted)
throw lazyDOMException('AbortError');
throw lazyDOMException('The operation was aborted', 'AbortError');

state.state = kSocketBound;

Expand Down
20 changes: 12 additions & 8 deletions lib/timers/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const {

let DOMException;

const lazyDOMException = hideStackFrames((message) => {
const lazyDOMException = hideStackFrames((message, name) => {
if (DOMException === undefined)
DOMException = internalBinding('messaging').DOMException;
return new DOMException(message);
return new DOMException(message, name);
});

function setTimeout(after, value, options = {}) {
Expand Down Expand Up @@ -54,8 +54,10 @@ function setTimeout(after, value, options = {}) {
// 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
// simplify the check.
if (signal && signal.aborted)
return PromiseReject(lazyDOMException('AbortError'));
if (signal && signal.aborted) {
return PromiseReject(
lazyDOMException('The operation was aborted', 'AbortError'));
}
return new Promise((resolve, reject) => {
const timeout = new Timeout(resolve, after, args, false, true);
if (!ref) timeout.unref();
Expand All @@ -65,7 +67,7 @@ function setTimeout(after, value, options = {}) {
if (!timeout._destroyed) {
// eslint-disable-next-line no-undef
clearTimeout(timeout);
reject(lazyDOMException('AbortError'));
reject(lazyDOMException('The operation was aborted', 'AbortError'));
}
}, { once: true });
}
Expand Down Expand Up @@ -101,8 +103,10 @@ function setImmediate(value, options = {}) {
// 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
// simplify the check.
if (signal && signal.aborted)
return PromiseReject(lazyDOMException('AbortError'));
if (signal && signal.aborted) {
return PromiseReject(
lazyDOMException('The operation was aborted', 'AbortError'));
}
return new Promise((resolve, reject) => {
const immediate = new Immediate(resolve, [value]);
if (!ref) immediate.unref();
Expand All @@ -111,7 +115,7 @@ function setImmediate(value, options = {}) {
if (!immediate._destroyed) {
// eslint-disable-next-line no-undef
clearImmediate(immediate);
reject(lazyDOMException('AbortError'));
reject(lazyDOMException('The operation was aborted', 'AbortError'));
}
}, { once: true });
}
Expand Down