本文整理汇总了Java中jdk.nashorn.api.scripting.NashornException类的典型用法代码示例。如果您正苦于以下问题:Java NashornException类的具体用法?Java NashornException怎么用?Java NashornException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NashornException类属于jdk.nashorn.api.scripting包,在下文中一共展示了NashornException类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runFXScripts
import jdk.nashorn.api.scripting.NashornException; //导入依赖的package包/类
/**
* Runs launches "fx:bootstrap.js" with the given JavaScript files provided
* as arguments.
*
* @param context the nashorn context
* @param global the global scope
* @param files the list of script files to provide
*
* @return error code
* @throws IOException when any script file read results in I/O error
*/
private static int runFXScripts(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);
}
global.addOwnProperty("$GLOBAL", Property.NOT_ENUMERABLE, global);
global.addOwnProperty("$SCRIPTS", Property.NOT_ENUMERABLE, files);
context.load(global, "fx:bootstrap.js");
} catch (final NashornException e) {
context.getErrorManager().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: getTopLevelExpression
import jdk.nashorn.api.scripting.NashornException; //导入依赖的package包/类
private ExpressionTree getTopLevelExpression(final Parser parser, final String code) {
try {
final CompilationUnitTree cut = parser.parse("<code>", code, null);
final List<? extends Tree> stats = cut.getSourceElements();
if (stats.size() == 1) {
final Tree stat = stats.get(0);
if (stat instanceof ExpressionStatementTree) {
return ((ExpressionStatementTree)stat).getExpression();
}
}
} catch (final NashornException ignored) {
// ignore any parser error. This is for completion anyway!
// And user will get that error later when the expression is evaluated.
}
return null;
}
示例3: doComplete
import jdk.nashorn.api.scripting.NashornException; //导入依赖的package包/类
protected void doComplete(F aResult) {
if (exceptions.isEmpty()) {
if (onSuccess != null) {
onSuccess.accept(aResult);
}
} else {
if (onFailure != null) {
StringBuilder eMessagesSum = new StringBuilder();
exceptions.stream().forEach((ex) -> {
if (eMessagesSum.length() > 0) {
eMessagesSum.append("\n");
}
String message = ex.getMessage() != null && !ex.getMessage().isEmpty() ? ex.getMessage() : ex.toString();
if (ex instanceof FileNotFoundException) {
message = "File or module not found: " + message;
} else if(ex instanceof NashornException){
NashornException nex = (NashornException)ex;
message = nex.getFileName() + ":" + nex.getLineNumber() + " " + message;
}
eMessagesSum.append(message);
});
onFailure.accept(new IllegalStateException(eMessagesSum.toString()));
}
}
}
示例4: printStackTrace
import jdk.nashorn.api.scripting.NashornException; //导入依赖的package包/类
@Override
public void printStackTrace(PrintStream s) {
if (nex == null) {
orig.printStackTrace(s);
} else {
synchronized (s) {
doPrintStackTrace(s, orig.getMessage(), getStackTrace());
// Suppressed
for (Throwable sup : orig.getSuppressed()) {
System.err.println("Suppressed...");
NashornException supNex = retrieveNashornException(sup);
if (supNex == null) {
sup.printStackTrace(s);
} else {
doPrintStackTrace(s, supNex.getMessage(),
NashornException.getScriptFrames(supNex));
}
}
}
}
}
示例5: isScriptFrame
import jdk.nashorn.api.scripting.NashornException; //导入依赖的package包/类
/**
* Check if a stack trace element is in JavaScript
*
* @param frame frame
*
* @return true if frame is in the script
*/
public static boolean isScriptFrame(final StackTraceElement frame) {
final String className = frame.getClassName();
// Look for script package in class name (into which compiler puts generated code)
if (className.startsWith(scriptPackage)) {
final String source = frame.getFileName();
/*
* Make sure that it is not some Java code that Nashorn has in that package!
* also, we don't want to report JavaScript code that lives in script engine implementation
* We want to report only user's own scripts and not any of our own scripts like "engine.js"
*/
return source != null && !source.endsWith(".java") && !source.contains(NashornException.ENGINE_SCRIPT_SOURCE_NAME);
}
return false;
}
示例6: registerAuthentication
import jdk.nashorn.api.scripting.NashornException; //导入依赖的package包/类
@Override
public void registerAuthentication(Object registerFunction) throws ScriptException, NashornException, NasapiException {
if (registerFunction == null) {
throw new NasapiException("registerAuthentication argument cannot be null");
} else if (registerFunction instanceof ScriptObjectMirror && ((ScriptObjectMirror)registerFunction).isFunction()) {
authenticateFunction = (ScriptObjectMirror)registerFunction;
} else {
throw new NasapiException("registerAuthentication argument must be a function");
}
}
示例7: getStackTrace
import jdk.nashorn.api.scripting.NashornException; //导入依赖的package包/类
/**
* Nashorn extension: Error.prototype.getStackTrace()
* "stack" property is an array typed value containing {@link StackTraceElement}
* objects of JavaScript stack frames.
*
* @param self self reference
*
* @return stack trace as a script array.
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object getStackTrace(final Object self) {
final ScriptObject sobj = Global.checkObject(self);
final Object exception = ECMAException.getException(sobj);
Object[] res;
if (exception instanceof Throwable) {
res = NashornException.getScriptFrames((Throwable)exception);
} else {
res = ScriptRuntime.EMPTY_ARRAY;
}
return new NativeArray(res);
}
示例8: getLineNumber
import jdk.nashorn.api.scripting.NashornException; //导入依赖的package包/类
/**
* Get the line number for a {@code ScriptObject} representing an error
*
* @param errObj the error object
* @return the line number, or undefined if wrapped exception is not a ParserException
*/
public static Object getLineNumber(final ScriptObject errObj) {
final Object e = getException(errObj);
if (e instanceof NashornException) {
return ((NashornException)e).getLineNumber();
} else if (e instanceof ScriptException) {
return ((ScriptException)e).getLineNumber();
}
return UNDEFINED;
}
示例9: getColumnNumber
import jdk.nashorn.api.scripting.NashornException; //导入依赖的package包/类
/**
* Get the column number for a {@code ScriptObject} representing an error
*
* @param errObj the error object
* @return the column number, or undefined if wrapped exception is not a ParserException
*/
public static Object getColumnNumber(final ScriptObject errObj) {
final Object e = getException(errObj);
if (e instanceof NashornException) {
return ((NashornException)e).getColumnNumber();
} else if (e instanceof ScriptException) {
return ((ScriptException)e).getColumnNumber();
}
return UNDEFINED;
}
示例10: getFileName
import jdk.nashorn.api.scripting.NashornException; //导入依赖的package包/类
/**
* Get the file name for a {@code ScriptObject} representing an error
*
* @param errObj the error object
* @return the file name, or undefined if wrapped exception is not a ParserException
*/
public static Object getFileName(final ScriptObject errObj) {
final Object e = getException(errObj);
if (e instanceof NashornException) {
return ((NashornException)e).getFileName();
} else if (e instanceof ScriptException) {
return ((ScriptException)e).getFileName();
}
return UNDEFINED;
}
示例11: parse
import jdk.nashorn.api.scripting.NashornException; //导入依赖的package包/类
@Override
public CompilationUnitTree parse(final File file, final DiagnosticListener listener) throws IOException, NashornException {
if (moduleMode) {
return parseModule(file, listener);
}
final Source src = Source.sourceFor(Objects.requireNonNull(file).getName(), file);
return translate(makeParser(src, listener).parse());
}
示例12: parseModule
import jdk.nashorn.api.scripting.NashornException; //导入依赖的package包/类
private CompilationUnitTree parseModule(final ScriptObjectMirror scriptObj, final DiagnosticListener listener) throws NashornException {
final Map<?, ?> map = Objects.requireNonNull(scriptObj);
if (map.containsKey("script") && map.containsKey("name")) {
final String script = JSType.toString(map.get("script"));
final String name = JSType.toString(map.get("name"));
final Source src = Source.sourceFor(name, script);
return makeModule(src, listener);
} else {
throw new IllegalArgumentException("can't find 'script' and 'name' properties");
}
}
示例13: parse
import jdk.nashorn.api.scripting.NashornException; //导入依赖的package包/类
@Override
public CompilationUnitTree parse(final ScriptObjectMirror scriptObj, final DiagnosticListener listener) throws NashornException {
final Map<?,?> map = Objects.requireNonNull(scriptObj);
if (map.containsKey("script") && map.containsKey("name")) {
final String script = JSType.toString(map.get("script"));
final String name = JSType.toString(map.get("name"));
final Source src = Source.sourceFor(name, script);
return translate(makeParser(src, listener).parse());
} else {
throw new IllegalArgumentException("can't find 'script' and 'name' properties");
}
}