class JavaScriptUtils {

  public static Number jsToNumber( Object value, String classType ) {
    if ( classType.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) {
      return null;
    } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) {
      try {
        return (Double) Context.jsToJava( value, Double.class );
      } catch ( Exception e ) {
        String string = Context.toString( value );
        return Double.parseDouble( Const.trim( string ) );
      }
    } else if ( classType.equalsIgnoreCase( "org.mozilla.javascript.NativeNumber" ) ) {
      Number nb = Context.toNumber( value );
      return nb.doubleValue();
    } else {
      Number nb = (Number) value;
      return nb.doubleValue();
    }
  }

}