@@ -793,21 +793,45 @@ function createComparator (name, func) {
793
793
return {
794
794
method : ( args , context , above , engine ) => {
795
795
if ( ! Array . isArray ( args ) || args . length <= 1 ) throw INVALID_ARGUMENTS
796
- if ( args . length === 2 ) return func ( runOptimizedOrFallback ( args [ 0 ] , engine , context , above ) , runOptimizedOrFallback ( args [ 1 ] , engine , context , above ) )
796
+ if ( args . length === 2 ) {
797
+ const a = runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
798
+ const b = runOptimizedOrFallback ( args [ 1 ] , engine , context , above )
799
+ if ( typeof a !== typeof b ) {
800
+ if ( typeof a === 'string' && Number . isNaN ( + a ) ) throw NaN
801
+ if ( typeof b === 'string' && Number . isNaN ( + b ) ) throw NaN
802
+ }
803
+ return func ( a , b )
804
+ }
797
805
let prev = runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
798
806
for ( let i = 1 ; i < args . length ; i ++ ) {
799
807
const current = runOptimizedOrFallback ( args [ i ] , engine , context , above )
808
+ if ( typeof current !== typeof prev ) {
809
+ if ( typeof current === 'string' && Number . isNaN ( + current ) ) throw NaN
810
+ if ( i === 1 && typeof prev === 'string' && Number . isNaN ( + prev ) ) throw NaN
811
+ }
800
812
if ( ! func ( prev , current ) ) return false
801
813
prev = current
802
814
}
803
815
return true
804
816
} ,
805
817
asyncMethod : async ( args , context , above , engine ) => {
806
818
if ( ! Array . isArray ( args ) || args . length <= 1 ) throw INVALID_ARGUMENTS
807
- if ( args . length === 2 ) return func ( await runOptimizedOrFallback ( args [ 0 ] , engine , context , above ) , await runOptimizedOrFallback ( args [ 1 ] , engine , context , above ) )
819
+ if ( args . length === 2 ) {
820
+ const a = await runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
821
+ const b = await runOptimizedOrFallback ( args [ 1 ] , engine , context , above )
822
+ if ( typeof a !== typeof b ) {
823
+ if ( typeof a === 'string' && Number . isNaN ( + a ) ) throw NaN
824
+ if ( typeof b === 'string' && Number . isNaN ( + b ) ) throw NaN
825
+ }
826
+ return func ( a , b )
827
+ }
808
828
let prev = await runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
809
829
for ( let i = 1 ; i < args . length ; i ++ ) {
810
830
const current = await runOptimizedOrFallback ( args [ i ] , engine , context , above )
831
+ if ( typeof current !== typeof prev ) {
832
+ if ( typeof current === 'string' && Number . isNaN ( + current ) ) throw NaN
833
+ if ( i === 1 && typeof prev === 'string' && Number . isNaN ( + prev ) ) throw NaN
834
+ }
811
835
if ( ! func ( prev , current ) ) return false
812
836
prev = current
813
837
}
@@ -816,9 +840,9 @@ function createComparator (name, func) {
816
840
compile : ( data , buildState ) => {
817
841
if ( ! Array . isArray ( data ) ) return false
818
842
if ( data . length < 2 ) return false
819
- if ( data . length === 2 ) return buildState . compile `(${ data [ 0 ] } ${ opStr } ${ data [ 1 ] } )`
820
- let res = buildState . compile `(${ data [ 0 ] } ${ opStr } (prev = ${ data [ 1 ] } ))`
821
- for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && prev ${ opStr } (prev = ${ data [ i ] } ))`
843
+ if ( data . length === 2 ) return buildState . compile `((prev = ${ data [ 0 ] } ) ${ opStr } compareCheck( ${ data [ 1 ] } , prev) )`
844
+ let res = buildState . compile `((prev = ${ data [ 0 ] } ) ${ opStr } (prev = compareCheck( ${ data [ 1 ] } , prev) ))`
845
+ for ( let i = 2 ; i < data . length ; i ++ ) res = buildState . compile `(${ res } && prev ${ opStr } (prev = compareCheck( ${ data [ i ] } , prev) ))`
822
846
return res
823
847
} ,
824
848
[ OriginalImpl ] : true ,
0 commit comments