Sharing native JavaScript objects across contexts

Sundararajan Athijegannathan sundararajan.athijegannathan at
Wed Dec 9 11:33:24 UTC 2015

This is in response to 
[ I accidentally deleted the original email ]

Yes, objects from other ScriptContexts are indeed foreign - but nashorn 
allows you to call functions, access properties and so on.And even when 
you're using multiple ScriptContexts in the same engine -- compiled 
Classes (java.lang.Class instances) are shared. i.e., so long as you use 
same script, Nashorn will re-use Class objects.
i.e., compiled code sharing is on per-engine basis. So, you can eval 
"common code" again and again -- you'll be re-using same Class object.

You don't share ECMAScript global objects (which are in ENGINE_SCOPE of 
the ScriptContexts you use) -- but that is only about objects including 
function objects. But you still share nashorn compiled code -- so long 
as you use the same script engine instance.

Hope that answers your concerns,

More information about the nashorn-dev mailing list