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: improve the coverage of the validator #42443

Merged
merged 3 commits into from
Apr 2, 2022
Merged
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions lib/internal/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ const validateInteger = hideStackFrames(
const validateInt32 = hideStackFrames(
(value, name, min = -2147483648, max = 2147483647) => {
// The defaults for min and max correspond to the limits of 32-bit integers.
if (typeof value == 'symbol' || typeof value == 'bigint') {
throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
}
if (!isInt32(value)) {
if (typeof value !== 'number') {
throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
Expand All @@ -98,6 +101,9 @@ const validateInt32 = hideStackFrames(
);

const validateUint32 = hideStackFrames((value, name, positive) => {
if (typeof value == 'symbol' || typeof value == 'bigint') {
throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
}
if (!isUint32(value)) {
if (typeof value !== 'number') {
throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
Expand Down