public static Number toNumber(Object o) {
if (o == null) return new Long(0);
if (o instanceof Number) return ((Number)o);
- // FIXME: There are about 3 pages of rules in ecma262 about string to number conversions
- // We aren't even close to following all those rules
+
+ // NOTE: There are about 3 pages of rules in ecma262 about string to number conversions
+ // We aren't even close to following all those rules. We probably never will be.
if (o instanceof String) try { return new Double((String)o); } catch (NumberFormatException e) { return new Double(Double.NaN); }
if (o instanceof Boolean) return ((Boolean)o).booleanValue() ? new Long(1) : new Long(0);
if (o instanceof JS) return ((JS)o).coerceToNumber();