@@ -108,7 +108,6 @@ const {
108108 ERR_UNKNOWN_ENCODING ,
109109 } ,
110110 genericNodeError,
111- hideStackFrames,
112111} = require ( 'internal/errors' ) ;
113112const {
114113 validateArray,
@@ -386,19 +385,12 @@ Buffer.of = of;
386385
387386ObjectSetPrototypeOf ( Buffer , Uint8Array ) ;
388387
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-
396388/**
397389 * Creates a new filled Buffer instance.
398390 * alloc(size[, fill[, encoding]])
399391 */
400392Buffer . alloc = function alloc ( size , fill , encoding ) {
401- assertSize ( size ) ;
393+ validateNumber ( size , 'size' , 0 , kMaxLength ) ;
402394 if ( fill !== undefined && fill !== 0 && size > 0 ) {
403395 const buf = createUnsafeBuffer ( size ) ;
404396 return _fill ( buf , fill , 0 , buf . length , encoding ) ;
@@ -411,7 +403,7 @@ Buffer.alloc = function alloc(size, fill, encoding) {
411403 * instance. If `--zero-fill-buffers` is set, will zero-fill the buffer.
412404 */
413405Buffer . allocUnsafe = function allocUnsafe ( size ) {
414- assertSize ( size ) ;
406+ validateNumber ( size , 'size' , 0 , kMaxLength ) ;
415407 return allocate ( size ) ;
416408} ;
417409
@@ -421,15 +413,15 @@ Buffer.allocUnsafe = function allocUnsafe(size) {
421413 * If `--zero-fill-buffers` is set, will zero-fill the buffer.
422414 */
423415Buffer . allocUnsafeSlow = function allocUnsafeSlow ( size ) {
424- assertSize ( size ) ;
416+ validateNumber ( size , 'size' , 0 , kMaxLength ) ;
425417 return createUnsafeBuffer ( size ) ;
426418} ;
427419
428420// If --zero-fill-buffers command line argument is set, a zero-filled
429421// 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 ) ;
433425}
434426
435427ObjectSetPrototypeOf ( SlowBuffer . prototype , Uint8ArrayPrototype ) ;
0 commit comments