@Override
public RhinoExecutor invoke()
{
final Context context = contextFactory.enterContext();
final ScriptableObject scope = context.initStandardObjects();
try
{
context.setOptimizationLevel(-1);
for (Resource script : scripts)
{
loadScript(context, scope, script);
}
} finally
{
Context.exit();
}
return new RhinoExecutor()
{
@Override
public ScriptableObject invokeFunction(String functionName, Object... arguments)
{
contextFactory.enterContext(context);
try
{
NativeFunction function = (NativeFunction) scope.get(functionName, scope);
return (ScriptableObject) function.call(context, scope, null, arguments);
} finally
{
Context.exit();