Rhino embedding

Does anyone understand javascript contexts for rhino? I cannot find any useful documentation about this. My main problem is Context.exit () (actually it should be cx.exit ()), which, from what I understand, comes out of the context associated with the current thread? Does this mean that I need to track what the thread is doing?

main theme:

Context cx;
cx.evaluateReader( ... ) // load some function
start thread 2

stream 2:

Object o= scope.get("methodname", scope);
((Function)o).call( ... )

I don't plan on doing multithreading, but what if different settings come from different threads?

+5
source share
1 answer

From docs :

Rhino , , . , , JavaScript.

, . . Context.enter() . , . Context.enter() - .

docs:

, , . , . , .

:

Context ctx = Context.enter();
try {
    // do something with the ctx
} finally {
    Context.exit();
}

, Groovy :

def withContext(Closure closure) {
    Context ctx = Context.enter();
    try {
        closure.call(ctx);
    } finally {
        Context.exit();
    }
}

, :

withContext { Context ctx ->
    ScriptableObject scope = ctx.initStandardObjects()
    // now to do work with the scope and ctx.
}

. / .

+13

All Articles