Create empty environment?

A. Sundararajan sundararajan.athijegannathan at
Mon Jan 20 21:24:07 PST 2014


You can start your application with the System property


This will avoid initializing properties needed for Java access 
("Packages", "Java", "java", "javax" etc.). Note that the script can 
access Java methods/properties of objects explicitly exposed via 
javax.script.ScriptContext/Bindings (if any). If those are also empty, 
then global scope gets nothing from Java.

Note this still defines certain extensions like 'load' , 'print' in 
global scope as well as "context" (required per jsr223 spec). If you 
want, you can manually delete these properties or assign undefined to 
these by writing a simple init script that is loaded upfront - before 
running the actual script.

Hope this helps,

On Tuesday 21 January 2014 10:45 AM, Peter Michaux wrote:
> Hi,
> When I create a new Nashorn script engine, it seems to come preloaded with globals like `print` which are not part of the ECMAScript standard. How can I create an "empty" environment that only has the globals defined in the standard?
> Thanks,
> Peter

More information about the nashorn-dev mailing list