本文整理汇总了Java中jdk.nashorn.internal.runtime.ErrorManager.error方法的典型用法代码示例。如果您正苦于以下问题:Java ErrorManager.error方法的具体用法?Java ErrorManager.error怎么用?Java ErrorManager.error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.ErrorManager
的用法示例。
在下文中一共展示了ErrorManager.error方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runScripts
import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
/**
* Runs the given JavaScript files in the command line
*
* @param context the nashorn context
* @param global the global scope
* @param files the list of script files to run
*
* @return error code
* @throws IOException when any script file read results in I/O error
*/
private int runScripts(final Context context, final Global global, final List<String> files) throws IOException {
final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
if (globalChanged) {
Context.setGlobal(global);
}
final ErrorManager errors = context.getErrorManager();
// For each file on the command line.
for (final String fileName : files) {
if ("-".equals(fileName)) {
final int res = readEvalPrint(context, global);
if (res != SUCCESS) {
return res;
}
continue;
}
final File file = new File(fileName);
final ScriptFunction script = context.compileScript(sourceFor(fileName, file), global);
if (script == null || errors.getNumberOfErrors() != 0) {
return COMPILATION_ERROR;
}
try {
apply(script, global);
} catch (final NashornException e) {
errors.error(e.toString());
if (context.getEnv()._dump_on_error) {
e.printStackTrace(context.getErr());
}
return RUNTIME_ERROR;
}
}
} finally {
context.getOut().flush();
context.getErr().flush();
if (globalChanged) {
Context.setGlobal(oldGlobal);
}
}
return SUCCESS;
}
示例2: runScripts
import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
/**
* Runs the given JavaScript files in the command line
*
* @param context the nashorn context
* @param global the global scope
* @param files the list of script files to run
*
* @return error code
* @throws IOException when any script file read results in I/O error
*/
private int runScripts(final Context context, final Global global, final List<String> files) throws IOException {
final Global oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
if (globalChanged) {
Context.setGlobal(global);
}
final ErrorManager errors = context.getErrorManager();
// For each file on the command line.
for (final String fileName : files) {
if ("-".equals(fileName)) {
final int res = readEvalPrint(context, global);
if (res != SUCCESS) {
return res;
}
continue;
}
final File file = new File(fileName);
final ScriptFunction script = context.compileScript(sourceFor(fileName, file), global);
if (script == null || errors.getNumberOfErrors() != 0) {
if (context.getEnv()._parse_only && !errors.hasErrors()) {
continue; // No error, continue to consume all files in list
}
return COMPILATION_ERROR;
}
try {
apply(script, global);
} catch (final NashornException e) {
errors.error(e.toString());
if (context.getEnv()._dump_on_error) {
e.printStackTrace(context.getErr());
}
return RUNTIME_ERROR;
}
}
} finally {
context.getOut().flush();
context.getErr().flush();
if (globalChanged) {
Context.setGlobal(oldGlobal);
}
}
return SUCCESS;
}
示例3: run
import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
@Override
public int run(final OutputStream out, final OutputStream err, final String[] args) throws IOException {
final Global oldGlobal = Context.getGlobal();
try {
ctxOut.setDelegatee(out);
ctxErr.setDelegatee(err);
final ErrorManager errors = context.getErrorManager();
final Global global = context.createGlobal();
Context.setGlobal(global);
// For each file on the command line.
for (final String fileName : args) {
if (fileName.startsWith("-")) {
// ignore options in shared context mode (which was initialized upfront!)
continue;
}
final File file = new File(fileName);
final ScriptFunction script = context.compileScript(sourceFor(fileName, file.toURI().toURL()), global);
if (script == null || errors.getNumberOfErrors() != 0) {
return COMPILATION_ERROR;
}
try {
ScriptRuntime.apply(script, global);
} catch (final NashornException e) {
errors.error(e.toString());
if (context.getEnv()._dump_on_error) {
e.printStackTrace(context.getErr());
}
return RUNTIME_ERROR;
}
}
} finally {
context.getOut().flush();
context.getErr().flush();
Context.setGlobal(oldGlobal);
}
return SUCCESS;
}
示例4: runScripts
import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
/**
* Runs the given JavaScript files in the command line
*
* @param context the nashorn context
* @param global the global scope
* @param files the list of script files to run
*
* @return error code
* @throws IOException when any script file read results in I/O error
*/
private int runScripts(final Context context, final ScriptObject global, final List<String> files) throws IOException {
final ScriptObject oldGlobal = Context.getGlobal();
final boolean globalChanged = (oldGlobal != global);
try {
if (globalChanged) {
Context.setGlobal(global);
}
final ErrorManager errors = context.getErrorManager();
// For each file on the command line.
for (final String fileName : files) {
if ("-".equals(fileName)) {
final int res = readEvalPrint(context, global);
if (res != SUCCESS) {
return res;
}
continue;
}
final File file = new File(fileName);
final ScriptFunction script = context.compileScript(new Source(fileName, file.toURI().toURL()), global);
if (script == null || errors.getNumberOfErrors() != 0) {
return COMPILATION_ERROR;
}
try {
apply(script, global);
} catch (final NashornException e) {
errors.error(e.toString());
if (context.getEnv()._dump_on_error) {
e.printStackTrace(context.getErr());
}
return RUNTIME_ERROR;
}
}
} finally {
context.getOut().flush();
context.getErr().flush();
if (globalChanged) {
Context.setGlobal(oldGlobal);
}
}
return SUCCESS;
}
示例5: run
import jdk.nashorn.internal.runtime.ErrorManager; //导入方法依赖的package包/类
@Override
public int run(final OutputStream out, final OutputStream err, final String[] args) throws IOException {
final ScriptObject oldGlobal = Context.getGlobal();
try {
ctxOut.setDelegatee(out);
ctxErr.setDelegatee(err);
final ErrorManager errors = context.getErrorManager();
final ScriptObject global = context.createGlobal();
Context.setGlobal(global);
// For each file on the command line.
for (final String fileName : args) {
if (fileName.startsWith("-")) {
// ignore options in shared context mode (which was initialized upfront!)
continue;
}
final File file = new File(fileName);
ScriptFunction script = context.compileScript(new Source(fileName, file.toURI().toURL()), global);
if (script == null || errors.getNumberOfErrors() != 0) {
return COMPILATION_ERROR;
}
try {
ScriptRuntime.apply(script, global);
} catch (final NashornException e) {
errors.error(e.toString());
if (context.getEnv()._dump_on_error) {
e.printStackTrace(context.getErr());
}
return RUNTIME_ERROR;
}
}
} finally {
context.getOut().flush();
context.getErr().flush();
Context.setGlobal(oldGlobal);
}
return SUCCESS;
}