| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -149,8 +149,8 @@ function randomInt(min, max, callback) { | |||
| 149 | 149 | if (!NumberIsSafeInteger(max)) { | |
| 150 | 150 | throw new ERR_INVALID_ARG_TYPE('max', 'safe integer', max); | |
| 151 | 151 | } | |
| 152 | - if (!(max >= min)) { | ||
| 153 | - throw new ERR_OUT_OF_RANGE('max', `>= ${min}`, max); | ||
| 152 | + if (max <= min) { | ||
| 153 | + throw new ERR_OUT_OF_RANGE('max', `> ${min}`, max); | ||
| 154 | 154 | } | |
| 155 | 155 | ||
| 156 | 156 | // First we generate a random int between [0..range) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -456,13 +456,16 @@ assert.throws( | |||
| 456 | 456 | } | |
| 457 | 457 | ); | |
| 458 | 458 | ||
| 459 | - crypto.randomInt(0, common.mustCall()); | ||
| 460 | - crypto.randomInt(0, 0, common.mustCall()); | ||
| 461 | - assert.throws(() => crypto.randomInt(-1, common.mustNotCall()), { | ||
| 462 | - code: 'ERR_OUT_OF_RANGE', | ||
| 463 | - name: 'RangeError', | ||
| 464 | - message: 'The value of "max" is out of range. It must be >= 0. Received -1' | ||
| 465 | - }); | ||
| 459 | + crypto.randomInt(1, common.mustCall()); | ||
| 460 | + crypto.randomInt(0, 1, common.mustCall()); | ||
| 461 | + for (const arg of [[0], [1, 1], [3, 2], [-5, -5], [11, -10]]) { | ||
| 462 | + assert.throws(() => crypto.randomInt(...arg, common.mustNotCall()), { | ||
| 463 | + code: 'ERR_OUT_OF_RANGE', | ||
| 464 | + name: 'RangeError', | ||
| 465 | + message: 'The value of "max" is out of range. It must be > ' + | ||
| 466 | + `${arg[arg.length - 2] || 0}. Received ${arg[arg.length - 1]}` | ||
| 467 | + }); | ||
| 468 | + } | ||
| 466 | 469 | ||
| 467 | 470 | const MAX_RANGE = 0xFFFF_FFFF_FFFF; | |
| 468 | 471 | crypto.randomInt(MAX_RANGE, common.mustCall()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments