Skip to content

Commit 5469d04

Browse files
authored
lib: fix misleading argument of validateUint32
The type of the argument `positive` was declared as `boolean|number`, which is misleading because the function treats it as a boolean only. Some call sites even passed numbers, specifically, either `0` or `1`, which happen to work as expected because they are interpreted as `false` and `true`, respectively. However, passing `2` would silently lead to unexpected behavior. Thus, strictly make the argument a boolean. PR-URL: #53307 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 001c36b commit 5469d04

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

lib/internal/test_runner/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function testMatchesPattern(test, patterns) {
194194

195195
class TestPlan {
196196
constructor(count) {
197-
validateUint32(count, 'count', 0);
197+
validateUint32(count, 'count');
198198
this.expected = count;
199199
this.actual = 0;
200200
}
@@ -428,7 +428,7 @@ class Test extends AsyncResource {
428428

429429
switch (typeof concurrency) {
430430
case 'number':
431-
validateUint32(concurrency, 'options.concurrency', 1);
431+
validateUint32(concurrency, 'options.concurrency', true);
432432
this.concurrency = concurrency;
433433
break;
434434

lib/internal/validators.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const validateInt32 = hideStackFrames(
129129
* @callback validateUint32
130130
* @param {*} value
131131
* @param {string} name
132-
* @param {number|boolean} [positive=false]
132+
* @param {boolean} [positive=false]
133133
* @returns {asserts value is number}
134134
*/
135135

lib/v8.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ function getHeapCodeStatistics() {
248248

249249
let heapSnapshotNearHeapLimitCallbackAdded = false;
250250
function setHeapSnapshotNearHeapLimit(limit) {
251-
validateUint32(limit, 'limit', 1);
251+
validateUint32(limit, 'limit', true);
252252
if (heapSnapshotNearHeapLimitCallbackAdded ||
253253
getOptionValue('--heapsnapshot-near-heap-limit') > 0
254254
) {

0 commit comments

Comments
 (0)