mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
perf_hooks: fix checking range of options.figures in createHistogram
For `options.figures`, number between 1 and 5 is allowed. So need to use `validateInteger` to limit max as 5. Refs: https://github.com/nodejs/node/blob/main/doc/api/perf_hooks.md#perf_hookscreatehistogramoptions PR-URL: https://github.com/nodejs/node/pull/45999 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
f309e2acb6
commit
f0508894d6
2 files changed
+8
-2
No files matched your search
@@ -36,7 +36,6 @@ const {
|
||||
validateInteger,
|
||||
validateNumber,
|
||||
validateObject,
|
||||
validateUint32,
|
||||
} = require('internal/validators');
|
||||
|
||||
const kDestroy = Symbol('kDestroy');
|
||||
@@ -368,7 +367,7 @@ function createHistogram(options = kEmptyObject) {
|
||||
} else if (highest < 2n * lowest) {
|
||||
throw new ERR_INVALID_ARG_VALUE.RangeError('options.highest', highest);
|
||||
}
|
||||
validateUint32(figures, 'options.figures', 1, 5);
|
||||
validateInteger(figures, 'options.figures', 1, 5);
|
||||
return internalRecordableHistogram(new _Histogram(lowest, highest, figures));
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +135,13 @@ const { inspect } = require('util');
|
||||
});
|
||||
});
|
||||
|
||||
// Number greater than 5 is not allowed
|
||||
for (const i of [6, 10]) {
|
||||
throws(() => createHistogram({ figures: i }), {
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
});
|
||||
}
|
||||
|
||||
createHistogram({ lowest: 1, highest: 11, figures: 1 });
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user