Nashorn and script binding scopes
nashorn
Solution
If a variable is not found in ENGINE_SCOPE, GLOBAL_SCOPE bindings is searched. Nashorn's global object (the one that has JS Object, Number, RegExp, parseInt etc.) is wrapped as Bindings - and that is your ENGINE_SCOPE. For eg. if you put "foo"->"hello" map entry into GLOBAL_SCOPE, that will be visible in scripts - if ENGINE_SCOPE does not have map entry by the name "foo".
Problem
Somewhat confused about ENGINE_SCOPE and GLOBAL_SCOPE binding in Nashorn, trying to follow the discussion here. Before reading this my understanding of scopes (at least in rhino) was that there's a single, shared Bindings in the GLOBAL_SCOPE and individual bindings in ENGINE_SCOPE for each individual engine. However this page seems to be saying that each individual engine stores the basic javascript constructs in bindings that exist in the engines ENGINE_SCOPE (confusingly called the "Nashorn Global Scope"). This sounds like it makes the GLOBAL_SCOPE bindings effectively useless (because they won't have access to any of those basic constructs). What I'm trying to do is create a context that I can inject a few scripts into, and then repeatedly eval different bindings in the context of those scripts. However if the only context I can access is the individual engines ENGINE_SCOPE (because anything above that won't have access to basic javascript constructs) then it seems that any local invocation has to add to those same bindings. Does anyone know how to manage multiple levels of bindings in Nashorn?