File tree 1 file changed +19
-2
lines changed
1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,14 @@ const {
5
5
codes : {
6
6
ERR_INVALID_ARG_TYPE ,
7
7
ERR_INVALID_ARG_VALUE ,
8
- ERR_OUT_OF_RANGE
8
+ ERR_OUT_OF_RANGE ,
9
+ ERR_UNKNOWN_SIGNAL
9
10
}
10
11
} = require ( 'internal/errors' ) ;
11
12
const {
12
13
isArrayBufferView
13
14
} = require ( 'internal/util/types' ) ;
15
+ const { signals } = internalBinding ( 'constants' ) . os ;
14
16
15
17
function isInt32 ( value ) {
16
18
return value === ( value | 0 ) ;
@@ -110,6 +112,20 @@ function validateNumber(value, name) {
110
112
throw new ERR_INVALID_ARG_TYPE ( name , 'number' , value ) ;
111
113
}
112
114
115
+ function validateSignalName ( signal , name = 'signal' ) {
116
+ if ( typeof signal !== 'string' )
117
+ throw new ERR_INVALID_ARG_TYPE ( name , 'string' , signal ) ;
118
+
119
+ if ( signals [ signal ] === undefined ) {
120
+ if ( signals [ signal . toUpperCase ( ) ] !== undefined ) {
121
+ throw new ERR_UNKNOWN_SIGNAL ( signal +
122
+ ' (signals must use all capital letters)' ) ;
123
+ }
124
+
125
+ throw new ERR_UNKNOWN_SIGNAL ( signal ) ;
126
+ }
127
+ }
128
+
113
129
// TODO(BridgeAR): We have multiple validation functions that call
114
130
// `require('internal/utils').toBuf()` before validating for array buffer views.
115
131
// Those should likely also be consolidated in here.
@@ -130,5 +146,6 @@ module.exports = {
130
146
validateInt32,
131
147
validateUint32,
132
148
validateString,
133
- validateNumber
149
+ validateNumber,
150
+ validateSignalName
134
151
} ;
You can’t perform that action at this time.
0 commit comments