Stack scopes / bindings?
A. Sundararajan
sundararajan.athijegannathan at oracle.com
Fri Jan 30 04:38:53 UTC 2015
Hi.
A script engine has an associated (default) ScriptContext instance. A
ScriptContext has ENGINE_SCOPE and GLOBAL_SCOPE bindings in it.
ENGINE_SCOPE which is the same as a "global" object of ECMAScript (has
properties like "Object", "Function", "undefined", "parseInt" etc.). If
a variable is missing in ENGINE_SCOPE, then it is searched in GLOBAL_SCOPE.
For more details, please check out
https://wiki.openjdk.java.net/display/Nashorn/Nashorn+jsr223+engine+notes
Hope this helps,
-Sundar
On Thursday 29 January 2015 07:30 PM, Nicolas ALBERT wrote:
> I used to use Rhino and to stack scope through Scriptable.setParentScope
>
> I can not find an equivalent with Bindings or ScriptContext.
>
>
> - if a variable is defined without var, it's a global variable (root
> scope)
> - if a variable is defined with var, it's a local variable (current
> scope)
> - if a variable is accessed or modified, engine lookup in its current
> scope, and parent, and parent parent ... and the global scope
>
> I miss something or this behavior (with setParentScope) doesn't exist ?
>
> Thanks
More information about the nashorn-dev
mailing list