use of org.mozilla.javascript.ClassCache in project echosvg by css4j.
the class RhinoInterpreter method init.
protected void init(URL documentURL, final ImportInfo imports) {
try {
rhinoClassLoader = new RhinoClassLoader(documentURL, getClass().getClassLoader());
} catch (SecurityException se) {
rhinoClassLoader = null;
}
ContextAction<?> initAction = new ContextAction<Object>() {
@Override
public Object run(Context cx) {
Scriptable scriptable = cx.initStandardObjects(null, false);
defineGlobalWrapperClass(scriptable);
globalObject = createGlobalObject(cx);
ClassCache cache = ClassCache.get(globalObject);
cache.setCachingEnabled(rhinoClassLoader != null);
ImportInfo ii = imports;
if (ii == null)
ii = ImportInfo.getImports();
// import Java lang package & DOM Level 3 & SVG DOM packages
StringBuffer sb = new StringBuffer();
Iterator<String> iter;
iter = ii.getPackages();
while (iter.hasNext()) {
String pkg = iter.next();
sb.append("importPackage(Packages.");
sb.append(pkg);
sb.append(");");
}
iter = ii.getClasses();
while (iter.hasNext()) {
String cls = iter.next();
sb.append("importClass(Packages.");
sb.append(cls);
sb.append(");");
}
cx.evaluateString(globalObject, sb.toString(), null, 0, rhinoClassLoader);
return null;
}
};
contextFactory.call(initAction);
}
use of org.mozilla.javascript.ClassCache in project echosvg by css4j.
the class RhinoInterpreter method dispose.
/**
* For <code>RhinoInterpreter</code> this method flushes the Rhino caches to
* avoid memory leaks.
*/
@Override
public void dispose() {
if (rhinoClassLoader != null) {
ClassCache cache = ClassCache.get(globalObject);
cache.setCachingEnabled(false);
}
}
use of org.mozilla.javascript.ClassCache in project servoy-client by Servoy.
the class InstanceJavaMembers method deRegisterClass.
public static void deRegisterClass(Scriptable scope) {
ClassCache cache = ClassCache.get(scope);
cache.getClassCacheMap().clear();
cache = null;
}
use of org.mozilla.javascript.ClassCache in project servoy-client by Servoy.
the class InstanceJavaMembers method registerClass.
static void registerClass(Scriptable scope, Class<?> cls, InstanceJavaMembers ijm) {
ClassCache cache = ClassCache.get(scope);
Map<Class<?>, JavaMembers> ct = cache.getClassCacheMap();
ct.put(cls, ijm);
}
Aggregations