@Test
public void intArrayLengthTest() throws ScriptException {
Map<String, Object> vars = new HashMap<String, Object>();
Integer[] l = new Integer[] { 1,2,3 };
vars.put("l", l);
String script = "l.length";
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("nashorn");
ScriptContext context = engine.getContext();
Bindings bindings = context.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.putAll(vars);
Compilable compilable = (Compilable)engine;
CompiledScript compiledScript = compilable.compile(script);
Object o = compiledScript.eval();
assertThat(((Number) o).intValue(), equalTo(3));
}
NashornTests.java 文件源码
java
阅读 21
收藏 0
点赞 0
评论 0
项目:elasticsearch-lang-javascript-nashorn
作者:
评论列表
文章目录