in src/main/java/org/apache/sling/scripting/sightly/js/impl/jsapi/SlyBindingsValuesProvider.java [183:203]
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);
}
InputStream inputStream = resource.adaptTo(InputStream.class);
if (inputStream == null) {
throw new SightlyException("Sly namespace loader could not read the following script: " + path);
}
AsyncContainer container = jsEnvironment.runScript(
new ScriptNameAwareReader(
new InputStreamReader(inputStream, 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;
}