cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Oliver <>
Subject Re: JavaScriptInterpreter: bug or feature?
Date Thu, 20 Mar 2003 03:47:59 GMT
Hold on, Vadim. I'll fix that shortly. It's only there for testing 
compiling with different scopes. I think it's good that you're visually 
inspecting the code for problems, but I think we should focus more on 
externally visible problems rather than code inspection at this point.

What I'm trying to accomplish here is to share code between users 
(meaning we don't have to duplicate immutable objects like scripts, 
thereby saving memory).

Perhaps you can help by explaining how and when instances of 
JavaScriptInterpreter get created. Is it per sitemap?

With Rhino, script variables are stored in a "scope" object - which must 
be created on a per user basis. This is the "thrScope" variable you see 
in However, it's possible to share the 
built-in JavaScript objects, like String, Number, etc. as well as 
scripts loaded by the sitemap (system.js, etc) since these are immutable 
objects, among all the thrScope's. This shared scope is the "scope" 
field in

When you request the property of an object in JavaScript the interpreter 
performs the lookup in the following way:

   Search the object itself
   Search the object's prototype chain
   Search the object's parent scope

The thrScope's parent scope is null, so it becomes the global variable 
scope for the user, but we set its prototype to be the shared "scope", 
so builtin objects are located in the shared scope.

I wanted to test if I could successfully compile scripts using the 
shared scope instead of in thrScope, and it does indeed seem to work.

Now my question:

I only want to compile and execute the set of scripts that apply to a 
specific application. I don't want them shared between different 
applications. I think I remember Ovidiu saying that each (sub-)sitemap 
should represent a single application. Does that make sense? If so, 
would each one its own instance of JavaScriptInterpreter?




Vadim Gritsenko wrote:
> Can somebody knowledgable comment on the following method? Local 
> variable scope is not used...
>    private Script compileScript(Context cx, Scriptable scope,
>                                 Source src) throws Exception {
>        InputStream is = src.getInputStream();
>        Reader reader = new BufferedReader(new InputStreamReader(is));
>        // FIXME: scope or this.scope?
>        Script compiledScript = cx.compileReader(this.scope, reader,
>                                                 src.getURI(),
>                                                 1, null);
>        return compiledScript;
>    }
> Thanks,
> Vadim

View raw message