@@ -49,19 +49,19 @@ function assertSize(size, elementSize, offset, length) {
49
49
return size >>> 0 ; // Convert to uint32.
50
50
}
51
51
52
- function randomBytes ( size , cb ) {
52
+ function randomBytes ( size , callback ) {
53
53
size = assertSize ( size , 1 , 0 , Infinity ) ;
54
- if ( cb !== undefined && typeof cb !== 'function' )
55
- throw new ERR_INVALID_CALLBACK ( cb ) ;
54
+ if ( callback !== undefined && typeof callback !== 'function' )
55
+ throw new ERR_INVALID_CALLBACK ( callback ) ;
56
56
57
57
const buf = new FastBuffer ( size ) ;
58
58
59
- if ( ! cb ) return handleError ( _randomBytes ( buf , 0 , size ) , buf ) ;
59
+ if ( ! callback ) return handleError ( _randomBytes ( buf , 0 , size ) , buf ) ;
60
60
61
61
const wrap = new AsyncWrap ( Providers . RANDOMBYTESREQUEST ) ;
62
62
wrap . ondone = ( ex ) => { // Retains buf while request is in flight.
63
- if ( ex ) return cb . call ( wrap , ex ) ;
64
- cb . call ( wrap , null , buf ) ;
63
+ if ( ex ) return callback . call ( wrap , ex ) ;
64
+ callback . call ( wrap , null , buf ) ;
65
65
} ;
66
66
67
67
_randomBytes ( buf , 0 , size , wrap ) ;
@@ -85,22 +85,22 @@ function randomFillSync(buf, offset = 0, size) {
85
85
return handleError ( _randomBytes ( buf , offset , size ) , buf ) ;
86
86
}
87
87
88
- function randomFill ( buf , offset , size , cb ) {
88
+ function randomFill ( buf , offset , size , callback ) {
89
89
if ( ! isArrayBufferView ( buf ) ) {
90
90
throw new ERR_INVALID_ARG_TYPE ( 'buf' , 'ArrayBufferView' , buf ) ;
91
91
}
92
92
93
93
const elementSize = buf . BYTES_PER_ELEMENT || 1 ;
94
94
95
95
if ( typeof offset === 'function' ) {
96
- cb = offset ;
96
+ callback = offset ;
97
97
offset = 0 ;
98
98
size = buf . bytesLength ;
99
99
} else if ( typeof size === 'function' ) {
100
- cb = size ;
100
+ callback = size ;
101
101
size = buf . byteLength - offset ;
102
- } else if ( typeof cb !== 'function' ) {
103
- throw new ERR_INVALID_CALLBACK ( cb ) ;
102
+ } else if ( typeof callback !== 'function' ) {
103
+ throw new ERR_INVALID_CALLBACK ( callback ) ;
104
104
}
105
105
106
106
offset = assertOffset ( offset , elementSize , buf . byteLength ) ;
@@ -113,8 +113,8 @@ function randomFill(buf, offset, size, cb) {
113
113
114
114
const wrap = new AsyncWrap ( Providers . RANDOMBYTESREQUEST ) ;
115
115
wrap . ondone = ( ex ) => { // Retains buf while request is in flight.
116
- if ( ex ) return cb . call ( wrap , ex ) ;
117
- cb . call ( wrap , null , buf ) ;
116
+ if ( ex ) return callback . call ( wrap , ex ) ;
117
+ callback . call ( wrap , null , buf ) ;
118
118
} ;
119
119
120
120
_randomBytes ( buf , offset , size , wrap ) ;
@@ -126,22 +126,22 @@ const RAND_MAX = 0xFFFF_FFFF_FFFF;
126
126
127
127
// Generates an integer in [min, max) range where min is inclusive and max is
128
128
// exclusive.
129
- function randomInt ( min , max , cb ) {
129
+ function randomInt ( min , max , callback ) {
130
130
// Detect optional min syntax
131
131
// randomInt(max)
132
- // randomInt(max, cb )
132
+ // randomInt(max, callback )
133
133
const minNotSpecified = typeof max === 'undefined' ||
134
134
typeof max === 'function' ;
135
135
136
136
if ( minNotSpecified ) {
137
- cb = max ;
137
+ callback = max ;
138
138
max = min ;
139
139
min = 0 ;
140
140
}
141
141
142
- const isSync = typeof cb === 'undefined' ;
143
- if ( ! isSync && typeof cb !== 'function' ) {
144
- throw new ERR_INVALID_CALLBACK ( cb ) ;
142
+ const isSync = typeof callback === 'undefined' ;
143
+ if ( ! isSync && typeof callback !== 'function' ) {
144
+ throw new ERR_INVALID_CALLBACK ( callback ) ;
145
145
}
146
146
if ( ! NumberIsSafeInteger ( min ) ) {
147
147
throw new ERR_INVALID_ARG_TYPE ( 'min' , 'safe integer' , min ) ;
@@ -180,15 +180,15 @@ function randomInt(min, max, cb) {
180
180
// Async API
181
181
const pickAttempt = ( ) => {
182
182
randomBytes ( 6 , ( err , bytes ) => {
183
- if ( err ) return cb ( err ) ;
183
+ if ( err ) return callback ( err ) ;
184
184
const x = bytes . readUIntBE ( 0 , 6 ) ;
185
185
// If x > (maxVal - (maxVal % range)), we will get "modulo bias"
186
186
if ( x > randLimit ) {
187
187
// Try again
188
188
return pickAttempt ( ) ;
189
189
}
190
190
const n = ( x % range ) + min ;
191
- cb ( null , n ) ;
191
+ callback ( null , n ) ;
192
192
} ) ;
193
193
} ;
194
194
0 commit comments