Skip to content

Commit

Permalink
timers: refactor to use validateAbortSignal
Browse files Browse the repository at this point in the history
PR-URL: #36604
Backport-PR-URL: #38386
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
  • Loading branch information
Lxxyx authored and targos committed Apr 30, 2021
1 parent 385e8e8 commit 1b74a08
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions lib/internal/timers/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const {
codes: { ERR_INVALID_ARG_TYPE }
} = require('internal/errors');

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

let DOMException;

const lazyDOMException = hideStackFrames((message, name) => {
Expand All @@ -34,15 +36,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 @@ -83,15 +80,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

0 comments on commit 1b74a08

Please sign in to comment.