Problem is, Rhino doesn't allow a second context to be associated with a thread while one context is associated with it. You need to exit the context in A1 before invoking the context in B1.

As a matter of fact, I believe this is suboptimal design - it acts as a global interference (for a given thread) and thus hinders composability (i.e. someone using Rhino can't call a method on a Java bean that internally also uses Rhino to execute some JS code, and it would like to do so with different settings - exactly your problem, if I read it correctly).

Norris, Hannes: this appears to be enforced by this code in Context.enter(Context, ContextFactory):

        Context old = VMBridge.instance.getContext(helper);
        if (old != null) {
            cx = old;
        } else {
        ...

It seems to me we should allow nesting of contexts within a thread for this purpose - Context.enter() with a different ContextFactory than the current one should create a new Context through that factory, and a corresponding Context.exit() should restore the previous Context instance.

(BTW, can we keep the discussion on the list?)

Attila.

On 2009.03.06., at 5:19, Anupama Joshi wrote:

Hi,
 Here is the description of my problem
        •  I have 2  separate applications  having rhino implementation
        •  Assume that the names are A1 and B1.
• A1 and B1 can run separately and co exist where A1 depends on B1.jar. • A1 implements a ContextFactory and a context. Sets security controller and ClassShutter in MakeCOntext() of CotextFactory say A1ContextFactory • A1 starts Rhino first , creates context , does context.eneter() executes script and then calls B1's Rhino engine execution. • B1 has initialization like this - if (Context.getCurrentContext() == null)
            Context.enter();
        moContext = Context.getCurrentContext();
        System.out.println(moContext);
        //
        // Disable all LiveConnect features.
        //
        synchronized (RhinoEngine.class) {
            if (! gLiveConnectDisabled) {
                moContext.setClassShutter(new ClassShutter() {
                    public boolean visibleToScripts(String name) {
                        return false;
                    }
                });
                gLiveConnectDisabled = true;
            }
• When A1 has executed a script before going to B1 the current thread dooes not have a context but as soon as A1 has executed a script with Context.enter() etc.. The context which the B1 in step 6 gets has classshutter from A1 and so the setClassShutter as described above throws security exception. • The only thing I could think of is to use moContext = new Context(). Which will have no association with the A1's context and B1 will have no problem while operating independently or in collaborative environment of A1 +B1. • Is there any other solution which can be done onA1 to solve this problem.?
 This is a very critical issue for me. Any help will be appreciated.
Thanks a lot
-Anupama
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to