Skip to content

Commit

Permalink
lib: refactor to use validateBoolean
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Lxxyx authored and targos committed Feb 2, 2021
1 parent 53a0bdf commit c4cab1f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 20 deletions.
7 changes: 3 additions & 4 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const {
const {
isUint32,
parseFileMode,
validateBoolean,
validateBuffer,
validateCallback,
validateInteger,
Expand Down Expand Up @@ -1002,8 +1003,7 @@ function mkdir(path, options, callback) {
callback = makeCallback(callback);
path = getValidatedPath(path);

if (typeof recursive !== 'boolean')
throw new ERR_INVALID_ARG_TYPE('options.recursive', 'boolean', recursive);
validateBoolean(recursive, 'options.recursive');

const req = new FSReqCallback();
req.oncomplete = callback;
Expand All @@ -1023,8 +1023,7 @@ function mkdirSync(path, options) {
mode = options.mode;
}
path = getValidatedPath(path);
if (typeof recursive !== 'boolean')
throw new ERR_INVALID_ARG_TYPE('options.recursive', 'boolean', recursive);
validateBoolean(recursive, 'options.recursive');

const ctx = { path };
const result = binding.mkdir(pathModule.toNamespacedPath(path),
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const {
const { opendir } = require('internal/fs/dir');
const {
parseFileMode,
validateBoolean,
validateBuffer,
validateInteger,
validateUint32
Expand Down Expand Up @@ -509,8 +510,7 @@ async function mkdir(path, options) {
mode = 0o777
} = options || {};
path = getValidatedPath(path);
if (typeof recursive !== 'boolean')
throw new ERR_INVALID_ARG_TYPE('options.recursive', 'boolean', recursive);
validateBoolean(recursive, 'options.recursive');

return binding.mkdir(pathModule.toNamespacedPath(path),
parseFileMode(mode, 'mode', 0o777), recursive,
Expand Down
9 changes: 3 additions & 6 deletions lib/internal/process/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,15 @@ const report = {
return nr.shouldReportOnFatalError();
},
set reportOnFatalError(trigger) {
if (typeof trigger !== 'boolean')
throw new ERR_INVALID_ARG_TYPE('trigger', 'boolean', trigger);
validateBoolean(trigger, 'trigger');

nr.setReportOnFatalError(trigger);
},
get reportOnSignal() {
return nr.shouldReportOnSignal();
},
set reportOnSignal(trigger) {
if (typeof trigger !== 'boolean')
throw new ERR_INVALID_ARG_TYPE('trigger', 'boolean', trigger);
validateBoolean(trigger, 'trigger');

nr.setReportOnSignal(trigger);
removeSignalHandler();
Expand All @@ -89,8 +87,7 @@ const report = {
return nr.shouldReportOnUncaughtException();
},
set reportOnUncaughtException(trigger) {
if (typeof trigger !== 'boolean')
throw new ERR_INVALID_ARG_TYPE('trigger', 'boolean', trigger);
validateBoolean(trigger, 'trigger');

nr.setReportOnUncaughtException(trigger);
}
Expand Down
6 changes: 2 additions & 4 deletions lib/internal/vm/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const {
ERR_VM_MODULE_STATUS,
} = require('internal/errors').codes;
const {
validateBoolean,
validateInt32,
validateUint32,
validateString,
Expand Down Expand Up @@ -215,10 +216,7 @@ class Module {
validateUint32(timeout, 'options.timeout', true);
}
const { breakOnSigint = false } = options;
if (typeof breakOnSigint !== 'boolean') {
throw new ERR_INVALID_ARG_TYPE('options.breakOnSigint', 'boolean',
breakOnSigint);
}
validateBoolean(breakOnSigint, 'options.breakOnSigint');
const status = this[kWrap].getStatus();
if (status !== kInstantiated &&
status !== kEvaluated &&
Expand Down
5 changes: 1 addition & 4 deletions lib/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ class Script extends ContextifyScript {
cachedData
);
}
if (typeof produceCachedData !== 'boolean') {
throw new ERR_INVALID_ARG_TYPE('options.produceCachedData', 'boolean',
produceCachedData);
}
validateBoolean(produceCachedData, 'options.produceCachedData');

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

0 comments on commit c4cab1f

Please sign in to comment.