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 validateInteger #45772

Merged
Merged
Show file tree
Hide file tree
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
11 changes: 2 additions & 9 deletions lib/internal/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const {
MapPrototypeEntries,
NumberIsNaN,
NumberIsInteger,
NumberMAX_SAFE_INTEGER,
ObjectFromEntries,
Expand Down Expand Up @@ -186,10 +185,7 @@ class Histogram {
percentile(percentile) {
if (!isHistogram(this))
throw new ERR_INVALID_THIS('Histogram');
validateNumber(percentile, 'percentile');

if (NumberIsNaN(percentile) || percentile <= 0 || percentile > 100)
throw new ERR_INVALID_ARG_VALUE.RangeError('percentile', percentile);
validateNumber(percentile, 'percentile', 1, 100);
Copy link
Contributor

@aduh95 aduh95 Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This forbids all the numbers between 0 and 1 that were previously allowed.

Copy link
Contributor Author

@deokjinkim deokjinkim Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. I can't use min/max of validateNumber here because zero have not to be allowed for percentile. Instead, I changed error code to ERR_OUT_OF_RANGE. Plus, I find another place to use validateInteger. Please take a look when you are available.


return this[kHandle]?.percentile(percentile);
}
Expand All @@ -201,10 +197,7 @@ class Histogram {
percentileBigInt(percentile) {
if (!isHistogram(this))
throw new ERR_INVALID_THIS('Histogram');
validateNumber(percentile, 'percentile');

if (NumberIsNaN(percentile) || percentile <= 0 || percentile > 100)
throw new ERR_INVALID_ARG_VALUE.RangeError('percentile', percentile);
validateNumber(percentile, 'percentile', 1, 100);

return this[kHandle]?.percentileBigInt(percentile);
}
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-performance-eventloopdelay.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const { sleep } = require('internal/util');
() => histogram.percentile(i),
{
name: 'RangeError',
code: 'ERR_INVALID_ARG_VALUE'
code: 'ERR_OUT_OF_RANGE'
}
);
});
Expand Down