final Object toJavaScript()

in boot-script/src/main/java/net/java/html/boot/script/ScriptPresenter.java [309:350]


    final Object toJavaScript(Object toReturn, boolean arrayChecks, boolean keepAlive) {
        if (toReturn == null || !arrayChecks) {
            return toReturn;
        }
        if (toReturn.getClass().isArray()) {
            try {
                return convertArrays(toReturn);
            } catch (Exception ex) {
                throw new IllegalStateException(ex);
            }
        } else {
            if (JDK7) {
                if (toReturn instanceof Boolean) {
                    return ((Boolean)toReturn) ? true : null;
                }
            }
            if (toReturn.getClass().getSimpleName().equals("$JsCallbacks$")) { // NOI18N
                return toReturn;
            }
            if (toReturn instanceof Character) {
                return (int) (Character) toReturn;
            }
            if (
                toReturn instanceof Boolean || toReturn instanceof String ||
                toReturn instanceof Number
            ) {
                return toReturn;
            }
            if (isJSReady(toReturn)) {
                return toReturn;
            }
            if (!keepAlive) {
                toReturn = new Weak(toReturn);
            }
            String name = toReturn instanceof Enum ? toReturn.toString() : null;
            try {
                return wrapJavaObject().invokeImpl(null, false, toReturn, callback, name);
            } catch (Exception ex) {
                throw new IllegalStateException(ex);
            }
        }
    }