Skip to content

Commit c4cab1f

Browse files
Lxxyxtargos
authored andcommitted
lib: refactor to use validateBoolean
PR-URL: #36983 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 53a0bdf commit c4cab1f

File tree

5 files changed

+11
-20
lines changed

5 files changed

+11
-20
lines changed

lib/fs.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ const {
123123
const {
124124
isUint32,
125125
parseFileMode,
126+
validateBoolean,
126127
validateBuffer,
127128
validateCallback,
128129
validateInteger,
@@ -1002,8 +1003,7 @@ function mkdir(path, options, callback) {
10021003
callback = makeCallback(callback);
10031004
path = getValidatedPath(path);
10041005

1005-
if (typeof recursive !== 'boolean')
1006-
throw new ERR_INVALID_ARG_TYPE('options.recursive', 'boolean', recursive);
1006+
validateBoolean(recursive, 'options.recursive');
10071007

10081008
const req = new FSReqCallback();
10091009
req.oncomplete = callback;
@@ -1023,8 +1023,7 @@ function mkdirSync(path, options) {
10231023
mode = options.mode;
10241024
}
10251025
path = getValidatedPath(path);
1026-
if (typeof recursive !== 'boolean')
1027-
throw new ERR_INVALID_ARG_TYPE('options.recursive', 'boolean', recursive);
1026+
validateBoolean(recursive, 'options.recursive');
10281027

10291028
const ctx = { path };
10301029
const result = binding.mkdir(pathModule.toNamespacedPath(path),

lib/internal/fs/promises.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const {
6666
const { opendir } = require('internal/fs/dir');
6767
const {
6868
parseFileMode,
69+
validateBoolean,
6970
validateBuffer,
7071
validateInteger,
7172
validateUint32
@@ -509,8 +510,7 @@ async function mkdir(path, options) {
509510
mode = 0o777
510511
} = options || {};
511512
path = getValidatedPath(path);
512-
if (typeof recursive !== 'boolean')
513-
throw new ERR_INVALID_ARG_TYPE('options.recursive', 'boolean', recursive);
513+
validateBoolean(recursive, 'options.recursive');
514514

515515
return binding.mkdir(pathModule.toNamespacedPath(path),
516516
parseFileMode(mode, 'mode', 0o777), recursive,

lib/internal/process/report.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,15 @@ const report = {
6969
return nr.shouldReportOnFatalError();
7070
},
7171
set reportOnFatalError(trigger) {
72-
if (typeof trigger !== 'boolean')
73-
throw new ERR_INVALID_ARG_TYPE('trigger', 'boolean', trigger);
72+
validateBoolean(trigger, 'trigger');
7473

7574
nr.setReportOnFatalError(trigger);
7675
},
7776
get reportOnSignal() {
7877
return nr.shouldReportOnSignal();
7978
},
8079
set reportOnSignal(trigger) {
81-
if (typeof trigger !== 'boolean')
82-
throw new ERR_INVALID_ARG_TYPE('trigger', 'boolean', trigger);
80+
validateBoolean(trigger, 'trigger');
8381

8482
nr.setReportOnSignal(trigger);
8583
removeSignalHandler();
@@ -89,8 +87,7 @@ const report = {
8987
return nr.shouldReportOnUncaughtException();
9088
},
9189
set reportOnUncaughtException(trigger) {
92-
if (typeof trigger !== 'boolean')
93-
throw new ERR_INVALID_ARG_TYPE('trigger', 'boolean', trigger);
90+
validateBoolean(trigger, 'trigger');
9491

9592
nr.setReportOnUncaughtException(trigger);
9693
}

lib/internal/vm/module.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const {
3939
ERR_VM_MODULE_STATUS,
4040
} = require('internal/errors').codes;
4141
const {
42+
validateBoolean,
4243
validateInt32,
4344
validateUint32,
4445
validateString,
@@ -215,10 +216,7 @@ class Module {
215216
validateUint32(timeout, 'options.timeout', true);
216217
}
217218
const { breakOnSigint = false } = options;
218-
if (typeof breakOnSigint !== 'boolean') {
219-
throw new ERR_INVALID_ARG_TYPE('options.breakOnSigint', 'boolean',
220-
breakOnSigint);
221-
}
219+
validateBoolean(breakOnSigint, 'options.breakOnSigint');
222220
const status = this[kWrap].getStatus();
223221
if (status !== kInstantiated &&
224222
status !== kEvaluated &&

lib/vm.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ class Script extends ContextifyScript {
9090
cachedData
9191
);
9292
}
93-
if (typeof produceCachedData !== 'boolean') {
94-
throw new ERR_INVALID_ARG_TYPE('options.produceCachedData', 'boolean',
95-
produceCachedData);
96-
}
93+
validateBoolean(produceCachedData, 'options.produceCachedData');
9794

9895
// Calling `ReThrow()` on a native TryCatch does not generate a new
9996
// abort-on-uncaught-exception check. A dummy try/catch in JS land

0 commit comments

Comments
 (0)