com.eclipsesource.v8.V8RuntimeException Java Examples

The following examples show how to use com.eclipsesource.v8.V8RuntimeException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: V8ScriptRunner.java    From citeproc-java with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T callMethod(String name, Class<T> resultType, Object... args)
        throws ScriptRunnerException {
    Set<V8Value> newValues = new HashSet<>();
    V8Array parameters = convertArguments(args, newValues);
    try {
        if (String.class.isAssignableFrom(resultType)) {
            return (T)runtime.executeStringFunction(name, parameters);
        }
        return convert(runtime.executeObjectFunction(name, parameters), resultType);
    } catch (V8RuntimeException e) {
        throw new ScriptRunnerException("Could not call method", e);
    } finally {
        newValues.forEach(V8Value::release);
    }
}
 
Example #2
Source File: V8ScriptRunner.java    From citeproc-java with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T callMethod(Object obj, String name, Class<T> resultType,
        Object... args) throws ScriptRunnerException {
    Set<V8Value> newValues = new HashSet<>();
    V8Array parameters = convertArguments(args, newValues);
    try {
        V8Object vo = (V8Object)obj;
        if (String.class.isAssignableFrom(resultType)) {
            return (T)vo.executeStringFunction(name, parameters);
        }
        return convert(vo.executeObjectFunction(name, parameters), resultType);
    } catch (V8RuntimeException e) {
        throw new ScriptRunnerException("Could not call method", e);
    } finally {
        newValues.forEach(V8Value::release);
    }
}
 
Example #3
Source File: V8JavascriptEngine.java    From graphviz-java with Apache License 2.0 5 votes vote down vote up
@Override
protected String execute(String js) {
    try {
        v8.executeVoidScript(js);
        return resultHandler.waitFor();
    } catch (V8RuntimeException e) {
        throw new GraphvizException("Problem executing javascript", e);
    }
}
 
Example #4
Source File: V8ScriptRunner.java    From citeproc-java with Apache License 2.0 5 votes vote down vote up
@Override
public void callMethod(String name, Object... args)
        throws ScriptRunnerException {
    Set<V8Value> newValues = new HashSet<>();
    V8Array parameters = convertArguments(args, newValues);
    try {
        runtime.executeVoidFunction(name, parameters);
    } catch (V8RuntimeException e) {
        throw new ScriptRunnerException("Could not call method", e);
    } finally {
        newValues.forEach(V8Value::release);
    }
}
 
Example #5
Source File: V8ScriptRunner.java    From citeproc-java with Apache License 2.0 5 votes vote down vote up
@Override
public void callMethod(Object obj, String name, Object... args)
        throws ScriptRunnerException {
    Set<V8Value> newValues = new HashSet<>();
    V8Array parameters = convertArguments(args, newValues);
    try {
        ((V8Object)obj).executeVoidFunction(name, parameters);
    } catch (V8RuntimeException e) {
        throw new ScriptRunnerException("Could not call method", e);
    } finally {
        newValues.forEach(V8Value::release);
    }
}