Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 94552 invoked from network); 28 Oct 2005 09:27:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 28 Oct 2005 09:27:41 -0000 Received: (qmail 77476 invoked by uid 500); 28 Oct 2005 09:27:37 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 77412 invoked by uid 500); 28 Oct 2005 09:27:37 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@cocoon.apache.org List-Id: Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 77394 invoked by uid 99); 28 Oct 2005 09:27:36 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Oct 2005 02:27:36 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [217.115.197.170] (HELO s2.nedstars.nl) (217.115.197.170) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Oct 2005 02:27:33 -0700 Received: from rbe (cp503342-a.venra1.lb.home.nl [84.30.212.98]) by powered-by.parchosting.nl (8.11.6/8.11.6) with ESMTP id j9S9RDd05070 for ; Fri, 28 Oct 2005 11:27:13 +0200 Message-ID: <002a01c5dba2$0db24920$0701a8c0@rbe> From: "Rob Berens" To: Subject: FlowScript: Enforcing exlplicit declaration blocks dynamic loading Date: Fri, 28 Oct 2005 11:28:40 +0200 Organization: Osirion B.V. MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-MailScanner-Information: Please contact the ISP for more information X-MailScanner: Found to be clean X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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: main.js: function loadScript() { var scriptURI = "determineScriptURIFromRequest"; cocoon.load(scriptURI); } When a request comes in, the sitemap calls the function loadScript(). Let's say loadScript determines that it needs to load myScript.js. myScript.js: var myVar = "myValue"; // This results in an error when loaded from main.js. "doSomething"; 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 org.apache.cocoon.components.flow.javascript.fom.FOM_Cocoon.java into: public Object jsFunction_load( String filename ) throws Exception { org.mozilla.javascript.Context cx = org.mozilla.javascript.Context.getCurrentContext(); FOM_JavaScriptInterpreter.ThreadScope scope = (FOM_JavaScriptInterpreter.ThreadScope)getParentScope(); Script script = getInterpreter().compileScript(cx, filename); Object obj; synchronized(scope) { scope.setLock(false); obj = script.exec( cx, scope ); scope.setLock(true); } 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 E-mail: rberens@osirion.nl