in src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/SlyBindingsValuesProvider.java [195:218]
private Function loadFactory(ResourceResolver resolver, JsEnvironment jsEnvironment, String path, Bindings bindings) {
Resource resource = resolver.getResource(path);
if (resource == null) {
throw new SightlyException("Sly namespace loader could not find the following script: " + path);
}
try {
AsyncContainer container =
jsEnvironment.runScript(
new ScriptNameAwareReader(
new StringReader(IOUtils.toString(resource.adaptTo(InputStream.class), StandardCharsets.UTF_8)),
resource.getPath()
),
createBindings(bindings, resource.getPath()),
new LazyBindings()
);
Object obj = container.getResult();
if (!(obj instanceof Function)) {
throw new SightlyException("Script " + path + " was expected to return a function.");
}
return (Function) obj;
} catch (IOException e) {
throw new SightlyException("Cannot read script " + path + " .");
}
}