use of org.apache.sling.scripting.javascript.RhinoHostObjectProvider in project sling by apache.
the class RhinoJavaScriptEngineFactory method getRootScope.
@SuppressWarnings("unchecked")
private Scriptable getRootScope() {
if (rootScope == null) {
final Context rhinoContext = Context.enter();
try {
rhinoContext.setOptimizationLevel(optimizationLevel);
Scriptable tmpScope = rhinoContext.initStandardObjects(new ImporterTopLevel(rhinoContext), false);
// default classes
addHostObjects(tmpScope, (Class<? extends ScriptableObject>[]) HOSTOBJECT_CLASSES);
// provided classes
for (RhinoHostObjectProvider provider : hostObjectProvider) {
addHostObjects(tmpScope, provider.getHostObjectClasses());
addImportedClasses(rhinoContext, tmpScope, provider.getImportedClasses());
addImportedPackages(rhinoContext, tmpScope, provider.getImportedPackages());
}
// only assign the root scope when complete set up
rootScope = tmpScope;
} finally {
// ensure the context is exited after setting up the
// the new root scope
Context.exit();
}
}
return rootScope;
}
Aggregations