nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java
changeset 29282 a8523237b66c
parent 29133 1cd7d8af99ba
child 29283 fb47e4d25a9f
equal deleted inserted replaced
29281:8cc2618a07aa 29282:a8523237b66c
   309 
   309 
   310         if (obj instanceof Boolean) {
   310         if (obj instanceof Boolean) {
   311             return JSType.BOOLEAN;
   311             return JSType.BOOLEAN;
   312         }
   312         }
   313 
   313 
   314         if (obj instanceof String || obj instanceof ConsString) {
   314         if (isString(obj)) {
   315             return JSType.STRING;
   315             return JSType.STRING;
   316         }
   316         }
   317 
   317 
   318         if (obj instanceof Number) {
   318         if (obj instanceof Number) {
   319             return JSType.NUMBER;
   319             return JSType.NUMBER;
   347 
   347 
   348         if (obj instanceof Boolean) {
   348         if (obj instanceof Boolean) {
   349             return JSType.BOOLEAN;
   349             return JSType.BOOLEAN;
   350         }
   350         }
   351 
   351 
   352         if (obj instanceof String || obj instanceof ConsString) {
   352         if (isString(obj)) {
   353             return JSType.STRING;
   353             return JSType.STRING;
   354         }
   354         }
   355 
   355 
   356         if (obj instanceof Number) {
   356         if (obj instanceof Number) {
   357             return JSType.NUMBER;
   357             return JSType.NUMBER;
   453     public static boolean isPrimitive(final Object obj) {
   453     public static boolean isPrimitive(final Object obj) {
   454         return obj == null ||
   454         return obj == null ||
   455                obj == ScriptRuntime.UNDEFINED ||
   455                obj == ScriptRuntime.UNDEFINED ||
   456                obj instanceof Boolean ||
   456                obj instanceof Boolean ||
   457                obj instanceof Number ||
   457                obj instanceof Number ||
   458                obj instanceof String ||
   458                isString(obj);
   459                obj instanceof ConsString;
       
   460     }
   459     }
   461 
   460 
   462    /**
   461    /**
   463     * Primitive converter for an object
   462     * Primitive converter for an object
   464     *
   463     *
   575         if (obj instanceof Number) {
   574         if (obj instanceof Number) {
   576             final double num = ((Number)obj).doubleValue();
   575             final double num = ((Number)obj).doubleValue();
   577             return num != 0 && !Double.isNaN(num);
   576             return num != 0 && !Double.isNaN(num);
   578         }
   577         }
   579 
   578 
   580         if (obj instanceof String || obj instanceof ConsString) {
   579         if (isString(obj)) {
   581             return ((CharSequence)obj).length() > 0;
   580             return ((CharSequence)obj).length() > 0;
   582         }
   581         }
   583 
   582 
   584         return true;
   583         return true;
   585     }
   584     }
   623             Double.parseDouble(str);
   622             Double.parseDouble(str);
   624             return true;
   623             return true;
   625         } catch (final NumberFormatException e) {
   624         } catch (final NumberFormatException e) {
   626             return false;
   625             return false;
   627         }
   626         }
       
   627     }
       
   628 
       
   629     /**
       
   630      * Returns true if object represents a primitive JavaScript string value.
       
   631      * @param obj the object
       
   632      * @return true if the object represents a primitive JavaScript string value.
       
   633      */
       
   634     public static boolean isString(final Object obj) {
       
   635         return obj instanceof String || obj instanceof ConsString;
   628     }
   636     }
   629 
   637 
   630     /**
   638     /**
   631      * JavaScript compliant conversion of integer to String
   639      * JavaScript compliant conversion of integer to String
   632      *
   640      *