in src/main/java/org/apache/sling/scripting/esx/EsxScriptEngine.java [40:72]
public Object eval(Reader reader, ScriptContext context) throws ScriptException {
log.debug("starting to eval ESX Script");
Bindings bindings = context.getBindings(ScriptContext.ENGINE_SCOPE);
SlingScriptHelper scriptHelper = (SlingScriptHelper) bindings.get("sling");
Resource scriptResource = scriptHelper.getScript().getScriptResource();
Resource resource = scriptHelper.getRequest().getResource();
ModuleScript moduleScript = new ModuleScript(ModuleScript.JS_FILE, scriptResource);
//public Module (EsxScriptEngineFactory factory, Resource resource, ModuleScript moduleScript, String id, Module parent, SlingScriptHelper scriptHelper) throws ScriptException {
Module module = new Module(
(EsxScriptEngineFactory) getFactory(),
resource, moduleScript, scriptResource.getPath(), null,
scriptHelper,
Module.LOADER_JS
);
try {
Object moduleResults = module.require(scriptResource.getPath());
String result = ((EsxScriptEngineFactory) getFactory()).getNashornEngine().eval(
"if(exports.render && typeof exports.render === 'function') { exports.render('test'); }"
+ " else if(typeof exports === 'class') { new exports().render('function') } else {"
+ "'You need to define either a render function or export an object with a render method'; }", module).toString();
context.getWriter().write(result);
} catch (IOException ex) {
throw new ScriptException(ex);
}
return null;
}