Example usage for jdk.nashorn.api.scripting NashornException NashornException

List of usage examples for jdk.nashorn.api.scripting NashornException NashornException

Introduction

In this page you can find the example usage for jdk.nashorn.api.scripting NashornException NashornException.

Prototype

protected NashornException(final String msg, final Throwable cause) 

Source Link

Document

Constructor to initialize error message and cause exception.

Usage

From source file:reactor.js.test.NashornJUnitTestRunner.java

License:Open Source License

private static void addStaticMethods(Class<?> type, Bindings bindings) {
    for (Method method : type.getDeclaredMethods()) {
        if (Modifier.isStatic(method.getModifiers())) {
            final Method methodToInvoke = method;
            method.setAccessible(true);/*from  w ww.jav a2  s.  co m*/
            bindings.put(method.getName(), new AbstractJSObject() {
                @Override
                public Object call(Object thiz, Object... args) {
                    try {
                        return methodToInvoke.invoke(null, args);
                    } catch (Exception e) {
                        return new NashornException(e.getMessage(), e) {
                        };
                    }
                }

                @Override
                public boolean isFunction() {
                    return true;
                }

                @Override
                public boolean isStrictFunction() {
                    return true;
                }
            });
        }
    }
}