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

perf_hooks: fix checking range of options.figures in createHistogram #45999

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/internal/histogram.js
Expand Up @@ -36,7 +36,6 @@ const {
validateInteger,
validateNumber,
validateObject,
validateUint32,
} = require('internal/validators');

const kDestroy = Symbol('kDestroy');
Expand Down Expand Up @@ -368,7 +367,7 @@ function createHistogram(options = kEmptyObject) {
} else if (highest < 2n * lowest) {
throw new ERR_INVALID_ARG_VALUE.RangeError('options.highest', highest);
}
validateUint32(figures, 'options.figures', 1, 5);
validateInteger(figures, 'options.figures', 1, 5);
return internalRecordableHistogram(new _Histogram(lowest, highest, figures));
}

Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-perf-hooks-histogram.js
Expand Up @@ -135,6 +135,13 @@ const { inspect } = require('util');
});
});

// Number greater than 5 is not allowed
for (const i of [6, 10]) {
throws(() => createHistogram({ figures: i }), {
code: 'ERR_OUT_OF_RANGE',
});
}

createHistogram({ lowest: 1, highest: 11, figures: 1 });
}

Expand Down