@@ -36,7 +36,6 @@ const {
3636 Map,
3737 MathMax,
3838 Number,
39- NumberIsSafeInteger,
4039 ObjectCreate,
4140 ObjectDefineProperties,
4241 ObjectDefineProperty,
@@ -69,7 +68,8 @@ const {
6968 ERR_INVALID_ARG_VALUE ,
7069 ERR_INVALID_ARG_TYPE ,
7170 ERR_INVALID_CALLBACK ,
72- ERR_FEATURE_UNAVAILABLE_ON_PLATFORM
71+ ERR_FEATURE_UNAVAILABLE_ON_PLATFORM ,
72+ ERR_OUT_OF_RANGE ,
7373 } ,
7474 hideStackFrames,
7575 uvErrmapGet,
@@ -553,9 +553,23 @@ function read(fd, buffer, offset, length, position, callback) {
553553
554554 validateOffsetLengthRead ( offset , length , buffer . byteLength ) ;
555555
556- if ( ! NumberIsSafeInteger ( position ) )
556+ if ( position == null )
557557 position = - 1 ;
558558
559+ if ( typeof position === 'number' ) {
560+ validateInteger ( position , 'position' ) ;
561+ } else if ( typeof position === 'bigint' ) {
562+ if ( ! ( position >= - ( 2n ** 63n ) && position <= 2n ** 63n - 1n ) ) {
563+ throw new ERR_OUT_OF_RANGE ( 'position' ,
564+ `>= ${ - ( 2n ** 63n ) } && <= ${ 2n ** 63n - 1n } ` ,
565+ position ) ;
566+ }
567+ } else {
568+ throw new ERR_INVALID_ARG_TYPE ( 'position' ,
569+ [ 'integer' , 'bigint' ] ,
570+ position ) ;
571+ }
572+
559573 function wrapper ( err , bytesRead ) {
560574 // Retain a reference to buffer so that it can't be GC'ed too soon.
561575 callback ( err , bytesRead || 0 , buffer ) ;
@@ -605,9 +619,23 @@ function readSync(fd, buffer, offset, length, position) {
605619
606620 validateOffsetLengthRead ( offset , length , buffer . byteLength ) ;
607621
608- if ( ! NumberIsSafeInteger ( position ) )
622+ if ( position == null )
609623 position = - 1 ;
610624
625+ if ( typeof position === 'number' ) {
626+ validateInteger ( position , 'position' ) ;
627+ } else if ( typeof position === 'bigint' ) {
628+ if ( ! ( position >= - ( 2n ** 63n ) && position <= 2n ** 63n - 1n ) ) {
629+ throw new ERR_OUT_OF_RANGE ( 'position' ,
630+ `>= ${ - ( 2n ** 63n ) } && <= ${ 2n ** 63n - 1n } ` ,
631+ position ) ;
632+ }
633+ } else {
634+ throw new ERR_INVALID_ARG_TYPE ( 'position' ,
635+ [ 'integer' , 'bigint' ] ,
636+ position ) ;
637+ }
638+
611639 const ctx = { } ;
612640 const result = binding . read ( fd , buffer , offset , length , position ,
613641 undefined , ctx ) ;
0 commit comments