Java源码示例:com.eclipsesource.v8.V8RuntimeException

示例1
@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);
    }
}
 
示例2
@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);
    }
}
 
示例3
@Override
protected String execute(String js) {
    try {
        v8.executeVoidScript(js);
        return resultHandler.waitFor();
    } catch (V8RuntimeException e) {
        throw new GraphvizException("Problem executing javascript", e);
    }
}
 
示例4
@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);
    }
}
 
示例5
@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);
    }
}