Skip to content

Commit 8b7336b

Browse files
Lxxyxdanielleadams
authored andcommitted
quic,timers: refactor to use validateAbortSignal
PR-URL: #36604 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]>
1 parent 8a0cdb3 commit 8b7336b

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

lib/internal/quic/core.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ const {
204204
} = require('internal/histogram');
205205

206206
const {
207+
validateAbortSignal,
207208
validateBoolean,
208209
validateInteger,
209210
validateObject,
@@ -680,8 +681,7 @@ class QuicEndpoint {
680681
return this.address;
681682

682683
const { signal } = { ...options };
683-
if (signal != null && !('aborted' in signal))
684-
throw new ERR_INVALID_ARG_TYPE('options.signal', 'AbortSignal', signal);
684+
validateAbortSignal(signal, 'options.signal');
685685

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

10851085
const { signal } = { ...options };
1086-
if (signal != null && !('aborted' in signal))
1087-
throw new ERR_INVALID_ARG_TYPE('options.signal', 'AbortSignal', signal);
1086+
validateAbortSignal(signal, 'options.signal');
10881087

10891088
// If an AbotSignal was passed in, check to make sure it is not already
10901089
// aborted before we continue on to do any work.

lib/timers/promises.js

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

21+
const { validateAbortSignal } = require('internal/validators');
22+
2123
function cancelListenerHandler(clear, reject) {
2224
if (!this._destroyed) {
2325
clear(this);
@@ -35,15 +37,10 @@ function setTimeout(after, value, options = {}) {
3537
options));
3638
}
3739
const { signal, ref = true } = options;
38-
if (signal !== undefined &&
39-
(signal === null ||
40-
typeof signal !== 'object' ||
41-
!('aborted' in signal))) {
42-
return PromiseReject(
43-
new ERR_INVALID_ARG_TYPE(
44-
'options.signal',
45-
'AbortSignal',
46-
signal));
40+
try {
41+
validateAbortSignal(signal, 'options.signal');
42+
} catch (err) {
43+
return PromiseReject(err);
4744
}
4845
if (typeof ref !== 'boolean') {
4946
return PromiseReject(
@@ -85,15 +82,10 @@ function setImmediate(value, options = {}) {
8582
options));
8683
}
8784
const { signal, ref = true } = options;
88-
if (signal !== undefined &&
89-
(signal === null ||
90-
typeof signal !== 'object' ||
91-
!('aborted' in signal))) {
92-
return PromiseReject(
93-
new ERR_INVALID_ARG_TYPE(
94-
'options.signal',
95-
'AbortSignal',
96-
signal));
85+
try {
86+
validateAbortSignal(signal, 'options.signal');
87+
} catch (err) {
88+
return PromiseReject(err);
9789
}
9890
if (typeof ref !== 'boolean') {
9991
return PromiseReject(

0 commit comments

Comments
 (0)