On Feb 27, 2:51 pm, "jbarciela jbarciela" <[EMAIL PROTECTED]> wrote: > Hello all, > > I'm using Rhino to write server side logic inside a servlet container. > > >From the docs I understand that initStandardObjects is expensive so I > > call it once and put the resulting scope it in a static variable. I > also seal the scope to use it from all servlets/threads without > conflicts. Then for every request I create another scope where I will > put the request parameters. > > So far so good. Now the problem is that I want to use the Javascript > Templates from Trimpath > (http://code.google.com/p/trimpath/wiki/JavaScriptTemplates), I load > the library in a String (is small) and do: > > rhinoContext.evaluateString(newScope, stringWithTrimpathCode, > "js/trimpath-template-1.0.38", 1, null); > > but I get the following error: > > org.mozilla.javascript.EvaluatorException: Cannot modify a property of > a sealed object: RegExp. (js/trimpath-template-1.0.38#115) > > I suspect that many libraries will trigger the same issue, is there a > workaround for that in the context of a servler container? > > Thanks > Jaime
JST adds a method to String.prototype (called 'process') and in so doing violates the semantics of a sealed scope. You've got a couple of options that I can think of: - load all of your library code into the global scope before sealing it - don't seal the library scope but rather use it as the prototype (but not the parent) of a thread- or session-specific scope. Any new global variables you create will wind up in this session scope. I'm in the process of developing an extremely lightweight extension on top of Rhino that (hopefully) makes it easy to use server-side JavaScript as a fully general-purpose programming language. It is built with JST in mind and has a little bit of support for it. While Helma and Rhino-In-Spring are far superior as frameworks, for my purposes I wanted something in the spirit of mod_perl that allows me to take or leave the 'framework-like' aspects. It steals techniques for all the hard stuff from Rhino-In-Spring (imitation is the highest form of flattery). Anyways, if this sounds like it might meet your needs or if you want to know more about it then please drop me a line. My company is in the last steps of selecting an open-source licensing arrangement and I'd love to get some feedback on the code. If we're lucky then Yegge et al. will release their stuff as open-source and I can stop thinking about frameworks and go back to writing applications. Regards, Ben Reesman _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
