@@ -37,7 +37,6 @@ const {
3737 BigIntPrototypeToString,
3838 MathMax,
3939 Number,
40- NumberIsSafeInteger,
4140 ObjectCreate,
4241 ObjectDefineProperties,
4342 ObjectDefineProperty,
@@ -75,7 +74,8 @@ const {
7574 ERR_FS_FILE_TOO_LARGE ,
7675 ERR_INVALID_ARG_VALUE ,
7776 ERR_INVALID_ARG_TYPE ,
78- ERR_FEATURE_UNAVAILABLE_ON_PLATFORM
77+ ERR_FEATURE_UNAVAILABLE_ON_PLATFORM ,
78+ ERR_OUT_OF_RANGE ,
7979 } ,
8080 hideStackFrames,
8181 uvErrmapGet,
@@ -545,9 +545,23 @@ function read(fd, buffer, offset, length, position, callback) {
545545
546546 validateOffsetLengthRead ( offset , length , buffer . byteLength ) ;
547547
548- if ( ! NumberIsSafeInteger ( position ) )
548+ if ( position == null )
549549 position = - 1 ;
550550
551+ if ( typeof position === 'number' ) {
552+ validateInteger ( position , 'position' ) ;
553+ } else if ( typeof position === 'bigint' ) {
554+ if ( ! ( position >= - ( 2n ** 63n ) && position <= 2n ** 63n - 1n ) ) {
555+ throw new ERR_OUT_OF_RANGE ( 'position' ,
556+ `>= ${ - ( 2n ** 63n ) } && <= ${ 2n ** 63n - 1n } ` ,
557+ position ) ;
558+ }
559+ } else {
560+ throw new ERR_INVALID_ARG_TYPE ( 'position' ,
561+ [ 'integer' , 'bigint' ] ,
562+ position ) ;
563+ }
564+
551565 function wrapper ( err , bytesRead ) {
552566 // Retain a reference to buffer so that it can't be GC'ed too soon.
553567 callback ( err , bytesRead || 0 , buffer ) ;
@@ -597,9 +611,23 @@ function readSync(fd, buffer, offset, length, position) {
597611
598612 validateOffsetLengthRead ( offset , length , buffer . byteLength ) ;
599613
600- if ( ! NumberIsSafeInteger ( position ) )
614+ if ( position == null )
601615 position = - 1 ;
602616
617+ if ( typeof position === 'number' ) {
618+ validateInteger ( position , 'position' ) ;
619+ } else if ( typeof position === 'bigint' ) {
620+ if ( ! ( position >= - ( 2n ** 63n ) && position <= 2n ** 63n - 1n ) ) {
621+ throw new ERR_OUT_OF_RANGE ( 'position' ,
622+ `>= ${ - ( 2n ** 63n ) } && <= ${ 2n ** 63n - 1n } ` ,
623+ position ) ;
624+ }
625+ } else {
626+ throw new ERR_INVALID_ARG_TYPE ( 'position' ,
627+ [ 'integer' , 'bigint' ] ,
628+ position ) ;
629+ }
630+
603631 const ctx = { } ;
604632 const result = binding . read ( fd , buffer , offset , length , position ,
605633 undefined , ctx ) ;
0 commit comments