Skip to content

Commit

Permalink
perf_hooks: throw ERR_INVALID_ARG_VALUE if histogram.percentile param…
Browse files Browse the repository at this point in the history
… is NaN

Fixes: #36936

PR-URL: #36937
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
Lxxyx authored and jasnell committed Jan 18, 2021
1 parent 9a18bf2 commit 59af4e6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/internal/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const {
} = require('internal/util');

const { format } = require('util');
const { SafeMap, Symbol } = primordials;
const { NumberIsNaN, SafeMap, Symbol } = primordials;

const {
ERR_INVALID_ARG_TYPE,
Expand Down Expand Up @@ -61,7 +61,7 @@ class Histogram {
if (typeof percentile !== 'number')
throw new ERR_INVALID_ARG_TYPE('percentile', 'number', percentile);

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

return this[kHandle]?.percentile(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 @@ -86,7 +86,7 @@ const { sleep } = require('internal/util');
}
);
});
[-1, 0, 101].forEach((i) => {
[-1, 0, 101, NaN].forEach((i) => {
assert.throws(
() => histogram.percentile(i),
{
Expand Down

0 comments on commit 59af4e6

Please sign in to comment.