@Override
public Object eval(Reader reader, ScriptContext context) throws ScriptException {
String filename = (String) get(ScriptEngine.FILENAME);
if (filename == null) {
filename = "<Unknown Source>";
}
Object result;
EngineScope scope = new EngineScope(context);
Global global = getGlobal();
scope.setParentScope(global);
scope.setPrototype(global);
Context cx = enterContext();
try {
scope.put("exports", scope, cx.newObject(global));
result = cx.evaluateReader(scope, reader, filename, 1, null);
} catch (EcmaError e) {
throw new ScriptException(
e.getMessage(), e.sourceName(), e.lineNumber(), e.columnNumber());
} catch (Exception e) {
throw new ScriptException(e);
} finally {
Context.exit();
}
return result;
}