Rhino-in-Spring uses interpreted functions throughout. However, it  
assumes all functions are available on all servlet container instances  
and uses serialization stubbing for functions' code, so the serialized  
form doesn't contain the actual function code, just an ID for the  
function that is comprised of the script file name and the lexical  
position within the script. I.e. in case of a script foo.js:

function a()
{
     var x = function()
     {
     }
}

function b()
{
}

"function a" would be identified as "foo.js/0", anonymous function  
within it would be "foo.js/0/0" and "function b" would be "foo.js/1".

It would probably be impossible to come up with a solution that can  
calculate up front which functions you will wish to serialize, and  
which functions you won't. You can create two Context objects: one  
with optimization level set to -1 (interpreted) and one with  
optimization level set to 0 or higher (compiled). Then you can  
selectively compile scripts in one or in the other, and the resulting  
Script objects when executed will define either compiled functions or  
interpreted functions in the top-level scope of that execution  
(regardless of the optimization level of the Context you use for  
execution).

Hope that helps.

Attila.

On 2008.01.30., at 21:15, [EMAIL PROTECTED] wrote:

> Hi,
>
> One goal I have for using Rhino as an application server language is
> to be able to serialize functions in my session between requests. This
> includes potentially deserializing these functions into a different
> Tomcat instance than the one it was serialized in and executing them.
> The documentation seems to indicate that this is possible,
> particularly as long as I manage to exclude all of the supporting
> library code that the serialized function uses on the
> ScriptableOutputStream and the two scopes are identical in all other
> respects.
>
> My question (aside from whether or not I'm completely off the mark
> with the above scenario) is: can I somehow use the compiled behavior
> for all of the code in my application that does not get serialized and
> somehow cause Rhino to generate interpreted functions in this certain
> case?
>
> My desire is to be able to do this:
>
> function display_a_page(a, b, c) {
>  let important_value = do_computation(a, b);
>  let hash_key = generate_hash_key(...);
>  memcache_set(hash_key, function() {
>    do_some_stuff(important_value); // lexical closure
>  });
>  res.getWriter().print("<a href=\"server.foo.com/fnid/" + hash_key +
> "\">click me to get a closure as an event handler!</a>");
> }
>
> And then of course to be able to load balance between multiple Tomcat
> instances on different hardware (but sharing the same distributed
> store via memcache). The idea is that functions like do_computation
> (and all of the functions it depends on) would be compiled if
> possible.
>
> Is this possible? It seems like the Rhino In Spring project does a
> similar thing with continuations, but I'm still too much of a Rhino
> novice for it to be clear to me if those functions are getting
> compiled or not.
>
> Thanks in advance,
> Ben Reesman

_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to