400 /**
401 * read-eval-print loop for Nashorn shell.
402 *
403 * @param context the nashorn context
404 * @param global global scope object to use
405 * @return return code
406 */
407 private static int readEvalPrint(final Context context, final Global global) {
408 final String prompt = bundle.getString("shell.prompt");
409 final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
410 final PrintWriter err = context.getErr();
411 final Global oldGlobal = Context.getGlobal();
412 final boolean globalChanged = (oldGlobal != global);
413 final ScriptEnvironment env = context.getEnv();
414
415 try {
416 if (globalChanged) {
417 Context.setGlobal(global);
418 }
419
420 // initialize with "shell.js" script
421 try {
422 final Source source = sourceFor("<shell.js>", Shell.class.getResource("resources/shell.js"));
423 context.eval(global, source.getString(), global, "<shell.js>", false);
424 } catch (final Exception e) {
425 err.println(e);
426 if (env._dump_on_error) {
427 e.printStackTrace(err);
428 }
429
430 return INTERNAL_ERROR;
431 }
432
433 while (true) {
434 err.print(prompt);
435 err.flush();
436
437 String source = "";
438 try {
439 source = in.readLine();
440 } catch (final IOException ioe) {
441 err.println(ioe.toString());
442 }
443
444 if (source == null) {
445 break;
446 }
447
448 if (source.isEmpty()) {
449 continue;
450 }
451
|
400 /**
401 * read-eval-print loop for Nashorn shell.
402 *
403 * @param context the nashorn context
404 * @param global global scope object to use
405 * @return return code
406 */
407 private static int readEvalPrint(final Context context, final Global global) {
408 final String prompt = bundle.getString("shell.prompt");
409 final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
410 final PrintWriter err = context.getErr();
411 final Global oldGlobal = Context.getGlobal();
412 final boolean globalChanged = (oldGlobal != global);
413 final ScriptEnvironment env = context.getEnv();
414
415 try {
416 if (globalChanged) {
417 Context.setGlobal(global);
418 }
419
420 global.addShellBuiltins();
421
422 while (true) {
423 err.print(prompt);
424 err.flush();
425
426 String source = "";
427 try {
428 source = in.readLine();
429 } catch (final IOException ioe) {
430 err.println(ioe.toString());
431 }
432
433 if (source == null) {
434 break;
435 }
436
437 if (source.isEmpty()) {
438 continue;
439 }
440
|