本文整理汇总了Java中org.mozilla.javascript.RhinoException类的典型用法代码示例。如果您正苦于以下问题:Java RhinoException类的具体用法?Java RhinoException怎么用?Java RhinoException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RhinoException类属于org.mozilla.javascript包,在下文中一共展示了RhinoException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: callFunction
import org.mozilla.javascript.RhinoException; //导入依赖的package包/类
/**
* call a JS function and return its result as Object
*
* @param functionName
* @param args
* @throws ScriptException
* @return
*/
private Object callFunction(String functionName, Object[] args) throws ScriptException {
Object functionObj = scope.get(functionName, scope);
if (!(functionObj instanceof Function)) {
throw new ScriptException(functionName+ " is undefined or not a function");
}
Function func = (Function)functionObj;
try {
Object result = func.call(ctx, scope, scope, args);
// LOGGER.info("Call to javascript function "+functionName+" returned "+result.toString());
return result;
} catch (RhinoException e) {
throw makeScriptException(e);
}
}
示例2: callJavaScriptFunction
import org.mozilla.javascript.RhinoException; //导入依赖的package包/类
/**
* Call JavaScript functions with an argument array.
*
* @param f
* The function to be executed
* @param oaArgs
* The Java object arguments passed to the function being
* executed
*/
private Object callJavaScriptFunction( Function f, Object[] oaArgs )
throws CrosstabException
{
final Context cx = Context.enter( );
Object oReturnValue = null;
try
{
oReturnValue = f.call( cx, scope, scope, oaArgs );
}
catch ( RhinoException ex )
{
throw convertException( ex );
}
finally
{
Context.exit( );
}
return oReturnValue;
}
示例3: evalInlineScript
import org.mozilla.javascript.RhinoException; //导入依赖的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;
}
}
示例4: processFileNoThrow
import org.mozilla.javascript.RhinoException; //导入依赖的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;
}
}
示例5: onException
import org.mozilla.javascript.RhinoException; //导入依赖的package包/类
@Override
public void onException(ScriptExecution execution, Exception e) {
RhinoException rhinoException = getRhinoException(e);
int line = -1, col = 0;
if (rhinoException != null) {
line = rhinoException.lineNumber();
col = rhinoException.columnNumber();
}
if (ScriptInterruptedException.causedByInterrupted(e)) {
App.getApp().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED)
.putExtra(EXTRA_EXCEPTION_LINE_NUMBER, line)
.putExtra(EXTRA_EXCEPTION_COLUMN_NUMBER, col));
} else {
App.getApp().sendBroadcast(new Intent(ACTION_ON_EXECUTION_FINISHED)
.putExtra(EXTRA_EXCEPTION_MESSAGE, e.getMessage())
.putExtra(EXTRA_EXCEPTION_LINE_NUMBER, line)
.putExtra(EXTRA_EXCEPTION_COLUMN_NUMBER, col));
}
}
示例6: loadScriptFromSource
import org.mozilla.javascript.RhinoException; //导入依赖的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;
}
示例7: evaluateScript
import org.mozilla.javascript.RhinoException; //导入依赖的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();
}
示例8: testCustomContextFactory
import org.mozilla.javascript.RhinoException; //导入依赖的package包/类
public void testCustomContextFactory() {
ContextFactory factory = new MyFactory();
Context cx = factory.enterContext();
try {
Scriptable globalScope = cx.initStandardObjects();
// Test that FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME is enabled
/* TODO(stevey): fix this functionality in parser
Object result = cx.evaluateString(globalScope,
"var obj = {};" +
"function obj.foo() { return 'bar'; }" +
"obj.foo();",
"test source", 1, null);
assertEquals("bar", result);
*/
} catch (RhinoException e) {
fail(e.toString());
} finally {
Context.exit();
}
}
示例9: load
import org.mozilla.javascript.RhinoException; //导入依赖的package包/类
public PluginBase load(File file){
try{
PluginBase plugin;
if(file.getName().endsWith(".jar")) plugin = this.loadJar(file);
else if(file.getName().endsWith(".js")) plugin = new JavaScriptPlugin(file);
else return null;
Takoyaki.getInstance().getLogger().info("플러그인을 불러옵니다: " + plugin.getName() + (plugin.getVersion() != null ? " v" + plugin.getVersion() : ""));
plugin.onLoad();
return plugin;
}catch(IOException | RhinoException | ReflectiveOperationException e){
Takoyaki.getInstance().getLogger().error(e.getClass().getName() + ": " + e.getMessage());
}
return null;
}
示例10: throwWrappedScriptException
import org.mozilla.javascript.RhinoException; //导入依赖的package包/类
/**
* Wraps given exception and throws it as ScriptException.
*
* @param ex Exception to be wrapped.
* @throws ScriptException Thrown always by this method.
*/
public static void throwWrappedScriptException(Exception ex) throws ScriptException {
if ( ex instanceof RhinoException) {
RhinoException rhinoException = (RhinoException)ex;
int line = rhinoException.lineNumber();
int column = rhinoException.columnNumber();
String message;
if (ex instanceof JavaScriptException) {
message = String.valueOf(((JavaScriptException)ex).getValue());
} else {
message = ex.toString();
}
ScriptException scriptException = new ScriptException(message, rhinoException.sourceName(), line, column);
scriptException.initCause(ex);
throw scriptException;
} else {
throw new ScriptException(ex);
}
}
示例11: construct
import org.mozilla.javascript.RhinoException; //导入依赖的package包/类
public Scriptable construct(Context cx, Scriptable scope, Object[] args)
throws RhinoException {
if (isPrototype) {
Scriptable topLevel = ScriptableObject.getTopLevelScope(scope);
JSAdapter newObj;
if (args.length > 0) {
newObj = new JSAdapter(Context.toObject(args[0], topLevel));
} else {
throw Context.reportRuntimeError("JSAdapter requires adaptee");
}
return newObj;
} else {
Scriptable tmp = getAdaptee();
if (tmp instanceof Function) {
return ((Function)tmp).construct(cx, scope, args);
} else {
throw Context.reportRuntimeError("TypeError: not a constructor");
}
}
}
示例12: call
import org.mozilla.javascript.RhinoException; //导入依赖的package包/类
private Object call(Function func, Object[] args) {
Context cx = Context.getCurrentContext();
Scriptable thisObj = getAdaptee();
Scriptable scope = func.getParentScope();
try {
return func.call(cx, scope, thisObj, args);
} catch (RhinoException re) {
throw Context.reportRuntimeError(re.getMessage());
}
}
示例13: construct
import org.mozilla.javascript.RhinoException; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public Scriptable construct(Context cx, Scriptable scope, Object[] args) throws RhinoException {
if (args.length == 2) {
Class clazz = null;
Object obj1 = args[0];
if (obj1 instanceof Wrapper) {
Object o = ((Wrapper) obj1).unwrap();
if (o instanceof Class && ((Class) o).isInterface()) {
clazz = (Class) o;
}
} else if (obj1 instanceof Class) {
if (((Class) obj1).isInterface()) {
clazz = (Class) obj1;
}
}
if (clazz == null) {
throw Context.reportRuntimeError("JavaAdapter: first arg should be interface Class");
}
Scriptable topLevel = ScriptableObject.getTopLevelScope(scope);
return Context.toObject(engine.getInterface(args[1], clazz), topLevel);
} else {
throw Context.reportRuntimeError("JavaAdapter requires two arguments");
}
}
示例14: eval
import org.mozilla.javascript.RhinoException; //导入依赖的package包/类
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) {
int line = (line = re.lineNumber()) == 0 ? -1 : line;
throw new ScriptException(re.toString(), re.sourceName(), line);
} catch (IOException ee) {
throw new ScriptException(ee);
} finally {
Context.exit();
}
return unwrapReturnValue(ret);
}
示例15: invoke
import org.mozilla.javascript.RhinoException; //导入依赖的package包/类
private Object invoke(Object thiz, String name, Object... args)
throws ScriptException, NoSuchMethodException {
Context cx = enterContext();
try {
if (name == null) {
throw new NullPointerException("method name is null");
}
if (thiz != null && !(thiz instanceof Scriptable)) {
thiz = Context.toObject(thiz, topLevel);
}
Scriptable engineScope = getRuntimeScope(context);
Scriptable localScope = (thiz != null)? (Scriptable) thiz :
engineScope;
Object obj = ScriptableObject.getProperty(localScope, name);
if (! (obj instanceof Function)) {
throw new NoSuchMethodException("no such method: " + name);
}
Function func = (Function) obj;
Scriptable scope = func.getParentScope();
if (scope == null) {
scope = engineScope;
}
Object result = func.call(cx, scope, localScope,
wrapArguments(args));
return unwrapReturnValue(result);
} catch (RhinoException re) {
int line = (line = re.lineNumber()) == 0 ? -1 : line;
throw new ScriptException(re.toString(), re.sourceName(), line);
} finally {
Context.exit();
}
}