Search in sources :

Example 1 with ClassCache

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);
}
Also used : Context(org.mozilla.javascript.Context) ContextAction(org.mozilla.javascript.ContextAction) ImportInfo(io.sf.carte.echosvg.script.ImportInfo) ClassCache(org.mozilla.javascript.ClassCache) Scriptable(org.mozilla.javascript.Scriptable) RhinoClassLoader(io.sf.carte.echosvg.script.rhino.RhinoClassLoader)

Example 2 with ClassCache

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);
    }
}
Also used : ClassCache(org.mozilla.javascript.ClassCache)

Example 3 with ClassCache

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;
}
Also used : ClassCache(org.mozilla.javascript.ClassCache)

Example 4 with ClassCache

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);
}
Also used : JavaMembers(org.mozilla.javascript.JavaMembers) ClassCache(org.mozilla.javascript.ClassCache)

Aggregations

ClassCache (org.mozilla.javascript.ClassCache)4 ImportInfo (io.sf.carte.echosvg.script.ImportInfo)1 RhinoClassLoader (io.sf.carte.echosvg.script.rhino.RhinoClassLoader)1 Context (org.mozilla.javascript.Context)1 ContextAction (org.mozilla.javascript.ContextAction)1 JavaMembers (org.mozilla.javascript.JavaMembers)1 Scriptable (org.mozilla.javascript.Scriptable)1