本文整理匯總了Java中org.mozilla.javascript.Context.reportError方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.reportError方法的具體用法?Java Context.reportError怎麽用?Java Context.reportError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.mozilla.javascript.Context
的用法示例。
在下文中一共展示了Context.reportError方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: evalInlineScript
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
static void evalInlineScript(Context cx, String scriptText) {
try {
Script script = cx.compileString(scriptText, "<command>", 1, null);
if (script != null) {
script.exec(cx, getShellScope());
}
} catch (RhinoException rex) {
ToolErrorReporter.reportException(
cx.getErrorReporter(), rex);
exitCode = EXITCODE_RUNTIME_ERROR;
} catch (VirtualMachineError ex) {
// Treat StackOverflow and OutOfMemory as runtime errors
ex.printStackTrace();
String msg = ToolErrorReporter.getMessage(
"msg.uncaughtJSException", ex.toString());
Context.reportError(msg);
exitCode = EXITCODE_RUNTIME_ERROR;
}
}
示例2: processFileNoThrow
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public static void processFileNoThrow(Context cx, Scriptable scope, String filename) {
try {
processFile(cx, scope, filename);
} catch (IOException ioex) {
Context.reportError(ToolErrorReporter.getMessage(
"msg.couldnt.read.source", filename, ioex.getMessage()));
exitCode = EXITCODE_FILE_NOT_FOUND;
} catch (RhinoException rex) {
ToolErrorReporter.reportException(
cx.getErrorReporter(), rex);
exitCode = EXITCODE_RUNTIME_ERROR;
} catch (VirtualMachineError ex) {
// Treat StackOverflow and OutOfMemory as runtime errors
ex.printStackTrace();
String msg = ToolErrorReporter.getMessage(
"msg.uncaughtJSException", ex.toString());
Context.reportError(msg);
exitCode = EXITCODE_RUNTIME_ERROR;
}
}
示例3: loadScriptFromSource
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public static Script loadScriptFromSource(Context cx, String scriptSource,
String path, int lineno,
Object securityDomain)
{
try {
return cx.compileString(scriptSource, path, lineno,
securityDomain);
} catch (EvaluatorException ee) {
// Already printed message.
exitCode = EXITCODE_RUNTIME_ERROR;
} catch (RhinoException rex) {
ToolErrorReporter.reportException(
cx.getErrorReporter(), rex);
exitCode = EXITCODE_RUNTIME_ERROR;
} catch (VirtualMachineError ex) {
// Treat StackOverflow and OutOfMemory as runtime errors
ex.printStackTrace();
String msg = ToolErrorReporter.getMessage(
"msg.uncaughtJSException", ex.toString());
exitCode = EXITCODE_RUNTIME_ERROR;
Context.reportError(msg);
}
return null;
}
示例4: evaluateScript
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public static Object evaluateScript(Script script, Context cx,
Scriptable scope)
{
try {
return script.exec(cx, scope);
} catch (RhinoException rex) {
ToolErrorReporter.reportException(
cx.getErrorReporter(), rex);
exitCode = EXITCODE_RUNTIME_ERROR;
} catch (VirtualMachineError ex) {
// Treat StackOverflow and OutOfMemory as runtime errors
ex.printStackTrace();
String msg = ToolErrorReporter.getMessage(
"msg.uncaughtJSException", ex.toString());
exitCode = EXITCODE_RUNTIME_ERROR;
Context.reportError(msg);
}
return Context.getUndefinedValue();
}
示例5: processFiles
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
static void processFiles(Context cx, String[] args) {
// define "arguments" array in the top-level object:
// need to allocate new array since newArray requires instances
// of exactly Object[], not ObjectSubclass[]
Object[] array = new Object[args.length];
System.arraycopy(args, 0, array, 0, args.length);
Scriptable argsObj = cx.newArray(global, array);
global.defineProperty("arguments", argsObj,
ScriptableObject.DONTENUM);
for (String file : fileList) {
try {
processSource(cx, file);
} catch (IOException ioex) {
Context.reportError(ToolErrorReporter.getMessage(
"msg.couldnt.read.source", file, ioex.getMessage()));
exitCode = EXITCODE_FILE_NOT_FOUND;
} catch (RhinoException rex) {
ToolErrorReporter.reportException(
cx.getErrorReporter(), rex);
exitCode = EXITCODE_RUNTIME_ERROR;
} catch (VirtualMachineError ex) {
// Treat StackOverflow and OutOfMemory as runtime errors
ex.printStackTrace();
String msg = ToolErrorReporter.getMessage(
"msg.uncaughtJSException", ex.toString());
Context.reportError(msg);
exitCode = EXITCODE_RUNTIME_ERROR;
}
}
}
示例6: loadCompiledScript
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private static Script loadCompiledScript(Context cx, String path,
byte[] data, Object securityDomain)
throws FileNotFoundException {
if (data == null) {
throw new FileNotFoundException(path);
}
// XXX: For now extract class name of compiled Script from path
// instead of parsing class bytes
int nameStart = path.lastIndexOf('/');
if (nameStart < 0) {
nameStart = 0;
} else {
++nameStart;
}
int nameEnd = path.lastIndexOf('.');
if (nameEnd < nameStart) {
// '.' does not exist in path (nameEnd < 0)
// or it comes before nameStart
nameEnd = path.length();
}
String name = path.substring(nameStart, nameEnd);
try {
GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain);
Class<?> clazz = loader.defineClass(name, data);
loader.linkClass(clazz);
if (!Script.class.isAssignableFrom(clazz)) {
throw Context.reportRuntimeError("msg.must.implement.Script");
}
return (Script) clazz.newInstance();
} catch (IllegalAccessException iaex) {
Context.reportError(iaex.toString());
throw new RuntimeException(iaex);
} catch (InstantiationException inex) {
Context.reportError(inex.toString());
throw new RuntimeException(inex);
}
}
示例7: readFileOrUrl
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
/**
* Read file or url specified by <tt>path</tt>.
* @return file or url content as <tt>byte[]</tt> or as <tt>String</tt> if
* <tt>convertToString</tt> is true.
*/
private static Object readFileOrUrl(String path, boolean convertToString)
{
try {
return SourceReader.readFileOrUrl(path, convertToString,
shellContextFactory.getCharacterEncoding());
} catch (IOException ex) {
Context.reportError(ToolErrorReporter.getMessage(
"msg.couldnt.read.source", path, ex.getMessage()));
return null;
}
}
示例8: loadCompiledScript
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private static Script loadCompiledScript(Context cx, String path,
byte[] data, Object securityDomain)
{
if (data == null) {
exitCode = EXITCODE_FILE_NOT_FOUND;
return null;
}
// XXX: For now extract class name of compiled Script from path
// instead of parsing class bytes
int nameStart = path.lastIndexOf('/');
if (nameStart < 0) {
nameStart = 0;
} else {
++nameStart;
}
int nameEnd = path.lastIndexOf('.');
if (nameEnd < nameStart) {
// '.' does not exist in path (nameEnd < 0)
// or it comes before nameStart
nameEnd = path.length();
}
String name = path.substring(nameStart, nameEnd);
try {
GeneratedClassLoader loader = SecurityController.createLoader(cx.getApplicationClassLoader(), securityDomain);
Class<?> clazz = loader.defineClass(name, data);
loader.linkClass(clazz);
if (!Script.class.isAssignableFrom(clazz)) {
throw Context.reportRuntimeError("msg.must.implement.Script");
}
return (Script) clazz.newInstance();
} catch (RhinoException rex) {
ToolErrorReporter.reportException(
cx.getErrorReporter(), rex);
exitCode = EXITCODE_RUNTIME_ERROR;
} catch (IllegalAccessException iaex) {
exitCode = EXITCODE_RUNTIME_ERROR;
Context.reportError(iaex.toString());
} catch (InstantiationException inex) {
exitCode = EXITCODE_RUNTIME_ERROR;
Context.reportError(inex.toString());
}
return null;
}