Skip to content

Commit 8689ce4

Browse files
tniessenmarco-ippolito
authored andcommitted
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 <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Zeyu "Alex" Yang <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 37e725a commit 8689ce4

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
@@ -170,7 +170,7 @@ function stopTest(timeout, signal) {
170170

171171
class TestPlan {
172172
constructor(count) {
173-
validateUint32(count, 'count', 0);
173+
validateUint32(count, 'count');
174174
this.expected = count;
175175
this.actual = 0;
176176
}
@@ -388,7 +388,7 @@ class Test extends AsyncResource {
388388

389389
switch (typeof concurrency) {
390390
case 'number':
391-
validateUint32(concurrency, 'options.concurrency', 1);
391+
validateUint32(concurrency, 'options.concurrency', true);
392392
this.concurrency = concurrency;
393393
break;
394394

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)