本文整理了Java中org.mozilla.javascript.JavaScriptException.getValue()
方法的一些代码示例,展示了JavaScriptException.getValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JavaScriptException.getValue()
方法的具体详情如下:
包路径:org.mozilla.javascript.JavaScriptException
类名称:JavaScriptException
方法名:getValue
暂无
代码示例来源:origin: EngineHub/WorldEdit
msg = String.valueOf(((JavaScriptException) e).getValue());
} else {
msg = e.getMessage();
代码示例来源:origin: EngineHub/WorldEdit
@Override
public Object eval(String script, ScriptContext context)
throws ScriptException {
Scriptable scope = setupScope(cx, context);
String filename = (filename = (String) get(ScriptEngine.FILENAME)) == null
? "<unknown>" : filename;
try {
return cx.evaluateString(scope, script, filename, 1, null);
} catch (RhinoException e) {
String msg;
int line = (line = e.lineNumber()) == 0 ? -1 : line;
if (e instanceof JavaScriptException) {
msg = String.valueOf(((JavaScriptException) e).getValue());
} else {
msg = e.getMessage();
}
ScriptException scriptException =
new ScriptException(msg, e.sourceName(), line);
scriptException.initCause(e);
throw scriptException;
} finally {
Context.exit();
}
}
代码示例来源:origin: EngineHub/WorldEdit
@Override
public Object eval(Reader reader, ScriptContext context)
throws ScriptException {
Scriptable scope = setupScope(cx, context);
String filename = (filename = (String) get(ScriptEngine.FILENAME)) == null
? "<unknown>" : filename;
try {
return cx.evaluateReader(scope, reader, filename, 1, null);
} catch (RhinoException e) {
String msg;
int line = (line = e.lineNumber()) == 0 ? -1 : line;
if (e instanceof JavaScriptException) {
msg = String.valueOf(((JavaScriptException) e).getValue());
} else {
msg = e.getMessage();
}
ScriptException scriptException =
new ScriptException(msg, e.sourceName(), line);
scriptException.initCause(e);
throw scriptException;
} catch (IOException e) {
throw new ScriptException(e);
} finally {
Context.exit();
}
}
代码示例来源:origin: com.google.code.maven-play-plugin.com.github.yeungda.jcoffeescript/jcoffeescript
JCoffeeScriptCompileException (JavaScriptException e) {
super(e.getValue().toString(), e);
}
代码示例来源:origin: cn.dreampie/coffeescript
CoffeeException(JavaScriptException e) {
super(e.getValue().toString(), e);
}
代码示例来源:origin: com.atlassian.lesscss/lesscss-core
private LessCompilationException newLessException(JavaScriptException e) {
if (e.getValue() instanceof Scriptable) {
Scriptable value = (Scriptable) e.getValue();
String type = String.valueOf(ScriptableObject.getProperty(value, "type"));
String message = String.valueOf(ScriptableObject.getProperty(value, "message"));
if ("Syntax".equals(type)) {
return new LessSyntaxException(message, e);
} else if ("Unresolvable Import".equals(type)) {
return new UnresolvableImportException(message, e);
}
}
return new LessCompilationException(describeJsObject(e.getValue()), e);
}
代码示例来源:origin: biz.gabrys.lesscss/compiler
private static CompilerException parseException(final JavaScriptException exception) {
final Scriptable value = (Scriptable) exception.getValue();
if (value != null && ScriptableObject.hasProperty(value, "message")) {
final String message = ScriptableObject.getProperty(value, "message").toString();
final Matcher matcher = IMPORT_ERROR_PATTERN.matcher(message);
if (matcher.find()) {
return new ResolveImportException(message, matcher.group(IMPORT_ERROR_FILE_NAME_GROUP_INDEX), exception);
}
return new SyntaxException(message, exception);
}
return new SyntaxException(exception);
}
}
代码示例来源:origin: com.atlassian.pluginkit/ringojs-kit
public Object wrap(Context cx, Scriptable scope, Object obj, Class staticType)
{
if (obj instanceof List)
{
return new MyScriptableList(scope, (List) obj);
}
else if (obj instanceof JavaScriptException)
{
JavaScriptException jse = (JavaScriptException) obj;
Object nativeError = jse.getValue();
if (nativeError != null)
{
return nativeError;
}
}
return super.wrap(cx, scope, obj, staticType);
}
}
代码示例来源:origin: ro.isdc.wro4j/wro4j-extensions
/**
* Creates a more detailed message based on {@link RhinoException} thrown by rhino execution. The message will contain
* a detailed description of the problem by inspecting the JSON value provided by exception.
*
* @param e
* {@link RhinoException} thrown by rhino execution.
* @return detailed string message.
*/
public static String createExceptionMessage(final RhinoException e) {
StringBuffer message = new StringBuffer("Could not execute the script because: \n");
if (e instanceof JavaScriptException) {
message.append(toJson(((JavaScriptException) e).getValue()));
} else if (e instanceof EcmaError) {
final EcmaError ecmaError = (EcmaError) e;
message.append(String.format("Error message: %s at line: %s. \nSource: %s", ecmaError.getErrorMessage(),
ecmaError.lineNumber(), ecmaError.lineSource()));
} else {
message.append(e.getMessage());
}
return message.toString();
}
代码示例来源:origin: alexo/wro4j
/**
* Creates a more detailed message based on {@link RhinoException} thrown by rhino execution. The message will contain
* a detailed description of the problem by inspecting the JSON value provided by exception.
*
* @param e
* {@link RhinoException} thrown by rhino execution.
* @return detailed string message.
*/
public static String createExceptionMessage(final RhinoException e) {
StringBuffer message = new StringBuffer("Could not execute the script because: \n");
if (e instanceof JavaScriptException) {
message.append(toJson(((JavaScriptException) e).getValue()));
} else if (e instanceof EcmaError) {
final EcmaError ecmaError = (EcmaError) e;
message.append(String.format("Error message: %s at line: %s. \nSource: %s", ecmaError.getErrorMessage(),
ecmaError.lineNumber(), ecmaError.lineSource()));
} else {
message.append(e.getMessage());
}
return message.toString();
}
代码示例来源:origin: info.cukes/cucumber-rhino
public void execute(I18n i18n, Object[] args) throws Throwable {
try {
bodyFunc.call(cx, scope, scope, args);
} catch (JavaScriptException e) {
Object value = e.getValue();
if (value instanceof NativeJavaObject) {
NativeJavaObject njo = (NativeJavaObject) value;
Object unwrapped = njo.unwrap();
if (unwrapped instanceof Throwable) {
throw (Throwable) unwrapped;
}
}
throw e.getCause() == null ? e : e.getCause();
}
}
代码示例来源:origin: micromata/projectforge
} catch (final Exception e) {
if (e instanceof JavaScriptException) {
final Scriptable value = (Scriptable) ((JavaScriptException) e).getValue();
if (value != null && ScriptableObject.hasProperty(value, "message")) {
final String message = ScriptableObject.getProperty(value, "message").toString();
代码示例来源:origin: com.google.code.scriptengines/scriptengines-javascript
public Object eval(ScriptContext context) throws ScriptException {
Object result = null;
Context cx = RhinoScriptEngine.enterContext();
try {
Scriptable scope = engine.getRuntimeScope(context);
Object ret = script.exec(cx, scope);
result = engine.unwrapReturnValue(ret);
} catch (JavaScriptException jse) {
if (DEBUG) jse.printStackTrace();
int line = (line = jse.lineNumber()) == 0 ? -1 : line;
Object value = jse.getValue();
String str = (value != null && value.getClass().getName().equals("org.mozilla.javascript.NativeError") ?
value.toString() :
jse.toString());
throw new ExtendedScriptException(jse, str, jse.sourceName(), line);
} catch (RhinoException re) {
if (DEBUG) re.printStackTrace();
int line = (line = re.lineNumber()) == 0 ? -1 : line;
throw new ExtendedScriptException(re, re.toString(), re.sourceName(), line);
} finally {
Context.exit();
}
return result;
}
代码示例来源:origin: cat.inspiracio/rhino-js-engine
public Object eval(ScriptContext context) throws ScriptException {
Object result = null;
Context cx = RhinoScriptEngine.enterContext();
try {
Scriptable scope = engine.getRuntimeScope(context);
Object ret = script.exec(cx, scope);
result = engine.unwrapReturnValue(ret);
} catch (JavaScriptException jse) {
if (DEBUG) jse.printStackTrace();
int line = (line = jse.lineNumber()) == 0 ? -1 : line;
Object value = jse.getValue();
String str = (value != null && value.getClass().getName().equals("org.mozilla.javascript.NativeError") ?
value.toString() :
jse.toString());
throw new ExtendedScriptException(jse, str, jse.sourceName(), line);
} catch (RhinoException re) {
if (DEBUG) re.printStackTrace();
int line = (line = re.lineNumber()) == 0 ? -1 : line;
throw new ExtendedScriptException(re, re.toString(), re.sourceName(), line);
} finally {
Context.exit();
}
return result;
}
代码示例来源:origin: rhq-project/rhq
@Override
public Object eval(ScriptContext context) throws ScriptException {
Object result = null;
Context cx = RhinoScriptEngine.enterContext();
try {
Scriptable scope = engine.getRuntimeScope(context);
Object ret = script.exec(cx, scope);
result = engine.unwrapReturnValue(ret);
} catch (JavaScriptException jse) {
if (DEBUG) jse.printStackTrace();
int line = (line = jse.lineNumber()) == 0 ? -1 : line;
Object value = jse.getValue();
String str = (value != null && value.getClass().getName().equals("org.mozilla.javascript.NativeError") ?
value.toString() :
jse.toString());
throw new ExtendedScriptException(jse, str, jse.sourceName(), line);
} catch (RhinoException re) {
if (DEBUG) re.printStackTrace();
int line = (line = re.lineNumber()) == 0 ? -1 : line;
throw new ExtendedScriptException(re, re.toString(), re.sourceName(), line);
} finally {
Context.exit();
}
return result;
}
代码示例来源:origin: com.google.code.maven-play-plugin.com.asual.lesscss/lesscss-engine
private LessException parseLessException(Exception root) throws LessException {
logger.debug("Parsing LESS Exception", root);
if (root instanceof JavaScriptException) {
Scriptable value = (Scriptable) ((JavaScriptException) root).getValue();
String type = (String) ScriptableObject.getProperty(value, "type") + " Error";
String message = (String) ScriptableObject.getProperty(value, "message");
代码示例来源:origin: io.apisense/rhino-android
public Object eval(ScriptContext context) throws ScriptException {
Object result = null;
Context cx = RhinoScriptEngine.enterContext();
try {
Scriptable scope = engine.getRuntimeScope(context);
Object ret = script.exec(cx, scope);
result = engine.unwrapReturnValue(ret);
} catch (RhinoException re) {
int line = (line = re.lineNumber()) == 0 ? -1 : line;
String msg;
if (re instanceof JavaScriptException) {
msg = String.valueOf(((JavaScriptException)re).getValue());
} else {
msg = re.toString();
}
ScriptException se = new ScriptException(msg, re.sourceName(), line);
se.initCause(re);
throw se;
} finally {
Context.exit();
}
return result;
}
代码示例来源:origin: tv.cntt/rhinocoffeescript
public static String compile(String coffeeScript) throws ScriptException {
Context ctx = Context.enter();
try {
Scriptable scope = ctx.initStandardObjects();
Script script = (Script) new CoffeeScript();
script.exec(ctx, scope);
NativeObject obj = (NativeObject) scope.get("CoffeeScript", scope);
Function fun = (Function) obj.get("compile", scope);
Object opts = ctx.evaluateString(scope, "({bare: true})", null, 1, null);
String javaScript = (String) fun.call(ctx, scope, obj, new Object[] {coffeeScript, opts});
return javaScript;
} catch (JavaScriptException e) {
// Extract line and column of the error location in the CoffeeScript.
// The below code is guessed from:
// - Experimenting http://coffeescript.org/ with Chrome JavaScript Console
// - https://code.google.com/p/wiquery/source/browse/trunk/src/main/java/org/mozilla/javascript/NativeError.java?spec=svn1010&r=1010
Scriptable syntaxError = (Scriptable) e.getValue();
Scriptable location = (Scriptable) ScriptableObject.getProperty(syntaxError, "location");
Double firstLine = (Double) ScriptableObject.getProperty(location, "first_line");
Double firstColumn = (Double) ScriptableObject.getProperty(location, "first_column");
throw new ScriptException("CoffeeScript syntax error", "", firstLine.intValue(), firstColumn.intValue());
} finally {
Context.exit();
}
}
}
代码示例来源:origin: io.apisense/rhino-android
public Object eval(Reader reader, ScriptContext ctxt)
throws ScriptException {
Object ret;
Context cx = enterContext();
try {
Scriptable scope = getRuntimeScope(ctxt);
String filename = (String) get(ScriptEngine.FILENAME);
filename = filename == null ? "<Unknown source>" : filename;
ret = cx.evaluateReader(scope, reader, filename , 1, null);
} catch (RhinoException re) {
if (DEBUG) re.printStackTrace();
int line = (line = re.lineNumber()) == 0 ? -1 : line;
String msg;
if (re instanceof JavaScriptException) {
msg = String.valueOf(((JavaScriptException)re).getValue());
} else {
msg = re.toString();
}
ScriptException se = new ScriptException(msg, re.sourceName(), line);
se.initCause(re);
throw se;
} catch (IOException ee) {
throw new ScriptException(ee);
} finally {
cx.exit();
}
return unwrapReturnValue(ret);
}
代码示例来源:origin: io.apigee/rhino
obj = ((JavaScriptException)t).getValue();
} else {
cacheObj = true;
内容来源于网络,如有侵权,请联系作者删除!