use of org.mozilla.javascript.ClassShutter in project neo4j by neo4j.
the class GlobalJavascriptInitializer method initialize.
public static synchronized void initialize(Mode requestedMode) {
if (initializationMode != null) {
if (initializationMode == requestedMode) {
return;
} else {
throw new RuntimeException("Cannot initialize javascript context twice, " + "system is currently initialized as: '" + initializationMode.name() + "'.");
}
}
initializationMode = requestedMode;
ContextFactory contextFactory;
switch(requestedMode) {
case UNSAFE:
contextFactory = new ContextFactory() {
protected Context makeContext() {
Context cx = super.makeContext();
cx.setLanguageVersion(Context.VERSION_1_7);
// TODO: This goes up to 9, do performance tests to determine appropriate level of optimization
cx.setOptimizationLevel(4);
return cx;
}
};
break;
default:
contextFactory = new ContextFactory() {
protected Context makeContext() {
Context cx = super.makeContext();
ClassShutter shutter = new WhiteListClassShutter(UserScriptClassWhiteList.getWhiteList());
cx.setLanguageVersion(Context.VERSION_1_7);
// TODO: This goes up to 9, do performance tests to determine appropriate level of optimization
cx.setOptimizationLevel(4);
cx.setClassShutter(shutter);
cx.setWrapFactory(new WhiteListJavaWrapper(shutter));
return cx;
}
};
break;
}
ContextFactory.initGlobal(contextFactory);
}
use of org.mozilla.javascript.ClassShutter in project OpenAM by OpenRock.
the class RhinoScriptEngineFactory method getContext.
/**
* Gets a fresh Rhino {@link org.mozilla.javascript.Context} object by calling
* {@link org.mozilla.javascript.ContextFactory#enterContext()}. The returned context object will be configured
* with any specified class shutter and optimisation level settings before being returned. Each call to this
* method should be accompanied by a call to {@link #releaseContext(org.mozilla.javascript.Context)} when the
* context is no longer required. It is recommended to use a try-finally pattern for this, like:
* <pre>
* final Context context = factory.getContext();
* try {
* // Use context
* } finally {
* factory.releaseContext(context);
* }
* </pre>
*
* @return the freshly configured context object.
*/
Context getContext() {
final Context context = contextFactory.enterContext();
context.setOptimizationLevel(optimisationLevel);
final ClassShutter sandbox = classShutter;
if (sandbox != null) {
context.setClassShutter(sandbox);
}
return context;
}
Aggregations