< prev index next >

src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Main.java

Print this page




  68         }
  69     }
  70 
  71     /**
  72      * Starting point for executing a {@code Shell}. Starts a shell with the
  73      * given arguments and streams and lets it run until exit.
  74      *
  75      * @param in input stream for Shell
  76      * @param out output stream for Shell
  77      * @param err error stream for Shell
  78      * @param args arguments to Shell
  79      *
  80      * @return exit code
  81      *
  82      * @throws IOException if there's a problem setting up the streams
  83      */
  84     public static int main(final InputStream in, final OutputStream out, final OutputStream err, final String[] args) throws IOException {
  85         return new Main().run(in, out, err, args);
  86     }
  87 

  88     /**
  89      * read-eval-print loop for Nashorn shell.
  90      *
  91      * @param context the nashorn context
  92      * @param global  global scope object to use
  93      * @return return code
  94      */
  95     protected int readEvalPrint(final Context context, final Global global) {
  96         final ScriptEnvironment env = context.getEnv();
  97         final String prompt = bundle.getString("shell.prompt");
  98         final PrintWriter err = context.getErr();
  99         final Global oldGlobal = Context.getGlobal();
 100         final boolean globalChanged = (oldGlobal != global);
 101         final Completer completer = new NashornCompleter(context, global);
 102 
 103         try (final Console in = new Console(System.in, System.out, HIST_FILE, completer)) {
 104             if (globalChanged) {
 105                 Context.setGlobal(global);
 106             }
 107 
 108             global.addShellBuiltins();
 109             // expose history object for reflecting on command line history
 110             global.put("history", new HistoryObject(in.getHistory()), false);
 111 
 112             while (true) {
 113                 String source = "";
 114                 try {
 115                     source = in.readLine(prompt);
 116                 } catch (final IOException ioe) {
 117                     err.println(ioe.toString());
 118                     if (env._dump_on_error) {
 119                         ioe.printStackTrace(err);
 120                     }
 121                     return IO_ERROR;




  68         }
  69     }
  70 
  71     /**
  72      * Starting point for executing a {@code Shell}. Starts a shell with the
  73      * given arguments and streams and lets it run until exit.
  74      *
  75      * @param in input stream for Shell
  76      * @param out output stream for Shell
  77      * @param err error stream for Shell
  78      * @param args arguments to Shell
  79      *
  80      * @return exit code
  81      *
  82      * @throws IOException if there's a problem setting up the streams
  83      */
  84     public static int main(final InputStream in, final OutputStream out, final OutputStream err, final String[] args) throws IOException {
  85         return new Main().run(in, out, err, args);
  86     }
  87 
  88 
  89     /**
  90      * read-eval-print loop for Nashorn shell.
  91      *
  92      * @param context the nashorn context
  93      * @param global  global scope object to use
  94      * @return return code
  95      */
  96     protected int readEvalPrint(final Context context, final Global global) {
  97         final ScriptEnvironment env = context.getEnv();
  98         final String prompt = bundle.getString("shell.prompt");
  99         final PrintWriter err = context.getErr();
 100         final Global oldGlobal = Context.getGlobal();
 101         final boolean globalChanged = (oldGlobal != global);
 102         final Completer completer = new NashornCompleter(context, global, this);
 103 
 104         try (final Console in = new Console(System.in, System.out, HIST_FILE, completer)) {
 105             if (globalChanged) {
 106                 Context.setGlobal(global);
 107             }
 108 
 109             global.addShellBuiltins();
 110             // expose history object for reflecting on command line history
 111             global.put("history", new HistoryObject(in.getHistory()), false);
 112 
 113             while (true) {
 114                 String source = "";
 115                 try {
 116                     source = in.readLine(prompt);
 117                 } catch (final IOException ioe) {
 118                     err.println(ioe.toString());
 119                     if (env._dump_on_error) {
 120                         ioe.printStackTrace(err);
 121                     }
 122                     return IO_ERROR;


< prev index next >