title: Java code cannot invoke method from scriptengine with new context
body: <p>I am trying to implement example invoking method from Javascript in Java.</p>
  
  <pre><code>private static final String JS = "function doit(p) { list.add(p); return true; }";
  
  public static void main(String[] args) throws ScriptException, NoSuchMethodException {
      List&lt;String&gt; list = new ArrayList&lt;&gt;();
  
  
      ScriptEngineManager scriptManager = new ScriptEngineManager();
      ScriptEngine engine = scriptManager.getEngineByName("nashorn");
  
      ScriptContext context = new SimpleScriptContext();
      context.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
      Bindings scope = context.getBindings(ScriptContext.ENGINE_SCOPE);
  
      scope.put("list", list);
      engine.eval(JS, context);
  
      Invocable invocable = (Invocable) engine;
      invocable.invokeFunction("doit", "Hello!!!");
  
      System.out.println(list.size());
  }
  }
  </code></pre>
  
  <p>This code throws exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoSuchMethodException: No such function doit
      at jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:204)
      at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:383)
      at jdk.nashorn.api.scripting.NashornScriptEngine.invokeFunction(NashornScriptEngine.java:190)
      at testjavascriptinteraction.TestJavaScript.main(TestJavaScript.java:32)
  </code></pre>
  
  <h3>Version</h3>
  
  <pre><code>java -version
  openjdk version "1.8.0_91"
  OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)
  OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
  </code></pre>
  
  <p>What is wrong? </p>