本文整理了Java中org.mozilla.javascript.JavaScriptException
类的一些代码示例,展示了JavaScriptException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JavaScriptException
类的具体详情如下:
包路径:org.mozilla.javascript.JavaScriptException
类名称:JavaScriptException
[英]Java reflection of JavaScript exceptions. Instances of this class are thrown by the JavaScript 'throw' keyword.
[中]JavaScript异常的Java反射。这个类的实例由JavaScript'throw'关键字抛出。
代码示例来源:origin: EngineHub/WorldEdit
Context cx = factory.enterContext();
ScriptableObject scriptable = new ImporterTopLevel(cx);
Scriptable scope = cx.initStandardObjects(scriptable);
Context.javaToJS(entry.getValue(), scope));
return cx.evaluateString(scope, script, filename, 1, null);
} catch (Error e) {
throw new ScriptException(e.getMessage());
msg = String.valueOf(((JavaScriptException) e).getValue());
} else {
msg = e.getMessage();
代码示例来源:origin: pentaho/pentaho-kettle
jscx.setOptimizationLevel( -1 );
jsscope = jscx.initStandardObjects( null, false );
Scriptable jsR = Context.toObject( sItem.getText(), jsscope );
jsscope.put( folder.getItem( i ).getText(), jsscope, jsR );
retval = false;
} catch ( JavaScriptException e ) {
String position = "(" + e.lineNumber() + ":" + e.columnNumber() + ")";
String message = BaseMessages.getString( PKG, "ScriptDialog.Exception.CouldNotExecuteScript", position );
testException = new KettleException( message, e );
代码示例来源:origin: stackoverflow.com
trigger("var a=arguments[0];a.parentNode.removeChild(a);", anchor);
} else {
throw new JavaScriptException(element, "Unable to open tab", 1);
代码示例来源: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: 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: org.apache.sling/org.apache.sling.scripting.javascript
final Context rhinoContext = Context.enter();
rhinoContext.setLanguageVersion(((RhinoJavaScriptEngineFactory)getFactory()).rhinoLanguageVersion());
rhinoContext.setOptimizationLevel(optimizationLevel());
if (ScriptRuntime.hasTopCall(rhinoContext)) {
scope = ScriptRuntime.getTopCallScope(rhinoContext);
final ScriptException se = new ScriptException(t.details(),
t.sourceName(), t.lineNumber());
((Logger) bindings.get(SlingBindings.LOG)).error(t.getScriptStackTrace());
Object value = t.getValue();
if (value != null) {
if (value instanceof Wrapper) {
se.setStackTrace(t.getStackTrace());
代码示例来源: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: micromata/projectforge
final Context cx = Context.enter();
final Object result = doIt.call(cx, scope, null, new Object[] { input, compress });
} 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();
Context.exit();
代码示例来源:origin: org.ofbiz/ofbcore-jira-share
Context cx = Context.enter();
throw new JavaScriptException("function " + method +
" not found.");
theReturnValue = ScriptRuntime.call(cx, fun, global, args, null);
if (theReturnValue instanceof Wrapper) {
theReturnValue = ((Wrapper) theReturnValue).unwrap();
handleError(t);
} finally {
Context.exit();
代码示例来源:origin: geogebra/geogebra
Object x = args[0];
if (!(x instanceof CharSequence)) {
if (cx.hasFeature(Context.FEATURE_STRICT_MODE) ||
cx.hasFeature(Context.FEATURE_STRICT_EVAL))
throw Context.reportRuntimeError0("msg.eval.nonstring.strict");
String message = ScriptRuntime.getMessage0("msg.eval.nonstring");
Context.reportWarning(message);
return x;
makeUrlForGeneratedScript(true, filename, lineNumber);
Evaluator evaluator = Context.createInterpreter();
if (evaluator == null) {
throw new JavaScriptException("Interpreter not present",
filename, lineNumber);
代码示例来源:origin: com.github.tntim96/rhino
obj = ((JavaScriptException)t).getValue();
} else {
cacheObj = true;
if (obj == null) Kit.codeBug();
} else {
obj = wrapException(t, scope, cx);
exceptionName, obj, ScriptableObject.PERMANENT);
if (isVisible(cx, t)) {
"__exception__", Context.javaToJS(t, scope),
ScriptableObject.PERMANENT|ScriptableObject.DONTENUM);
代码示例来源: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: ro.isdc.wro4j/rhino
if (cx.getLanguageVersion() != Context.VERSION_1_2) {
sourceBuf.append("anonymous");
sourceBuf.append(',');
sourceBuf.append(ScriptRuntime.toString(args[i]));
String funBody = ScriptRuntime.toString(args[arglen - 1]);
sourceBuf.append(funBody);
String filename = Context.getSourcePositionFromStack(linep);
if (filename == null) {
filename = "<eval'ed string>";
makeUrlForGeneratedScript(false, filename, linep[0]);
reporter = DefaultErrorReporter.forEval(cx.getErrorReporter());
Evaluator evaluator = Context.createInterpreter();
if (evaluator == null) {
throw new JavaScriptException("Interpreter not present",
filename, linep[0]);
代码示例来源:origin: com.google.code.maven-play-plugin.com.github.yeungda.jcoffeescript/jcoffeescript
JCoffeeScriptCompileException (JavaScriptException e) {
super(e.getValue().toString(), e);
}
代码示例来源:origin: rhino/js
return Boolean.FALSE;
Callable f = (Callable) v;
Context cx = Context.getContext();
try {
x.currentId = f.call(cx, x.iterator.getParentScope(),
return Boolean.TRUE;
} catch (JavaScriptException e) {
if (e.getValue() instanceof NativeIterator.StopIteration) {
return Boolean.FALSE;
enumChangeObject(x);
continue;
代码示例来源:origin: geogebra/geogebra
/**
* Equivalent to executing "new $constructorName(message, sourceFileName, sourceLineNo)" from JavaScript.
* @param cx the current context
* @param scope the current scope
* @param message the message
* @return a JavaScriptException you should throw
*/
public static JavaScriptException throwCustomError(Context cx, Scriptable scope, String constructorName,
String message) {
int[] linep = { 0 };
String filename = Context.getSourcePositionFromStack(linep);
final Scriptable error = cx.newObject(scope, constructorName,
new Object[] { message, filename, Integer.valueOf(linep[0]) });
return new JavaScriptException(error, filename, linep[0]);
}
代码示例来源:origin: geogebra/geogebra
/**
* Sets the value of the indexed property, creating it if need be.
*
* @param index the numeric index for the property
* @param start the object whose property is being set
* @param value value to set the property to
*/
public void put(int index, Scriptable start, Object value)
{
if (externalData != null) {
if (index < externalData.getArrayLength()) {
externalData.setArrayElement(index, value);
} else {
throw new JavaScriptException(
ScriptRuntime.newNativeError(Context.getCurrentContext(), this,
TopLevel.NativeErrors.RangeError,
new Object[] { "External array index out of bounds " }),
null, 0);
}
return;
}
if (putImpl(null, index, start, value))
return;
if (start == this) throw Kit.codeBug();
start.put(index, start, value);
}
代码示例来源:origin: rhino/js
private Object next(Context cx, Scriptable scope) {
Boolean b = ScriptRuntime.enumNext(this.objectIterator);
if (!b.booleanValue()) {
// Out of values. Throw StopIteration.
throw new JavaScriptException(
NativeIterator.getStopIterationObject(scope), null, 0);
}
return ScriptRuntime.enumId(this.objectIterator, cx);
}
代码示例来源:origin: geogebra/geogebra
/**
* Equivalent to executing "new Error(message, sourceFileName, sourceLineNo)" from JavaScript.
* @param cx the current context
* @param scope the current scope
* @param message the message
* @return a JavaScriptException you should throw
*/
public static JavaScriptException throwError(Context cx, Scriptable scope,
String message) {
int[] linep = { 0 };
String filename = Context.getSourcePositionFromStack(linep);
final Scriptable error = newBuiltinObject(cx, scope,
TopLevel.Builtins.Error, new Object[] { message, filename, Integer.valueOf(linep[0]) });
return new JavaScriptException(error, filename, linep[0]);
}
内容来源于网络,如有侵权,请联系作者删除!