Details
-
Bug
-
Resolution: Fixed
-
P4
-
None
-
None
-
b82
-
generic
-
generic
Description
User should be able to create new global object using ScriptEngine.createBindings API.
ScriptEngine engine; // initialization skipped
Bindings newGlobal = engine.createBindings();
ScriptContext ctx = new ScriptContext();
ctx.setBindings(newGlobal, ScriptContext.ENGINE_SCOPE);
engine.eval("Object"); // refers to "Object" from default context's engine bindings
engine.eval("Object", ctx); // refers to "Object" from given context's engine bindings.
If engine_scope bindings of a ScriptContext is not nashorn engine created (by createBindings call), nashorn can fallback to use default global scope created for default context.
This essentially exposes nashorn's multiple-global-per-context feature (used in testruns) via standard API.
ScriptEngine engine; // initialization skipped
Bindings newGlobal = engine.createBindings();
ScriptContext ctx = new ScriptContext();
ctx.setBindings(newGlobal, ScriptContext.ENGINE_SCOPE);
engine.eval("Object"); // refers to "Object" from default context's engine bindings
engine.eval("Object", ctx); // refers to "Object" from given context's engine bindings.
If engine_scope bindings of a ScriptContext is not nashorn engine created (by createBindings call), nashorn can fallback to use default global scope created for default context.
This essentially exposes nashorn's multiple-global-per-context feature (used in testruns) via standard API.