| 113 | } |
| 114 | |
| 115 | public static Number toNumber(ExecutionContext context, Object o) { |
| 116 | // 9.3 |
| 117 | if (o instanceof Number) { |
| 118 | return (Number) o; |
| 119 | } |
| 120 | |
| 121 | if (o == Types.UNDEFINED) { |
| 122 | return Double.NaN; |
| 123 | } |
| 124 | |
| 125 | if (o == Types.NULL) { |
| 126 | return 0L; |
| 127 | } |
| 128 | |
| 129 | if (o instanceof JSObject) { |
| 130 | return toNumber(context, toPrimitive(context, o, "Number")); |
| 131 | } |
| 132 | |
| 133 | if (o instanceof Boolean) { |
| 134 | if (o == Boolean.TRUE) { |
| 135 | return 1L; |
| 136 | } |
| 137 | |
| 138 | return 0L; |
| 139 | } |
| 140 | |
| 141 | Number n = stringToNumber(o.toString()); |
| 142 | return n; |
| 143 | } |
| 144 | |
| 145 | public static String trimString(String value) { |
| 146 | int len = value.length(); |