// 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;