Java Code Examples for jdk.nashorn.internal.runtime.Context#getErr()

The following examples show how to use jdk.nashorn.internal.runtime.Context#getErr() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Shell.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * read-eval-print loop for Nashorn shell.
 *
 * @param context the nashorn context
 * @param global  global scope object to use
 * @return return code
 */
private static int readEvalPrint(final Context context, final Global global) {
    final String prompt = bundle.getString("shell.prompt");
    final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    final PrintWriter err = context.getErr();
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();

    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }

        global.addShellBuiltins();

        while (true) {
            err.print(prompt);
            err.flush();

            String source = "";
            try {
                source = in.readLine();
            } catch (final IOException ioe) {
                err.println(ioe.toString());
            }

            if (source == null) {
                break;
            }

            if (source.isEmpty()) {
                continue;
            }

            try {
                final Object res = context.eval(global, source, global, "<shell>");
                if (res != ScriptRuntime.UNDEFINED) {
                    err.println(JSType.toString(res));
                }
            } catch (final Exception e) {
                err.println(e);
                if (env._dump_on_error) {
                    e.printStackTrace(err);
                }
            }
        }
    } finally {
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
 
Example 2
Source File: Shell.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * read-eval-print loop for Nashorn shell.
 *
 * @param context the nashorn context
 * @param global  global scope object to use
 * @return return code
 */
private static int readEvalPrint(final Context context, final Global global) {
    final String prompt = bundle.getString("shell.prompt");
    final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    final PrintWriter err = context.getErr();
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();

    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }

        global.addShellBuiltins();

        while (true) {
            err.print(prompt);
            err.flush();

            String source = "";
            try {
                source = in.readLine();
            } catch (final IOException ioe) {
                err.println(ioe.toString());
            }

            if (source == null) {
                break;
            }

            if (source.isEmpty()) {
                continue;
            }

            try {
                final Object res = context.eval(global, source, global, "<shell>");
                if (res != ScriptRuntime.UNDEFINED) {
                    err.println(JSType.toString(res));
                }
            } catch (final Exception e) {
                err.println(e);
                if (env._dump_on_error) {
                    e.printStackTrace(err);
                }
            }
        }
    } finally {
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
 
Example 3
Source File: Shell.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * read-eval-print loop for Nashorn shell.
 *
 * @param context the nashorn context
 * @param global  global scope object to use
 * @return return code
 */
private static int readEvalPrint(final Context context, final Global global) {
    final String prompt = bundle.getString("shell.prompt");
    final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    final PrintWriter err = context.getErr();
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();

    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }

        global.addShellBuiltins();

        while (true) {
            err.print(prompt);
            err.flush();

            String source = "";
            try {
                source = in.readLine();
            } catch (final IOException ioe) {
                err.println(ioe.toString());
            }

            if (source == null) {
                break;
            }

            if (source.isEmpty()) {
                continue;
            }

            try {
                final Object res = context.eval(global, source, global, "<shell>");
                if (res != ScriptRuntime.UNDEFINED) {
                    err.println(JSType.toString(res));
                }
            } catch (final Exception e) {
                err.println(e);
                if (env._dump_on_error) {
                    e.printStackTrace(err);
                }
            }
        }
    } finally {
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
 
Example 4
Source File: Shell.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * read-eval-print loop for Nashorn shell.
 *
 * @param context the nashorn context
 * @param global  global scope object to use
 * @return return code
 */
private static int readEvalPrint(final Context context, final Global global) {
    final String prompt = bundle.getString("shell.prompt");
    final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    final PrintWriter err = context.getErr();
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();

    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }

        global.addShellBuiltins();

        while (true) {
            err.print(prompt);
            err.flush();

            String source = "";
            try {
                source = in.readLine();
            } catch (final IOException ioe) {
                err.println(ioe.toString());
            }

            if (source == null) {
                break;
            }

            if (source.isEmpty()) {
                continue;
            }

            try {
                final Object res = context.eval(global, source, global, "<shell>");
                if (res != ScriptRuntime.UNDEFINED) {
                    err.println(JSType.toString(res));
                }
            } catch (final Exception e) {
                err.println(e);
                if (env._dump_on_error) {
                    e.printStackTrace(err);
                }
            }
        }
    } finally {
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
 
Example 5
Source File: Shell.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * read-eval-print loop for Nashorn shell.
 *
 * @param context the nashorn context
 * @param global  global scope object to use
 * @return return code
 */
protected int readEvalPrint(final Context context, final Global global) {
    final String prompt = bundle.getString("shell.prompt");
    final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    final PrintWriter err = context.getErr();
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();

    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }

        global.addShellBuiltins();

        while (true) {
            err.print(prompt);
            err.flush();

            String source = "";
            try {
                source = in.readLine();
            } catch (final IOException ioe) {
                err.println(ioe.toString());
            }

            if (source == null) {
                break;
            }

            if (source.isEmpty()) {
                continue;
            }

            try {
                final Object res = context.eval(global, source, global, "<shell>");
                if (res != ScriptRuntime.UNDEFINED) {
                    err.println(toString(res, global));
                }
            } catch (final Exception e) {
                err.println(e);
                if (env._dump_on_error) {
                    e.printStackTrace(err);
                }
            }
        }
    } finally {
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
 
Example 6
Source File: Shell.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * read-eval-print loop for Nashorn shell.
 *
 * @param context the nashorn context
 * @param global  global scope object to use
 * @return return code
 */
private static int readEvalPrint(final Context context, final Global global) {
    final String prompt = bundle.getString("shell.prompt");
    final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    final PrintWriter err = context.getErr();
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();

    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }

        global.addShellBuiltins();

        while (true) {
            err.print(prompt);
            err.flush();

            String source = "";
            try {
                source = in.readLine();
            } catch (final IOException ioe) {
                err.println(ioe.toString());
            }

            if (source == null) {
                break;
            }

            if (source.isEmpty()) {
                continue;
            }

            try {
                final Object res = context.eval(global, source, global, "<shell>");
                if (res != ScriptRuntime.UNDEFINED) {
                    err.println(JSType.toString(res));
                }
            } catch (final Exception e) {
                err.println(e);
                if (env._dump_on_error) {
                    e.printStackTrace(err);
                }
            }
        }
    } finally {
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}
 
Example 7
Source File: Shell.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * read-eval-print loop for Nashorn shell.
 *
 * @param context the nashorn context
 * @param global  global scope object to use
 * @return return code
 */
private static int readEvalPrint(final Context context, final Global global) {
    final String prompt = bundle.getString("shell.prompt");
    final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    final PrintWriter err = context.getErr();
    final Global oldGlobal = Context.getGlobal();
    final boolean globalChanged = (oldGlobal != global);
    final ScriptEnvironment env = context.getEnv();

    try {
        if (globalChanged) {
            Context.setGlobal(global);
        }

        global.addShellBuiltins();

        while (true) {
            err.print(prompt);
            err.flush();

            String source = "";
            try {
                source = in.readLine();
            } catch (final IOException ioe) {
                err.println(ioe.toString());
            }

            if (source == null) {
                break;
            }

            if (source.isEmpty()) {
                continue;
            }

            try {
                final Object res = context.eval(global, source, global, "<shell>");
                if (res != ScriptRuntime.UNDEFINED) {
                    err.println(JSType.toString(res));
                }
            } catch (final Exception e) {
                err.println(e);
                if (env._dump_on_error) {
                    e.printStackTrace(err);
                }
            }
        }
    } finally {
        if (globalChanged) {
            Context.setGlobal(oldGlobal);
        }
    }

    return SUCCESS;
}