From 1bbbed3c9cb086900631909759d4837a01573fea Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Thu, 8 Dec 2022 00:42:53 +0900 Subject: [PATCH] lib: refactor to use min/max of `validateNumber` Fix NumberIsNaN is called two times and change error code to ERR_OUT_OF_RANGE when RangeError is occurred in test. --- lib/internal/histogram.js | 10 ++-------- test/sequential/test-performance-eventloopdelay.js | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/internal/histogram.js b/lib/internal/histogram.js index ca540e555e0160..048abea57dc7ba 100644 --- a/lib/internal/histogram.js +++ b/lib/internal/histogram.js @@ -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); } @@ -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); } diff --git a/test/sequential/test-performance-eventloopdelay.js b/test/sequential/test-performance-eventloopdelay.js index f262e9de3fe6cb..24e5744118cc38 100644 --- a/test/sequential/test-performance-eventloopdelay.js +++ b/test/sequential/test-performance-eventloopdelay.js @@ -91,7 +91,7 @@ const { sleep } = require('internal/util'); () => histogram.percentile(i), { name: 'RangeError', - code: 'ERR_INVALID_ARG_VALUE' + code: 'ERR_OUT_OF_RANGE' } ); });