Skip to content

Commit 1b74a08

Browse files
Lxxyxtargos
authored andcommitted
timers: refactor to use validateAbortSignal
PR-URL: #36604 Backport-PR-URL: #38386 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
1 parent 385e8e8 commit 1b74a08

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

lib/internal/timers/promises.js

+10-18
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const {
1616
codes: { ERR_INVALID_ARG_TYPE }
1717
} = require('internal/errors');
1818

19+
const { validateAbortSignal } = require('internal/validators');
20+
1921
let DOMException;
2022

2123
const lazyDOMException = hideStackFrames((message, name) => {
@@ -34,15 +36,10 @@ function setTimeout(after, value, options = {}) {
3436
options));
3537
}
3638
const { signal, ref = true } = options;
37-
if (signal !== undefined &&
38-
(signal === null ||
39-
typeof signal !== 'object' ||
40-
!('aborted' in signal))) {
41-
return PromiseReject(
42-
new ERR_INVALID_ARG_TYPE(
43-
'options.signal',
44-
'AbortSignal',
45-
signal));
39+
try {
40+
validateAbortSignal(signal, 'options.signal');
41+
} catch (err) {
42+
return PromiseReject(err);
4643
}
4744
if (typeof ref !== 'boolean') {
4845
return PromiseReject(
@@ -83,15 +80,10 @@ function setImmediate(value, options = {}) {
8380
options));
8481
}
8582
const { signal, ref = true } = options;
86-
if (signal !== undefined &&
87-
(signal === null ||
88-
typeof signal !== 'object' ||
89-
!('aborted' in signal))) {
90-
return PromiseReject(
91-
new ERR_INVALID_ARG_TYPE(
92-
'options.signal',
93-
'AbortSignal',
94-
signal));
83+
try {
84+
validateAbortSignal(signal, 'options.signal');
85+
} catch (err) {
86+
return PromiseReject(err);
9587
}
9688
if (typeof ref !== 'boolean') {
9789
return PromiseReject(

0 commit comments

Comments
 (0)