From 726ef40fcb829578027ceafb6155c949d2b55360 Mon Sep 17 00:00:00 2001 From: ZiJian Liu Date: Fri, 15 Jan 2021 12:49:53 +0800 Subject: [PATCH] perf_hooks: throw ERR_INVALID_ARG_VALUE if histogram.percentile param is NaN Fixes: https://github.com/nodejs/node/issues/36936 PR-URL: https://github.com/nodejs/node/pull/36937 Reviewed-By: Antoine du Hamel Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- lib/internal/histogram.js | 4 ++-- test/sequential/test-performance-eventloopdelay.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/histogram.js b/lib/internal/histogram.js index 00149db50236da..f599e4b3edb5f5 100644 --- a/lib/internal/histogram.js +++ b/lib/internal/histogram.js @@ -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, @@ -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); diff --git a/test/sequential/test-performance-eventloopdelay.js b/test/sequential/test-performance-eventloopdelay.js index 47c54a2543fd54..765691f3fcb14f 100644 --- a/test/sequential/test-performance-eventloopdelay.js +++ b/test/sequential/test-performance-eventloopdelay.js @@ -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), {