You can access the function's InterpreterData using Context.getDebuggableView() 
and walking the functions tree, but that won't get you far as it doesn't give 
you execution facilities. 

What I think you want to do is: create a scope to hold the functions, execute 
the script into it, then retrieve the functions from it:

ScriptableObject functionsHolder = cx.initStandardObjects();
script.exec(cx, functionHolder);

then when you need to invoke a function by name (myFunctionName), and pass it 
some arguments (someArgs) you can do this:

Callable callable = ScriptableObject.getProperty(functionsHolder, 
myFunctionName);
Object retval = callable.call(cx, functionsHolder, functionsHolder, someArgs)

(obviously, you can create different scopes for any side effects, if that's 
your intent) 

Attila.

On 2010.03.03., at 14:23, Johan Compagner wrote:

> problem is that we dont compile a js file with many functions
> But we compile a piece of script that is 1 function.
> We need to have access to the function object not to a script
> 
> Because from the outside world (java) tells us now execute this function by
> that name in rhino
> 
> And i dont see a way to ask a Script object for one of itsfunctions and
> execute that. Instead of the script itself.
> 
> johan
> 
> 
> On Wed, Mar 3, 2010 at 13:51, Attila Szegedi <[email protected]> wrote:
> 
>> InterpreterData is immutable after compilation. If you execute the same
>> org.mozilla.javascript.Script object obtained through
>> Context.compileReader() in different scopes, the functions it defines will
>> share the same InterpreterData instance.
>> 
>> The trick is thus to compile a source .js file once into a Script object,
>> and then use it for repeated execution.
>> 
>> Attila.
>> 
>> On 2010.03.03., at 13:36, Johan Compagner wrote:
>> 
>>> Hi,
>>> 
>>> We have 2 kind of clients, 1 is a swing client and there there is not
>> really
>>> a problem
>>> But the other is a web client that runs on the server
>>> 
>>> There we can have for example 10 clients and if i look what the total
>>> InterpreterData object size is for those 10 clients is is that 75MB mem
>>> usage
>>> But that is pretty much all the same kind of data. So if i could share
>> that
>>> then that would be 7.5MB of total of InterpreterData objects
>>> that then is reused by a InterpretedFunction function that is tied to a
>>> specific client.
>>> 
>>> The question is does InterpreterData has changing state? Or is it after
>>> compile static?
>>> 
>>> johan
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to