Don't need to copy this code. Use 
try {return toBoolean(Object)} catch (IllegalArgumentException e) {return def}
See https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/util/TiConvert.java#L387 for reference.