use of org.mozilla.javascript.EvaluatorException in project jmeter by apache.
the class BSFJavaScriptEngine method call.
/**
* Return an object from an extension.
* @param object Object on which to make the call (ignored).
* @param method The name of the method to call.
* @param args an array of arguments to be
* passed to the extension, which may be either
* Vectors of Nodes, or Strings.
*/
@Override
public Object call(Object object, String method, Object[] args) throws BSFException {
Object retval = null;
Context cx;
try {
cx = Context.enter();
// REMIND: convert arg list Vectors here?
Object fun = global.get(method, global);
// Any way to make these arguments *sensible?
if (fun == Scriptable.NOT_FOUND) {
throw new EvaluatorException("function " + method + " not found.", "none", 0);
}
cx.setOptimizationLevel(-1);
cx.setGeneratingDebug(false);
cx.setGeneratingSource(false);
cx.setOptimizationLevel(0);
cx.setDebugger(null, null);
retval = ((Function) fun).call(cx, global, global, args);
if (retval instanceof Wrapper) {
retval = ((Wrapper) retval).unwrap();
}
} catch (Throwable t) {
//NOSONAR We handle correctly Error case in function
handleError(t);
} finally {
Context.exit();
}
return retval;
}
use of org.mozilla.javascript.EvaluatorException in project jmeter by apache.
the class BSFJavaScriptEngine method handleError.
/**
* @param t {@link Throwable}
* @throws BSFException
*/
private void handleError(Throwable t) throws BSFException {
Throwable target = t;
if (t instanceof WrappedException) {
target = ((WrappedException) t).getWrappedException();
}
String message = null;
if (target instanceof JavaScriptException) {
message = target.getLocalizedMessage();
// Is it an exception wrapped in a JavaScriptException?
Object value = ((JavaScriptException) target).getValue();
if (value instanceof Throwable) {
// likely a wrapped exception from a LiveConnect call.
// Display its stack trace as a diagnostic
target = (Throwable) value;
}
} else if (target instanceof EvaluatorException || target instanceof SecurityException) {
message = target.getLocalizedMessage();
} else if (target instanceof RuntimeException) {
message = "Internal Error: " + target.toString();
} else if (target instanceof StackOverflowError) {
message = "Stack Overflow";
}
if (message == null) {
message = target.toString();
}
if (target instanceof Error && !(target instanceof StackOverflowError)) {
// a long stacktrace would end up on the user's console
throw (Error) target;
} else {
throw new BSFException(BSFException.REASON_OTHER_ERROR, "JavaScript Error: " + message, target);
}
}
Aggregations