Skip to content

Commit

Permalink
histogram: refactor to use min/max of validateNumber
Browse files Browse the repository at this point in the history
Fix NumberIsNaN is called two times and change error code
to ERR_OUT_OF_RANGE when RangeError is occurred in test.
  • Loading branch information
deokjinkim committed Dec 7, 2022
1 parent 3bef549 commit 4d67a36
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
10 changes: 2 additions & 8 deletions lib/internal/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,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);

return this[kHandle]?.percentile(percentile);
}
Expand All @@ -201,10 +198,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

0 comments on commit 4d67a36

Please sign in to comment.