Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8023551

Mirror functions can not be invoked using invokeMethod, invokeFunction

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P3
    • Resolution: Fixed
    • 8
    • 8
    • core-libs
    • None
    • b106
    • generic
    • generic

    Description

      Test script:

      <pre>

      var m = new javax.script.ScriptEngineManager();
      var e = m.getEngineByName("nashorn");

      function func(x) {
         print("func: " + x);
      }

      e.put("func", func);
      e.invokeFunction("func", "hello");

      var obj = e.eval("({ foo: func })");
      e.invokeMethod(obj, "foo", "world");

      </pre>
      Exception trace is as follows:

      Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchMethodException: No such function func
      at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:368)
      at jdk.nashorn.tools.Shell.apply(Shell.java:386)
      at jdk.nashorn.tools.Shell.runScripts(Shell.java:315)
      at jdk.nashorn.tools.Shell.run(Shell.java:179)
      at jdk.nashorn.tools.Shell.main(Shell.java:143)
      at jdk.nashorn.tools.Shell.main(Shell.java:122)
      Caused by: java.lang.NoSuchMethodException: No such function func
      at jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:92)
      at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:434)
      at jdk.nashorn.api.scripting.NashornScriptEngine.invokeFunction(NashornScriptEngine.java:200)
      at jdk.nashorn.internal.scripts.Script$test.runScript(test.js:9)
      at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:518)
      at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:204)
      at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:364)
      ... 5 more

      Attachments

        Activity

          People

            sundar Sundararajan Athijegannathan
            sundar Sundararajan Athijegannathan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: