Object.freeze(this) will not help. Scripts can still add/modify/delete properties of standard built-in constructors and the "prototype"-s of those. Unless all those are also frozen, script side-effect will still be a problem.

-Sundar

On Wednesday 29 October 2014 05:08 AM, John Bernardo wrote:
Hi,

We’re currently working on getting Nashorn to a usable state in our production 
environment and currently focusing on improving performance to reach an 
acceptable state before rollout.

Right now, we’re using ScriptEngine.eval() on the script source to set up the 
JS environment to prevent leaks into the global context. Instead of doing this, 
one idea we’ve been thinking about is using Object.freeze() on our global 
boilerplate and passing that around to each ScriptEngine instance we create 
(one per thread), which could potentially save performance.

Is this approach safe? Is there a better/more performant way to achieve a 
common context? Please advise.

JDK = 1_8_0_5

- JB

Reply via email to