Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 80964 invoked from network); 17 Oct 2005 19:30:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 17 Oct 2005 19:30:07 -0000 Received: (qmail 55781 invoked by uid 500); 17 Oct 2005 19:29:58 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 55677 invoked by uid 500); 17 Oct 2005 19:29:56 -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 55640 invoked by uid 99); 17 Oct 2005 19:29:55 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Oct 2005 12:29:55 -0700 X-ASF-Spam-Status: No, hits=2.6 required=10.0 tests=RCVD_IN_BL_SPAMCOP_NET,RCVD_IN_SORBS_WEB X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [212.85.125.162] (HELO v07274.home.net.pl) (212.85.125.162) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 17 Oct 2005 12:29:55 -0700 Received: from gprs6.orange.pl (HELO ?172.20.116.67?) (lgawron.mobilebox@home@217.116.100.252) by matrix15.home.net.pl with SMTP; Mon, 17 Oct 2005 19:29:28 -0000 Message-ID: <4353FB94.1000203@mobilebox.pl> Date: Mon, 17 Oct 2005 21:29:24 +0200 From: Leszek Gawron User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: dev@cocoon.apache.org Subject: Re: JavaScript expressions in JXTG (was Re: svn commit: r325889) References: <20051017132455.70460.qmail@minotaur.apache.org> <4353BA53.60309@mobilebox.pl> <1129561592.15983.18.camel@localhost.localdomain> <4353C08C.2050005@apache.org> <4353C502.1080302@mobilebox.pl> <4353D2E1.3060905@apache.org> In-Reply-To: <4353D2E1.3060905@apache.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Sylvain Wallez wrote: > Leszek Gawron wrote: > >> Sylvain Wallez wrote: >> >>> Actually, I'm more and more annoyed by Jexl: JXTemplate is the *only* >>> place in Cocoon where Jexl is used, and I would love to see it >>> replaced by JavaScript expressions. Script/expression language >>> consistency throughout Cocoon... >> >> hmmm... we have touched the subject once. At the time you have pointed >> me with some javascript helper class to get the basics of rhino but I >> lost that message. Do you happen to remember what class it was? >> >> This shouldn't be 'that' hard. > > > Oh no, damn easy! See JavaScriptHelper in CForms. Hmm.. looking at JavaScriptHelper I see you broke it again :) > Index: C:/dev/apache-projects/cocoon-2.2.x/src/blocks/forms/trunk/java/org/apache/cocoon/forms/util/JavaScriptHelper.java > =================================================================== > --- C:/dev/apache-projects/cocoon-2.2.x/src/blocks/forms/trunk/java/org/apache/cocoon/forms/util/JavaScriptHelper.java (revision 289537) > +++ C:/dev/apache-projects/cocoon-2.2.x/src/blocks/forms/trunk/java/org/apache/cocoon/forms/util/JavaScriptHelper.java (revision 289538) > @@ -23,7 +23,6 @@ > import org.apache.avalon.framework.CascadingRuntimeException; > import org.apache.cocoon.components.flow.FlowHelper; > import org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptFlowHelper; > -import org.apache.cocoon.environment.TemplateObjectModelHelper; > import org.mozilla.javascript.Context; > import org.mozilla.javascript.Function; > import org.mozilla.javascript.JavaScriptException; > @@ -39,7 +38,13 @@ > * @version $Id$ > */ > public class JavaScriptHelper { > + > /** > + * A shared root scope, avoiding to recreate a new one each time. > + */ > + private static Scriptable _rootScope = null; > + > + /** > * Build a script with the content of a DOM element. > * > * @param element the element containing the script > @@ -111,7 +116,20 @@ > * @return an appropriate root scope > */ > public static Scriptable getRootScope() { > - return TemplateObjectModelHelper.getScope(); > + // FIXME: TemplateOMH should be used in 2.2 > + //return TemplateObjectModelHelper.getScope(); > + > + > + if (_rootScope == null) { > + // Create it if never used up to now > + Context ctx = Context.enter(); > + try { > + _rootScope = ctx.initStandardObjects(null); > + } finally { > + Context.exit(); > + } > + } > + return _rootScope; > } > > /** this is the former logic of JavaScriptHelper which is invalid because of the fact that _rootScope is not thread safe. Please have look at how TemplateOMH does it: public static Scriptable getScope() { Context ctx = Context.enter(); try { // Create it if never used up to now if (rootScope == null) rootScope = ctx.initStandardObjects(null); Scriptable scope = ctx.newObject(rootScope); scope.setPrototype(rootScope); scope.setParentScope(null); return scope; } finally { Context.exit(); } } (shouldn't we wrap this code with synchronized block?) -- Leszek Gawron lgawron@mobilebox.pl IT Manager MobileBox sp. z o.o. +48 (61) 855 06 67 http://www.mobilebox.pl mobile: +48 (501) 720 812 fax: +48 (61) 853 29 65