@@ -108,7 +108,6 @@ const {
108
108
ERR_UNKNOWN_ENCODING ,
109
109
} ,
110
110
genericNodeError,
111
- hideStackFrames,
112
111
} = require ( 'internal/errors' ) ;
113
112
const {
114
113
validateArray,
@@ -386,19 +385,12 @@ Buffer.of = of;
386
385
387
386
ObjectSetPrototypeOf ( Buffer , Uint8Array ) ;
388
387
389
- // The 'assertSize' method will remove itself from the callstack when an error
390
- // occurs. This is done simply to keep the internal details of the
391
- // implementation from bleeding out to users.
392
- const assertSize = hideStackFrames ( ( size ) => {
393
- validateNumber ( size , 'size' , 0 , kMaxLength ) ;
394
- } ) ;
395
-
396
388
/**
397
389
* Creates a new filled Buffer instance.
398
390
* alloc(size[, fill[, encoding]])
399
391
*/
400
392
Buffer . alloc = function alloc ( size , fill , encoding ) {
401
- assertSize ( size ) ;
393
+ validateNumber ( size , 'size' , 0 , kMaxLength ) ;
402
394
if ( fill !== undefined && fill !== 0 && size > 0 ) {
403
395
const buf = createUnsafeBuffer ( size ) ;
404
396
return _fill ( buf , fill , 0 , buf . length , encoding ) ;
@@ -411,7 +403,7 @@ Buffer.alloc = function alloc(size, fill, encoding) {
411
403
* instance. If `--zero-fill-buffers` is set, will zero-fill the buffer.
412
404
*/
413
405
Buffer . allocUnsafe = function allocUnsafe ( size ) {
414
- assertSize ( size ) ;
406
+ validateNumber ( size , 'size' , 0 , kMaxLength ) ;
415
407
return allocate ( size ) ;
416
408
} ;
417
409
@@ -421,15 +413,15 @@ Buffer.allocUnsafe = function allocUnsafe(size) {
421
413
* If `--zero-fill-buffers` is set, will zero-fill the buffer.
422
414
*/
423
415
Buffer . allocUnsafeSlow = function allocUnsafeSlow ( size ) {
424
- assertSize ( size ) ;
416
+ validateNumber ( size , 'size' , 0 , kMaxLength ) ;
425
417
return createUnsafeBuffer ( size ) ;
426
418
} ;
427
419
428
420
// If --zero-fill-buffers command line argument is set, a zero-filled
429
421
// buffer is returned.
430
- function SlowBuffer ( length ) {
431
- assertSize ( length ) ;
432
- return createUnsafeBuffer ( length ) ;
422
+ function SlowBuffer ( size ) {
423
+ validateNumber ( size , 'size' , 0 , kMaxLength ) ;
424
+ return createUnsafeBuffer ( size ) ;
433
425
}
434
426
435
427
ObjectSetPrototypeOf ( SlowBuffer . prototype , Uint8ArrayPrototype ) ;
0 commit comments