本文整理汇总了Java中jdk.nashorn.internal.objects.Global.addShellBuiltins方法的典型用法代码示例。如果您正苦于以下问题:Java Global.addShellBuiltins方法的具体用法?Java Global.addShellBuiltins怎么用?Java Global.addShellBuiltins使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.objects.Global
的用法示例。
在下文中一共展示了Global.addShellBuiltins方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readEvalPrint
import jdk.nashorn.internal.objects.Global; //导入方法依赖的package包/类
/**
* 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;
}