return rhinoContext.evaluateReader(scope, scriptReader, scriptName,
lineNumber, securityDomain);
} catch (JavaScriptException t) {
final ScriptException se = new ScriptException(t.details(),
t.sourceName(), t.lineNumber());
// log the script stack trace
((Logger) bindings.get(SlingBindings.LOG)).error(t.getScriptStackTrace());
// set the exception cause
Object value = t.getValue();
if (value != null) {
if (value instanceof Wrapper) {
value = ((Wrapper) value).unwrap();
}
if (value instanceof Throwable) {
se.initCause((Throwable) value);
}
}
// if the cause could not be set, overwrite the stack trace
if (se.getCause() == null) {
se.setStackTrace(t.getStackTrace());
}
throw se;
} catch (Throwable t) {
final ScriptException se = new ScriptException(
"Failure running script " + scriptName + ": " + t.getMessage());
se.initCause(t);
throw se;
} finally {
// if properties have been replaced, reset them