Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8034892 nashorn compatibility issues
  3. JDK-8035181

No 'println' in global scope when executing script via javax.script

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • None
    • core-libs
    • None

      import java.io.*;
      import javax.script.*;

      public class Jtest6{

          public static void main(String[] args){
              ScriptEngineManager factory = new ScriptEngineManager();
              ScriptEngine js = factory.getEngineByName("JavaScript");
              Object obj = null;
              try {
                  obj = js.eval("function f(a){println(a);return a;}");
                  obj = js.eval("f(1)");
              } catch (ScriptException e){
                  System.out.printf("exception %s\n",e);
              }
          }
      }

      results in

      exception javax.script.ScriptException: ReferenceError: "println" is not defined in <eval> at line number 1

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

              Created:
              Updated:
              Resolved: