Nashorn implements JavascriptEngine<ScriptEngine> { @Override public Object executeFunction(String name, Object... parameters) { try { return ((Invocable) engine).invokeFunction(name, parameters); } catch (ScriptException | NoSuchMethodException e) { log.error("Error executing function [" + name + "]", e); } return null; }  @Override void setScriptAlias(String alias); @Override void startRuntime(); @Override void executeScript(String script); @Override Object executeFunction(String name, Object... parameters); @Override void closeRuntime(); @Override ScriptEngine getEngine(); @Override void registerCallback(ISender sender, IPipeLineSession session); @Override void setResultHandler(ResultHandler resultHandler);  }
@Test public void testExecuteFunction() { String script = "function plusTwo(x) { return x + 2;}"; engine.executeScript(script); Double out = (Double) engine.executeFunction("plusTwo", 5); Assert.assertEquals(7.0, out, 0.0); }
@Test public void testExecuteFunctionUnknownFunc() { Double out = (Double) engine.executeFunction("plusTwo"); Assert.assertNull(out); }