Skip to content

Commit bd08ede

Browse files
cjihrigBethGriggs
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 <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 2b03878 commit bd08ede

1 file changed

Lines changed: 29 additions & 33 deletions

File tree

‎lib/internal/buffer.js‎

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

2727
functioncheckBounds(buf,offset,byteLength){
28-
checkNumberType(offset);
28+
validateNumber(offset,'offset');
2929
if(buf[offset]===undefined||buf[offset+byteLength]===undefined)
3030
boundsError(offset,buf.length-(byteLength+1));
3131
}
@@ -37,13 +37,9 @@ function checkInt(value, min, max, buf, offset, byteLength) {
3737
checkBounds(buf,offset,byteLength);
3838
}
3939

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

@@ -74,7 +70,7 @@ function readUIntLE(offset, byteLength) {
7470
}
7571

7672
functionreadUInt48LE(buf,offset=0){
77-
checkNumberType(offset);
73+
validateNumber(offset,'offset');
7874
constfirst=buf[offset];
7975
constlast=buf[offset+5];
8076
if(first===undefined||last===undefined)
@@ -88,7 +84,7 @@ function readUInt48LE(buf, offset = 0) {
8884
}
8985

9086
functionreadUInt40LE(buf,offset=0){
91-
checkNumberType(offset);
87+
validateNumber(offset,'offset');
9288
constfirst=buf[offset];
9389
constlast=buf[offset+4];
9490
if(first===undefined||last===undefined)
@@ -102,7 +98,7 @@ function readUInt40LE(buf, offset = 0) {
10298
}
10399

104100
functionreadUInt32LE(offset=0){
105-
checkNumberType(offset);
101+
validateNumber(offset,'offset');
106102
constfirst=this[offset];
107103
constlast=this[offset+3];
108104
if(first===undefined||last===undefined)
@@ -115,7 +111,7 @@ function readUInt32LE(offset = 0) {
115111
}
116112

117113
functionreadUInt24LE(buf,offset=0){
118-
checkNumberType(offset);
114+
validateNumber(offset,'offset');
119115
constfirst=buf[offset];
120116
constlast=buf[offset+2];
121117
if(first===undefined||last===undefined)
@@ -125,7 +121,7 @@ function readUInt24LE(buf, offset = 0) {
125121
}
126122

127123
functionreadUInt16LE(offset=0){
128-
checkNumberType(offset);
124+
validateNumber(offset,'offset');
129125
constfirst=this[offset];
130126
constlast=this[offset+1];
131127
if(first===undefined||last===undefined)
@@ -135,7 +131,7 @@ function readUInt16LE(offset = 0) {
135131
}
136132

137133
functionreadUInt8(offset=0){
138-
checkNumberType(offset);
134+
validateNumber(offset,'offset');
139135
constval=this[offset];
140136
if(val===undefined)
141137
boundsError(offset,this.length-1);
@@ -161,7 +157,7 @@ function readUIntBE(offset, byteLength) {
161157
}
162158

163159
functionreadUInt48BE(buf,offset=0){
164-
checkNumberType(offset);
160+
validateNumber(offset,'offset');
165161
constfirst=buf[offset];
166162
constlast=buf[offset+5];
167163
if(first===undefined||last===undefined)
@@ -175,7 +171,7 @@ function readUInt48BE(buf, offset = 0) {
175171
}
176172

177173
functionreadUInt40BE(buf,offset=0){
178-
checkNumberType(offset);
174+
validateNumber(offset,'offset');
179175
constfirst=buf[offset];
180176
constlast=buf[offset+4];
181177
if(first===undefined||last===undefined)
@@ -189,7 +185,7 @@ function readUInt40BE(buf, offset = 0) {
189185
}
190186

191187
functionreadUInt32BE(offset=0){
192-
checkNumberType(offset);
188+
validateNumber(offset,'offset');
193189
constfirst=this[offset];
194190
constlast=this[offset+3];
195191
if(first===undefined||last===undefined)
@@ -202,7 +198,7 @@ function readUInt32BE(offset = 0) {
202198
}
203199

204200
functionreadUInt24BE(buf,offset=0){
205-
checkNumberType(offset);
201+
validateNumber(offset,'offset');
206202
constfirst=buf[offset];
207203
constlast=buf[offset+2];
208204
if(first===undefined||last===undefined)
@@ -212,7 +208,7 @@ function readUInt24BE(buf, offset = 0) {
212208
}
213209

214210
functionreadUInt16BE(offset=0){
215-
checkNumberType(offset);
211+
validateNumber(offset,'offset');
216212
constfirst=this[offset];
217213
constlast=this[offset+1];
218214
if(first===undefined||last===undefined)
@@ -239,7 +235,7 @@ function readIntLE(offset, byteLength) {
239235
}
240236

241237
functionreadInt48LE(buf,offset=0){
242-
checkNumberType(offset);
238+
validateNumber(offset,'offset');
243239
constfirst=buf[offset];
244240
constlast=buf[offset+5];
245241
if(first===undefined||last===undefined)
@@ -254,7 +250,7 @@ function readInt48LE(buf, offset = 0) {
254250
}
255251

256252
functionreadInt40LE(buf,offset=0){
257-
checkNumberType(offset);
253+
validateNumber(offset,'offset');
258254
constfirst=buf[offset];
259255
constlast=buf[offset+4];
260256
if(first===undefined||last===undefined)
@@ -268,7 +264,7 @@ function readInt40LE(buf, offset = 0) {
268264
}
269265

270266
functionreadInt32LE(offset=0){
271-
checkNumberType(offset);
267+
validateNumber(offset,'offset');
272268
constfirst=this[offset];
273269
constlast=this[offset+3];
274270
if(first===undefined||last===undefined)
@@ -281,7 +277,7 @@ function readInt32LE(offset = 0) {
281277
}
282278

283279
functionreadInt24LE(buf,offset=0){
284-
checkNumberType(offset);
280+
validateNumber(offset,'offset');
285281
constfirst=buf[offset];
286282
constlast=buf[offset+2];
287283
if(first===undefined||last===undefined)
@@ -292,7 +288,7 @@ function readInt24LE(buf, offset = 0) {
292288
}
293289

294290
functionreadInt16LE(offset=0){
295-
checkNumberType(offset);
291+
validateNumber(offset,'offset');
296292
constfirst=this[offset];
297293
constlast=this[offset+1];
298294
if(first===undefined||last===undefined)
@@ -303,7 +299,7 @@ function readInt16LE(offset = 0) {
303299
}
304300

305301
functionreadInt8(offset=0){
306-
checkNumberType(offset);
302+
validateNumber(offset,'offset');
307303
constval=this[offset];
308304
if(val===undefined)
309305
boundsError(offset,this.length-1);
@@ -329,7 +325,7 @@ function readIntBE(offset, byteLength) {
329325
}
330326

331327
functionreadInt48BE(buf,offset=0){
332-
checkNumberType(offset);
328+
validateNumber(offset,'offset');
333329
constfirst=buf[offset];
334330
constlast=buf[offset+5];
335331
if(first===undefined||last===undefined)
@@ -344,7 +340,7 @@ function readInt48BE(buf, offset = 0) {
344340
}
345341

346342
functionreadInt40BE(buf,offset=0){
347-
checkNumberType(offset);
343+
validateNumber(offset,'offset');
348344
constfirst=buf[offset];
349345
constlast=buf[offset+4];
350346
if(first===undefined||last===undefined)
@@ -358,7 +354,7 @@ function readInt40BE(buf, offset = 0) {
358354
}
359355

360356
functionreadInt32BE(offset=0){
361-
checkNumberType(offset);
357+
validateNumber(offset,'offset');
362358
constfirst=this[offset];
363359
constlast=this[offset+3];
364360
if(first===undefined||last===undefined)
@@ -371,7 +367,7 @@ function readInt32BE(offset = 0) {
371367
}
372368

373369
functionreadInt24BE(buf,offset=0){
374-
checkNumberType(offset);
370+
validateNumber(offset,'offset');
375371
constfirst=buf[offset];
376372
constlast=buf[offset+2];
377373
if(first===undefined||last===undefined)
@@ -382,7 +378,7 @@ function readInt24BE(buf, offset = 0) {
382378
}
383379

384380
functionreadInt16BE(offset=0){
385-
checkNumberType(offset);
381+
validateNumber(offset,'offset');
386382
constfirst=this[offset];
387383
constlast=this[offset+1];
388384
if(first===undefined||last===undefined)
@@ -394,7 +390,7 @@ function readInt16BE(offset = 0) {
394390

395391
// Read floats
396392
functionreadFloatBackwards(offset=0){
397-
checkNumberType(offset);
393+
validateNumber(offset,'offset');
398394
constfirst=this[offset];
399395
constlast=this[offset+3];
400396
if(first===undefined||last===undefined)
@@ -408,7 +404,7 @@ function readFloatBackwards(offset = 0) {
408404
}
409405

410406
functionreadFloatForwards(offset=0){
411-
checkNumberType(offset);
407+
validateNumber(offset,'offset');
412408
constfirst=this[offset];
413409
constlast=this[offset+3];
414410
if(first===undefined||last===undefined)
@@ -422,7 +418,7 @@ function readFloatForwards(offset = 0) {
422418
}
423419

424420
functionreadDoubleBackwards(offset=0){
425-
checkNumberType(offset);
421+
validateNumber(offset,'offset');
426422
constfirst=this[offset];
427423
constlast=this[offset+7];
428424
if(first===undefined||last===undefined)
@@ -440,7 +436,7 @@ function readDoubleBackwards(offset = 0) {
440436
}
441437

442438
functionreadDoubleForwards(offset=0){
443-
checkNumberType(offset);
439+
validateNumber(offset,'offset');
444440
constfirst=this[offset];
445441
constlast=this[offset+7];
446442
if(first===undefined||last===undefined)
@@ -554,7 +550,7 @@ function writeUInt16LE(value, offset = 0) {
554550
functionwriteU_Int8(buf,value,offset,min,max){
555551
value=+value;
556552
// `checkInt()` can not be used here because it checks two entries.
557-
checkNumberType(offset);
553+
validateNumber(offset,'offset');
558554
if(value>max||value<min){
559555
thrownewERR_OUT_OF_RANGE('value',`>= ${min} and <= ${max}`,value);
560556
}

0 commit comments

Comments
 (0)