Skip to content

Commit

Permalink
lib: 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 89113b8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
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);

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

0 comments on commit 89113b8

Please sign in to comment.