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 targos committed Jun 11, 2021
1 parent 77c7d97 commit 726ef40
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
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
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 726ef40

Please sign in to comment.