cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rob Berens" <>
Subject FlowScript: Enforcing exlplicit declaration blocks dynamic loading
Date Fri, 28 Oct 2005 09:28:40 GMT
In 2.1.6. explicit declaration of variables in global scope was enforced
(fix 25951).
This was implemented by locking the scope after the main part of the main
script has been loaded and processed.
In our situation we have one generic script loaded form the sitemap once,
that determines the name of the script to be loaded based on the request and
than loads that script. Simplified it's like this.
The sitemap loads the script main.js:


function loadScript() {
    var scriptURI = "determineScriptURIFromRequest";

When a request comes in, the sitemap calls the function loadScript(). Let's
say loadScript determines that it needs to load myScript.js.


var myVar = "myValue"; // This results in an error when loaded from main.js.


In this way we have a mechanism to load scripts dynamically without knowing
their names before hand.
The problem is that after loading the initial main.js the global scope is
locked, which results in an error on "var myVar = .....".

I solved by changing the jsFunction_Load method in into:

    public Object jsFunction_load( String filename )
        throws Exception {
        org.mozilla.javascript.Context cx =
        FOM_JavaScriptInterpreter.ThreadScope scope =
        Script script = getInterpreter().compileScript(cx, filename);
        Object obj;
        synchronized(scope) {
            obj = script.exec( cx, scope );
        return obj;

In this way the scope is temporarily unlocked during the load of the script.
This works fine. There is however one problem. The scope in FOM_Cocoon will
always be an instance of FOM_JavaScriptInterpreter.ThreadScope, but this is
not explicitly known in FOM_Cocoon. I just made this assumption to get
things working. So we might need a better solution..

Is there any GURU who can help? Can this be solved in 2.1.8?

Rob Berens
Osirion B.V.
Gagelveld 41
6596 CC  Milsbeek
The Netherlands
Tel: +31 (0)485-54 02 03
Fax: +31 (0)485-54 02 04

View raw message