Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: refactor to use validateBoolean #36983

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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