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

lib: refactor to use validateAbortSignal #36604

Merged
merged 1 commit into from
Dec 27, 2020
Merged
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
7 changes: 3 additions & 4 deletions lib/internal/quic/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ const {
} = require('internal/histogram');

const {
validateAbortSignal,
validateBoolean,
validateInteger,
validateObject,
Expand Down Expand Up @@ -680,8 +681,7 @@ class QuicEndpoint {
return this.address;

const { signal } = { ...options };
if (signal != null && !('aborted' in signal))
throw new ERR_INVALID_ARG_TYPE('options.signal', 'AbortSignal', signal);
validateAbortSignal(signal, 'options.signal');

// If an AbortSignal was passed in, check to make sure it is not already
// aborted before we continue on to do any work.
Expand Down Expand Up @@ -1083,8 +1083,7 @@ class QuicSocket extends EventEmitter {
return;

const { signal } = { ...options };
if (signal != null && !('aborted' in signal))
throw new ERR_INVALID_ARG_TYPE('options.signal', 'AbortSignal', signal);
validateAbortSignal(signal, 'options.signal');

// If an AbotSignal was passed in, check to make sure it is not already
// aborted before we continue on to do any work.
Expand Down
28 changes: 10 additions & 18 deletions lib/timers/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const {
codes: { ERR_INVALID_ARG_TYPE }
} = require('internal/errors');

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

function cancelListenerHandler(clear, reject) {
if (!this._destroyed) {
clear(this);
Expand All @@ -35,15 +37,10 @@ function setTimeout(after, value, options = {}) {
options));
}
const { signal, ref = true } = options;
if (signal !== undefined &&
(signal === null ||
typeof signal !== 'object' ||
!('aborted' in signal))) {
return PromiseReject(
new ERR_INVALID_ARG_TYPE(
'options.signal',
'AbortSignal',
signal));
try {
validateAbortSignal(signal, 'options.signal');
} catch (err) {
return PromiseReject(err);
}
if (typeof ref !== 'boolean') {
return PromiseReject(
Expand Down Expand Up @@ -85,15 +82,10 @@ function setImmediate(value, options = {}) {
options));
}
const { signal, ref = true } = options;
if (signal !== undefined &&
(signal === null ||
typeof signal !== 'object' ||
!('aborted' in signal))) {
return PromiseReject(
new ERR_INVALID_ARG_TYPE(
'options.signal',
'AbortSignal',
signal));
try {
validateAbortSignal(signal, 'options.signal');
} catch (err) {
return PromiseReject(err);
}
if (typeof ref !== 'boolean') {
return PromiseReject(
Expand Down