Skip to content

Commit 73786c8

Browse files
cjihrigBridgeAR
authored andcommitted
buffer: remove checkNumberType()
checkNumberType() was a very thin wrapper around validateNumber(). This commit removes checkNumberType() and used validateNumber() directly instead. PR-URL: #24815 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 1ea01c5 commit 73786c8

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

‎lib/internal/buffer.js‎

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ float32Array[0] = -1; // 0xBF800000
2626
constbigEndian=uInt8Float32Array[3]===0;
2727

2828
functioncheckBounds(buf,offset,byteLength){
29-
checkNumberType(offset);
29+
validateNumber(offset,'offset');
3030
if(buf[offset]===undefined||buf[offset+byteLength]===undefined)
3131
boundsError(offset,buf.length-(byteLength+1));
3232
}
@@ -38,13 +38,9 @@ function checkInt(value, min, max, buf, offset, byteLength){
3838
checkBounds(buf,offset,byteLength);
3939
}
4040

41-
functioncheckNumberType(value,type){
42-
validateNumber(value,type||'offset');
43-
}
44-
4541
functionboundsError(value,length,type){
4642
if(Math.floor(value)!==value){
47-
checkNumberType(value,type);
43+
validateNumber(value,type);
4844
thrownewERR_OUT_OF_RANGE(type||'offset','an integer',value);
4945
}
5046

@@ -77,7 +73,7 @@ function readUIntLE(offset, byteLength){
7773
}
7874

7975
functionreadUInt48LE(buf,offset=0){
80-
checkNumberType(offset);
76+
validateNumber(offset,'offset');
8177
constfirst=buf[offset];
8278
constlast=buf[offset+5];
8379
if(first===undefined||last===undefined)
@@ -91,7 +87,7 @@ function readUInt48LE(buf, offset = 0){
9187
}
9288

9389
functionreadUInt40LE(buf,offset=0){
94-
checkNumberType(offset);
90+
validateNumber(offset,'offset');
9591
constfirst=buf[offset];
9692
constlast=buf[offset+4];
9793
if(first===undefined||last===undefined)
@@ -105,7 +101,7 @@ function readUInt40LE(buf, offset = 0){
105101
}
106102

107103
functionreadUInt32LE(offset=0){
108-
checkNumberType(offset);
104+
validateNumber(offset,'offset');
109105
constfirst=this[offset];
110106
constlast=this[offset+3];
111107
if(first===undefined||last===undefined)
@@ -118,7 +114,7 @@ function readUInt32LE(offset = 0){
118114
}
119115

120116
functionreadUInt24LE(buf,offset=0){
121-
checkNumberType(offset);
117+
validateNumber(offset,'offset');
122118
constfirst=buf[offset];
123119
constlast=buf[offset+2];
124120
if(first===undefined||last===undefined)
@@ -128,7 +124,7 @@ function readUInt24LE(buf, offset = 0){
128124
}
129125

130126
functionreadUInt16LE(offset=0){
131-
checkNumberType(offset);
127+
validateNumber(offset,'offset');
132128
constfirst=this[offset];
133129
constlast=this[offset+1];
134130
if(first===undefined||last===undefined)
@@ -138,7 +134,7 @@ function readUInt16LE(offset = 0){
138134
}
139135

140136
functionreadUInt8(offset=0){
141-
checkNumberType(offset);
137+
validateNumber(offset,'offset');
142138
constval=this[offset];
143139
if(val===undefined)
144140
boundsError(offset,this.length-1);
@@ -166,7 +162,7 @@ function readUIntBE(offset, byteLength){
166162
}
167163

168164
functionreadUInt48BE(buf,offset=0){
169-
checkNumberType(offset);
165+
validateNumber(offset,'offset');
170166
constfirst=buf[offset];
171167
constlast=buf[offset+5];
172168
if(first===undefined||last===undefined)
@@ -180,7 +176,7 @@ function readUInt48BE(buf, offset = 0){
180176
}
181177

182178
functionreadUInt40BE(buf,offset=0){
183-
checkNumberType(offset);
179+
validateNumber(offset,'offset');
184180
constfirst=buf[offset];
185181
constlast=buf[offset+4];
186182
if(first===undefined||last===undefined)
@@ -194,7 +190,7 @@ function readUInt40BE(buf, offset = 0){
194190
}
195191

196192
functionreadUInt32BE(offset=0){
197-
checkNumberType(offset);
193+
validateNumber(offset,'offset');
198194
constfirst=this[offset];
199195
constlast=this[offset+3];
200196
if(first===undefined||last===undefined)
@@ -207,7 +203,7 @@ function readUInt32BE(offset = 0){
207203
}
208204

209205
functionreadUInt24BE(buf,offset=0){
210-
checkNumberType(offset);
206+
validateNumber(offset,'offset');
211207
constfirst=buf[offset];
212208
constlast=buf[offset+2];
213209
if(first===undefined||last===undefined)
@@ -217,7 +213,7 @@ function readUInt24BE(buf, offset = 0){
217213
}
218214

219215
functionreadUInt16BE(offset=0){
220-
checkNumberType(offset);
216+
validateNumber(offset,'offset');
221217
constfirst=this[offset];
222218
constlast=this[offset+1];
223219
if(first===undefined||last===undefined)
@@ -246,7 +242,7 @@ function readIntLE(offset, byteLength){
246242
}
247243

248244
functionreadInt48LE(buf,offset=0){
249-
checkNumberType(offset);
245+
validateNumber(offset,'offset');
250246
constfirst=buf[offset];
251247
constlast=buf[offset+5];
252248
if(first===undefined||last===undefined)
@@ -261,7 +257,7 @@ function readInt48LE(buf, offset = 0){
261257
}
262258

263259
functionreadInt40LE(buf,offset=0){
264-
checkNumberType(offset);
260+
validateNumber(offset,'offset');
265261
constfirst=buf[offset];
266262
constlast=buf[offset+4];
267263
if(first===undefined||last===undefined)
@@ -275,7 +271,7 @@ function readInt40LE(buf, offset = 0){
275271
}
276272

277273
functionreadInt32LE(offset=0){
278-
checkNumberType(offset);
274+
validateNumber(offset,'offset');
279275
constfirst=this[offset];
280276
constlast=this[offset+3];
281277
if(first===undefined||last===undefined)
@@ -288,7 +284,7 @@ function readInt32LE(offset = 0){
288284
}
289285

290286
functionreadInt24LE(buf,offset=0){
291-
checkNumberType(offset);
287+
validateNumber(offset,'offset');
292288
constfirst=buf[offset];
293289
constlast=buf[offset+2];
294290
if(first===undefined||last===undefined)
@@ -299,7 +295,7 @@ function readInt24LE(buf, offset = 0){
299295
}
300296

301297
functionreadInt16LE(offset=0){
302-
checkNumberType(offset);
298+
validateNumber(offset,'offset');
303299
constfirst=this[offset];
304300
constlast=this[offset+1];
305301
if(first===undefined||last===undefined)
@@ -310,7 +306,7 @@ function readInt16LE(offset = 0){
310306
}
311307

312308
functionreadInt8(offset=0){
313-
checkNumberType(offset);
309+
validateNumber(offset,'offset');
314310
constval=this[offset];
315311
if(val===undefined)
316312
boundsError(offset,this.length-1);
@@ -338,7 +334,7 @@ function readIntBE(offset, byteLength){
338334
}
339335

340336
functionreadInt48BE(buf,offset=0){
341-
checkNumberType(offset);
337+
validateNumber(offset,'offset');
342338
constfirst=buf[offset];
343339
constlast=buf[offset+5];
344340
if(first===undefined||last===undefined)
@@ -353,7 +349,7 @@ function readInt48BE(buf, offset = 0){
353349
}
354350

355351
functionreadInt40BE(buf,offset=0){
356-
checkNumberType(offset);
352+
validateNumber(offset,'offset');
357353
constfirst=buf[offset];
358354
constlast=buf[offset+4];
359355
if(first===undefined||last===undefined)
@@ -367,7 +363,7 @@ function readInt40BE(buf, offset = 0){
367363
}
368364

369365
functionreadInt32BE(offset=0){
370-
checkNumberType(offset);
366+
validateNumber(offset,'offset');
371367
constfirst=this[offset];
372368
constlast=this[offset+3];
373369
if(first===undefined||last===undefined)
@@ -380,7 +376,7 @@ function readInt32BE(offset = 0){
380376
}
381377

382378
functionreadInt24BE(buf,offset=0){
383-
checkNumberType(offset);
379+
validateNumber(offset,'offset');
384380
constfirst=buf[offset];
385381
constlast=buf[offset+2];
386382
if(first===undefined||last===undefined)
@@ -391,7 +387,7 @@ function readInt24BE(buf, offset = 0){
391387
}
392388

393389
functionreadInt16BE(offset=0){
394-
checkNumberType(offset);
390+
validateNumber(offset,'offset');
395391
constfirst=this[offset];
396392
constlast=this[offset+1];
397393
if(first===undefined||last===undefined)
@@ -403,7 +399,7 @@ function readInt16BE(offset = 0){
403399

404400
// Read floats
405401
functionreadFloatBackwards(offset=0){
406-
checkNumberType(offset);
402+
validateNumber(offset,'offset');
407403
constfirst=this[offset];
408404
constlast=this[offset+3];
409405
if(first===undefined||last===undefined)
@@ -417,7 +413,7 @@ function readFloatBackwards(offset = 0){
417413
}
418414

419415
functionreadFloatForwards(offset=0){
420-
checkNumberType(offset);
416+
validateNumber(offset,'offset');
421417
constfirst=this[offset];
422418
constlast=this[offset+3];
423419
if(first===undefined||last===undefined)
@@ -431,7 +427,7 @@ function readFloatForwards(offset = 0){
431427
}
432428

433429
functionreadDoubleBackwards(offset=0){
434-
checkNumberType(offset);
430+
validateNumber(offset,'offset');
435431
constfirst=this[offset];
436432
constlast=this[offset+7];
437433
if(first===undefined||last===undefined)
@@ -449,7 +445,7 @@ function readDoubleBackwards(offset = 0){
449445
}
450446

451447
functionreadDoubleForwards(offset=0){
452-
checkNumberType(offset);
448+
validateNumber(offset,'offset');
453449
constfirst=this[offset];
454450
constlast=this[offset+7];
455451
if(first===undefined||last===undefined)
@@ -563,7 +559,7 @@ function writeUInt16LE(value, offset = 0){
563559
functionwriteU_Int8(buf,value,offset,min,max){
564560
value=+value;
565561
// `checkInt()` can not be used here because it checks two entries.
566-
checkNumberType(offset);
562+
validateNumber(offset,'offset');
567563
if(value>max||value<min){
568564
thrownewERR_OUT_OF_RANGE('value',`>= ${min} and <= ${max}`,value);
569565
}

0 commit comments

Comments
(0)