nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java
changeset 29283 fb47e4d25a9f
parent 29282 a8523237b66c
child 29627 03fe257ba844
equal deleted inserted replaced
29282:a8523237b66c 29283:fb47e4d25a9f
   759             return ((Number)obj).doubleValue();
   759             return ((Number)obj).doubleValue();
   760         }
   760         }
   761         return toNumberGeneric(obj);
   761         return toNumberGeneric(obj);
   762     }
   762     }
   763 
   763 
       
   764     /**
       
   765      * Converts an object for a comparison with a number. Almost identical to {@link #toNumber(Object)} but
       
   766      * converts {@code null} to {@code NaN} instead of zero, so it won't compare equal to zero.
       
   767      *
       
   768      * @param obj  an object
       
   769      *
       
   770      * @return a number
       
   771      */
       
   772     public static double toNumberForEq(final Object obj) {
       
   773         return obj == null ? Double.NaN : toNumber(obj);
       
   774     }
       
   775 
       
   776     /**
       
   777      * Converts an object for strict comparison with a number. Returns {@code NaN} for any object that is not
       
   778      * a {@link Number}, so only boxed numerics can compare strictly equal to numbers.
       
   779      *
       
   780      * @param obj  an object
       
   781      *
       
   782      * @return a number
       
   783      */
       
   784     public static double toNumberForStrictEq(final Object obj) {
       
   785         if (obj instanceof Double) {
       
   786             return (Double)obj;
       
   787         }
       
   788         if (obj instanceof Number) {
       
   789             return ((Number)obj).doubleValue();
       
   790         }
       
   791         return Double.NaN;
       
   792     }
       
   793 
   764 
   794 
   765     /**
   795     /**
   766      * JavaScript compliant conversion of Boolean to number
   796      * JavaScript compliant conversion of Boolean to number
   767      * See ECMA 9.3 ToNumber
   797      * See ECMA 9.3 ToNumber
   768      *
   798      *