mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
lib: refactor to use validateBoolean
PR-URL: https://github.com/nodejs/node/pull/36983 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
committed by
James M Snell
parent
96f3977ded
commit
cb5668be99
@@ -123,6 +123,7 @@ const {
|
||||
const {
|
||||
isUint32,
|
||||
parseFileMode,
|
||||
validateBoolean,
|
||||
validateBuffer,
|
||||
validateCallback,
|
||||
validateInteger,
|
||||
@@ -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;
|
||||
@@ -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),
|
||||
|
||||
@@ -66,6 +66,7 @@ const {
|
||||
const { opendir } = require('internal/fs/dir');
|
||||
const {
|
||||
parseFileMode,
|
||||
validateBoolean,
|
||||
validateBuffer,
|
||||
validateInteger,
|
||||
validateUint32
|
||||
@@ -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,
|
||||
|
||||
@@ -69,8 +69,7 @@ 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);
|
||||
},
|
||||
@@ -78,8 +77,7 @@ const report = {
|
||||
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();
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ const {
|
||||
ERR_VM_MODULE_STATUS,
|
||||
} = require('internal/errors').codes;
|
||||
const {
|
||||
validateBoolean,
|
||||
validateInt32,
|
||||
validateUint32,
|
||||
validateString,
|
||||
@@ -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 &&
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user