// Get the function def (might need to expand local name by the name of
// the current action)
TMLAction.Locator actionLocator = determineActionLocator(cx, currentObject, context, actionID);
TMLAction action;
try {
action = context.getModuleActionByID(actionLocator.getId(), actionLocator.getDbkey());
}
catch (TMLActionException e) {
throw new EvaluatorException("Could not retrieve TMLScript module '" + args[0] + "': " + e.getMessage());
}
if (action == null) {
throw new EvaluatorException("Could not retrieve TMLScript module '" + args[0] + "'");
}
// Fetch runtime and return function object
RhinoExpressionEngineImpl runtime = fetchRuntime(cx);
// Use Context Redirector as scope, so the objects implicit context always directs to the current script's context
ContextRedirector redirector = new ContextRedirector();
// Preserve thread locals
ThreadLocalPreserver preserver = new ThreadLocalPreserver((RhinoContext) cx);
preserver.preserve(RhinoExpressionEngine.TL_ACTIONDEFINITION, action);
preserver.preserve(RhinoExpressionEngine.TL_SCRIPTNAME, "TMLScript-Object " + action.getModuleDatabase() + "/" + action.getModuleName());;
try {
Function func = runtime.getCompiledFunction(action.getCode(), (RhinoContext) cx, redirector);
func.put(RhinoExpressionEngine.PARAM_ACTIONDEFINITION, func, action);
return func;
}
finally {
preserver.restore();