MCPcopy Create free account
hub / github.com/dynjs/dynjs / toBoolean

Method toBoolean

src/main/java/org/dynjs/runtime/Types.java:265–296  ·  view source on GitHub ↗
(Object o)

Source from the content-addressed store, hash-verified

263 }
264
265 public static Boolean toBoolean(Object o) {
266 // 9.2
267 if (o instanceof Boolean) {
268 return (Boolean) o;
269 }
270
271 if (o == Types.UNDEFINED || o == Types.NULL) {
272 return false;
273 }
274 if (o instanceof Double) {
275 if (((Double) o).isNaN() || ((Double) o).doubleValue() == 0.0) {
276 return false;
277 }
278 return true;
279 }
280
281 if (o instanceof Number) {
282 if (((Number) o).intValue() == 0) {
283 return false;
284 }
285 return true;
286 }
287 if (o instanceof String) {
288 return (((String) o).length() != 0);
289 }
290
291 if (o instanceof JSObject) {
292 return true;
293 }
294
295 return true;
296 }
297
298 public static Long toInteger(ExecutionContext context, Object o) {
299 Number number = toNumber(context, o);

Callers 14

interpretMethod · 0.95
interpretMethod · 0.95
interpretMethod · 0.95
interpretMethod · 0.95
interpretMethod · 0.95
interpretMethod · 0.95
interpretMethod · 0.95
interpretMethod · 0.95
toPropertyDescriptorMethod · 0.95
callMethod · 0.95
callMethod · 0.95
callMethod · 0.95

Calls 2

lengthMethod · 0.80
isNaNMethod · 0.45

Tested by

no test coverage detected