@@ -793,21 +793,45 @@ function createComparator (name, func) {
793793 return {
794794 method : ( args , context , above , engine ) => {
795795 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+ }
797805 let prev = runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
798806 for ( let i = 1 ; i < args . length ; i ++ ) {
799807 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+ }
800812 if ( ! func ( prev , current ) ) return false
801813 prev = current
802814 }
803815 return true
804816 } ,
805817 asyncMethod : async ( args , context , above , engine ) => {
806818 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+ }
808828 let prev = await runOptimizedOrFallback ( args [ 0 ] , engine , context , above )
809829 for ( let i = 1 ; i < args . length ; i ++ ) {
810830 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+ }
811835 if ( ! func ( prev , current ) ) return false
812836 prev = current
813837 }
@@ -816,9 +840,9 @@ function createComparator (name, func) {
816840 compile : ( data , buildState ) => {
817841 if ( ! Array . isArray ( data ) ) return false
818842 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) ))`
822846 return res
823847 } ,
824848 [ OriginalImpl ] : true ,
0 commit comments