From 53f7d3ee2c598e7ce18f5026102cd1658b435957 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 4 Sep 2020 07:00:40 -0700 Subject: [PATCH] crypto: align parameter names with documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change _cb_ to _callback_ to align with documentation. This is so that stack traces and error messages align with the documentation. If the documentation says "callback", then the stack traces and error messages should indicate that "callback" needs to be function or whatever, rather than "cb". PR-URL: https://github.com/nodejs/node/pull/35054 Reviewed-By: Tobias Nießen Reviewed-By: Michaël Zasso --- lib/internal/crypto/random.js | 42 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/internal/crypto/random.js b/lib/internal/crypto/random.js index 561586472fd835..13a8030e671f8f 100644 --- a/lib/internal/crypto/random.js +++ b/lib/internal/crypto/random.js @@ -49,19 +49,19 @@ function assertSize(size, elementSize, offset, length) { return size >>> 0; // Convert to uint32. } -function randomBytes(size, cb) { +function randomBytes(size, callback) { size = assertSize(size, 1, 0, Infinity); - if (cb !== undefined && typeof cb !== 'function') - throw new ERR_INVALID_CALLBACK(cb); + if (callback !== undefined && typeof callback !== 'function') + throw new ERR_INVALID_CALLBACK(callback); const buf = new FastBuffer(size); - if (!cb) return handleError(_randomBytes(buf, 0, size), buf); + if (!callback) return handleError(_randomBytes(buf, 0, size), buf); const wrap = new AsyncWrap(Providers.RANDOMBYTESREQUEST); wrap.ondone = (ex) => { // Retains buf while request is in flight. - if (ex) return cb.call(wrap, ex); - cb.call(wrap, null, buf); + if (ex) return callback.call(wrap, ex); + callback.call(wrap, null, buf); }; _randomBytes(buf, 0, size, wrap); @@ -85,7 +85,7 @@ function randomFillSync(buf, offset = 0, size) { return handleError(_randomBytes(buf, offset, size), buf); } -function randomFill(buf, offset, size, cb) { +function randomFill(buf, offset, size, callback) { if (!isArrayBufferView(buf)) { throw new ERR_INVALID_ARG_TYPE('buf', 'ArrayBufferView', buf); } @@ -93,14 +93,14 @@ function randomFill(buf, offset, size, cb) { const elementSize = buf.BYTES_PER_ELEMENT || 1; if (typeof offset === 'function') { - cb = offset; + callback = offset; offset = 0; size = buf.bytesLength; } else if (typeof size === 'function') { - cb = size; + callback = size; size = buf.byteLength - offset; - } else if (typeof cb !== 'function') { - throw new ERR_INVALID_CALLBACK(cb); + } else if (typeof callback !== 'function') { + throw new ERR_INVALID_CALLBACK(callback); } offset = assertOffset(offset, elementSize, buf.byteLength); @@ -113,8 +113,8 @@ function randomFill(buf, offset, size, cb) { const wrap = new AsyncWrap(Providers.RANDOMBYTESREQUEST); wrap.ondone = (ex) => { // Retains buf while request is in flight. - if (ex) return cb.call(wrap, ex); - cb.call(wrap, null, buf); + if (ex) return callback.call(wrap, ex); + callback.call(wrap, null, buf); }; _randomBytes(buf, offset, size, wrap); @@ -126,22 +126,22 @@ const RAND_MAX = 0xFFFF_FFFF_FFFF; // Generates an integer in [min, max) range where min is inclusive and max is // exclusive. -function randomInt(min, max, cb) { +function randomInt(min, max, callback) { // Detect optional min syntax // randomInt(max) - // randomInt(max, cb) + // randomInt(max, callback) const minNotSpecified = typeof max === 'undefined' || typeof max === 'function'; if (minNotSpecified) { - cb = max; + callback = max; max = min; min = 0; } - const isSync = typeof cb === 'undefined'; - if (!isSync && typeof cb !== 'function') { - throw new ERR_INVALID_CALLBACK(cb); + const isSync = typeof callback === 'undefined'; + if (!isSync && typeof callback !== 'function') { + throw new ERR_INVALID_CALLBACK(callback); } if (!NumberIsSafeInteger(min)) { throw new ERR_INVALID_ARG_TYPE('min', 'safe integer', min); @@ -180,7 +180,7 @@ function randomInt(min, max, cb) { // Async API const pickAttempt = () => { randomBytes(6, (err, bytes) => { - if (err) return cb(err); + if (err) return callback(err); const x = bytes.readUIntBE(0, 6); // If x > (maxVal - (maxVal % range)), we will get "modulo bias" if (x > randLimit) { @@ -188,7 +188,7 @@ function randomInt(min, max, cb) { return pickAttempt(); } const n = (x % range) + min; - cb(null, n); + callback(null, n); }); };