java类javax.script.ScriptException的实例源码

DebugRestHandler.java 文件源码 项目:Lavalink 阅读 19 收藏 0 点赞 0 评论 0
public DebugRestHandler() {
    engine = new ScriptEngineManager().getEngineByName("nashorn");
    try {
        engine.eval("var imports = new JavaImporter(java.io, java.lang, java.util);");
    } catch (ScriptException ex) {
        log.error("Failed setting up Nashorn", ex);
    }
}
ScriptRunner.java 文件源码 项目:VISNode 阅读 28 收藏 0 点赞 0 评论 0
/**
 * Builds the script invocable
 */
private void buildInvocable() {
    ScriptEngineManager factory = new ScriptEngineManager();
    ScriptEngine engine = factory.getEngineByName("JavaScript");
    try {
        if (hasScript()) {
            engine.eval(script.getValue());
            inv = (Invocable) engine;
        }
    } catch (ScriptException e) {
        ExceptionHandler.get().handle(e);
    }
}
BooleanAccessTest.java 文件源码 项目:openjdk-jdk10 阅读 15 收藏 0 点赞 0 评论 0
@Test
public void accessVolatileField() throws ScriptException {
    e.eval("var pv_boolean = o.volatileBoolean;");
    assertEquals(o.volatileBoolean, e.get("pv_boolean"));
    assertEquals("boolean", e.eval("typeof pv_boolean;"));
    e.eval("o.volatileBoolean = false;");
    assertEquals(false, o.volatileBoolean);
}
ECMAException.java 文件源码 项目:OpenJSharp 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Get the line number for a {@code ScriptObject} representing an error
 *
 * @param errObj the error object
 * @return the line number, or undefined if wrapped exception is not a ParserException
 */
public static Object getLineNumber(final ScriptObject errObj) {
    final Object e = getException(errObj);
    if (e instanceof NashornException) {
        return ((NashornException)e).getLineNumber();
    } else if (e instanceof ScriptException) {
        return ((ScriptException)e).getLineNumber();
    }

    return UNDEFINED;
}
StringAccessTest.java 文件源码 项目:openjdk-jdk10 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void accessFinalFieldString() throws ScriptException {
    e.eval("var pf_string = o.publicFinalString;");
    assertEquals(o.publicFinalString, e.get("pf_string"));
    assertEquals("string", e.eval("typeof pf_string;"));
    e.eval("o.publicFinalString = 'changedString';");
    assertEquals("PublicFinalString", o.publicFinalString);
}
ConsStringTest.java 文件源码 项目:openjdk-jdk10 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void testConsStringFromMirror() throws ScriptException {
    final Bindings b = e.getBindings(ScriptContext.ENGINE_SCOPE);
    //final Map<Object, Object> m = new HashMap<>();
    e.eval("var x = 'f'; x += 'oo'; var obj = {x: x};");
    assertEquals("foo", ((JSObject)b.get("obj")).getMember("x"));
}
NumberAccessTest.java 文件源码 项目:openjdk-jdk10 阅读 25 收藏 0 点赞 0 评论 0
@Test
public void accessFinalFieldByte() throws ScriptException {
    e.eval("var pf_byte = o.publicFinalByte;");
    assertEquals((double)o.publicFinalByte, ((Number)e.get("pf_byte")).doubleValue());
    e.eval("o.publicFinalByte = 16;");
    assertEquals(-7, o.publicFinalByte);
}
ScriptRouter.java 文件源码 项目:dubbocloud 阅读 21 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked")
public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
    try {
        List<Invoker<T>> invokersCopy = new ArrayList<Invoker<T>>(invokers);
        Compilable compilable = (Compilable) engine;
        Bindings bindings = engine.createBindings();
        bindings.put("invokers", invokersCopy);
        bindings.put("invocation", invocation);
        bindings.put("context", RpcContext.getContext());
        CompiledScript function = compilable.compile(rule);
        Object obj = function.eval(bindings);
        if (obj instanceof Invoker[]) {
            invokersCopy = Arrays.asList((Invoker<T>[]) obj);
        } else if (obj instanceof Object[]) {
            invokersCopy = new ArrayList<Invoker<T>>();
            for (Object inv : (Object[]) obj) {
                invokersCopy.add((Invoker<T>)inv);
            }
        } else {
            invokersCopy = (List<Invoker<T>>) obj;
        }
        return invokersCopy;
    } catch (ScriptException e) {
        //fail then ignore rule .invokers.
        logger.error("route error , rule has been ignored. rule: " + rule + ", method:" + invocation.getMethodName() + ", url: " + RpcContext.getContext().getUrl(), e);
        return invokers;
    }
}
StreamScriptLogic.java 文件源码 项目:Pogamut3 阅读 18 收藏 0 点赞 0 评论 0
/**
 * Evaluates the stream of the script.
 *
 * @param is
 * @return true if eval succeeded
 * @throws ScriptedAgentException
 */
final protected boolean evalStream(Reader reader) throws ScriptedAgentException {
    try {
        engine.eval(reader);
        return true;
    } catch (ScriptException e) {
        getLog().severe("Script error -> " + e.getMessage());
        throw new ScriptedAgentException("Script error -> " + e.getMessage(), e);
    }
}
RunScriptTest.java 文件源码 项目:butterfly 阅读 19 收藏 0 点赞 0 评论 0
@Test
public void invalidScriptTest() {
    RunScript runScript =  new RunScript("++++");
    TUExecutionResult executionResult = runScript.execution(transformedAppFolder, transformationContext);
    Assert.assertEquals(executionResult.getType(), TUExecutionResult.Type.ERROR);
    Assert.assertNull(executionResult.getValue());
    Assert.assertEquals(runScript.getDescription(), "Executes script '++++' and saves its evaluation result");
    Assert.assertEquals(runScript.getScript(), "++++");
    Assert.assertEquals(runScript.getObjects().size(), 0);
    Assert.assertEquals(runScript.getAttributes().size(), 0);
    Assert.assertEquals(runScript.getLanguage(), "js");
    Assert.assertNotNull(executionResult.getException());
    Assert.assertEquals(executionResult.getException().getClass(), ScriptException.class);
    Assert.assertEquals(executionResult.getException().getMessage(), "<eval>:1:2 Expected l-value but found ++\n++++\n  ^ in <eval> at line number 1 at column number 2");
}


问题


面经


文章

微信
公众号

扫码关注公众号