|
2 | 2 |
|
3 | 3 | const {
|
4 | 4 | ArrayIsArray,
|
| 5 | + ArrayPrototypeIncludes, |
| 6 | + ArrayPrototypeJoin, |
| 7 | + ArrayPrototypeMap, |
5 | 8 | NumberIsInteger,
|
6 | 9 | NumberMAX_SAFE_INTEGER,
|
7 | 10 | NumberMIN_SAFE_INTEGER,
|
8 | 11 | NumberParseInt,
|
| 12 | + RegExpPrototypeTest, |
9 | 13 | String,
|
| 14 | + StringPrototypeToUpperCase, |
| 15 | + StringPrototypeTrim, |
10 | 16 | } = primordials;
|
11 | 17 |
|
12 | 18 | const {
|
@@ -63,7 +69,7 @@ function parseFileMode(value, name, def) {
|
63 | 69 | }
|
64 | 70 |
|
65 | 71 | if (typeof value === 'string') {
|
66 |
| - if (!octalReg.test(value)) { |
| 72 | + if (!RegExpPrototypeTest(octalReg, value)) { |
67 | 73 | throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc);
|
68 | 74 | }
|
69 | 75 | return NumberParseInt(value, 8);
|
@@ -129,10 +135,11 @@ function validateNumber(value, name) {
|
129 | 135 | }
|
130 | 136 |
|
131 | 137 | const validateOneOf = hideStackFrames((value, name, oneOf) => {
|
132 |
| - if (!oneOf.includes(value)) { |
133 |
| - const allowed = oneOf |
134 |
| - .map((v) => (typeof v === 'string' ? `'${v}'` : String(v))) |
135 |
| - .join(', '); |
| 138 | + if (!ArrayPrototypeIncludes(oneOf, value)) { |
| 139 | + const allowed = ArrayPrototypeJoin( |
| 140 | + ArrayPrototypeMap(oneOf, (v) => |
| 141 | + (typeof v === 'string' ? `'${v}'` : String(v))), |
| 142 | + ', '); |
136 | 143 | const reason = 'must be one of: ' + allowed;
|
137 | 144 | throw new ERR_INVALID_ARG_VALUE(name, value, reason);
|
138 | 145 | }
|
@@ -167,7 +174,7 @@ function validateSignalName(signal, name = 'signal') {
|
167 | 174 | throw new ERR_INVALID_ARG_TYPE(name, 'string', signal);
|
168 | 175 |
|
169 | 176 | if (signals[signal] === undefined) {
|
170 |
| - if (signals[signal.toUpperCase()] !== undefined) { |
| 177 | + if (signals[StringPrototypeToUpperCase(signal)] !== undefined) { |
171 | 178 | throw new ERR_UNKNOWN_SIGNAL(signal +
|
172 | 179 | ' (signals must use all capital letters)');
|
173 | 180 | }
|
@@ -198,7 +205,7 @@ function validateEncoding(data, encoding) {
|
198 | 205 | // is an integer and that it falls within the legal range of port numbers.
|
199 | 206 | function validatePort(port, name = 'Port', { allowZero = true } = {}) {
|
200 | 207 | if ((typeof port !== 'number' && typeof port !== 'string') ||
|
201 |
| - (typeof port === 'string' && port.trim().length === 0) || |
| 208 | + (typeof port === 'string' && StringPrototypeTrim(port).length === 0) || |
202 | 209 | +port !== (+port >>> 0) ||
|
203 | 210 | port > 0xFFFF ||
|
204 | 211 | (port === 0 && !allowZero)) {
|
|
0 commit comments