use of org.mozilla.javascript.ImporterTopLevel 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;
}
use of org.mozilla.javascript.ImporterTopLevel in project stetho by facebook.
the class JsRuntimeReplFactoryBuilder method initJsScope.
@NonNull
private ScriptableObject initJsScope(@NonNull Context jsContext) {
// Set the main Rhino goodies
ImporterTopLevel importerTopLevel = new ImporterTopLevel(jsContext);
ScriptableObject scope = jsContext.initStandardObjects(importerTopLevel, false);
ScriptableObject.putProperty(scope, "context", Context.javaToJS(mContext, scope));
try {
importClasses(jsContext, scope);
importPackages(jsContext, scope);
importConsole(scope);
importVariables(scope);
importFunctions(scope);
} catch (StethoJsException e) {
String message = String.format("%s\n%s", e.getMessage(), Log.getStackTraceString(e));
LogUtil.e(e, message);
CLog.writeToConsole(Console.MessageLevel.ERROR, Console.MessageSource.JAVASCRIPT, message);
}
return scope;
}
use of org.mozilla.javascript.ImporterTopLevel in project neo4j by neo4j.
the class JavascriptExecutor method createPrototype.
private Scriptable createPrototype(Context cx) {
Scriptable proto = cx.initStandardObjects();
Scriptable topLevel = new ImporterTopLevel(cx);
proto.setParentScope(topLevel);
return proto;
}
use of org.mozilla.javascript.ImporterTopLevel in project jmeter by apache.
the class BSFJavaScriptEngine method initialize.
/**
* Initialize the engine.
* Put the manager into the context-manager
* map hashtable too.
*/
@Override
public void initialize(BSFManager mgr, String lang, // superclass does not support types
@SuppressWarnings("rawtypes") Vector declaredBeans) throws BSFException {
super.initialize(mgr, lang, declaredBeans);
// Initialize context and global scope object
try {
Context cx = Context.enter();
global = new ImporterTopLevel(cx);
Scriptable bsf = Context.toObject(new BSFFunctions(mgr, this), global);
global.put("bsf", global, bsf);
// superclass does not support types
@SuppressWarnings("unchecked") final Vector<BSFDeclaredBean> beans = declaredBeans;
for (BSFDeclaredBean declaredBean : beans) {
declareBean(declaredBean);
}
} catch (Throwable t) {
// NOSONAR We handle correctly Error case in function
handleError(t);
} finally {
Context.exit();
}
}
Aggregations