Design design = unwrapThisObj(thisObj);
// For the current design redirect to WGAGlobal.loadObjectDefinition() which uses all location info from the current design
if (design._isCurrentScriptDesign) {
RhinoExpressionEngineImpl runtime = WGAGlobal.fetchRuntime(cx);
return WGAGlobal.loadObjectDefinition(cx, runtime.getSharedScope().getWgaGlobal(), args, funObj);
}
VarArgParser.Arguments parsedArgs = WGAGlobal._loadObjectDefVarags.parse(args);
TMLContext context = WGAGlobal.fetchInitialContext(cx);
String actionID = (String) parsedArgs.get("id");
NativeObject currentObject = (NativeObject) parsedArgs.get("currentObject");
// Get the function def (might need to expand local name by the name of
// the current action)
// Locate object definition
TMLAction action = null;
try {
if (design._currentObject != null) {
TMLAction.Locator locator = WGAGlobal.determineActionLocator(cx, design._currentObject, context, actionID);
action = context.getModuleActionByID(locator.getId(), locator.getDbkey());
}
else {
action = context.getModuleActionByID(actionID, design._designContext.getDesignDB().getDbReference());
}
}
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 = WGAGlobal.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();