Bug? script context doesn't revert if changed during eval

A. Sundararajan sundararajan.athijegannathan at oracle.com
Mon Jun 1 13:27:45 UTC 2015


Hi,

Sorry for the delayed response.

Thanks for the test program. Yes, I confirm that this is a bug. I ported 
your Scala program to java and filed an issue:

https://bugs.openjdk.java.net/browse/JDK-8081609

Thanks,
-Sundar

On Tuesday 19 May 2015 07:06 PM, Dima Golubets wrote:
> Sure,
>
> Here is the code (I have attached zipped sources too).
>
>
> object Program extends App {
>    val factory = new NashornScriptEngineFactory
>    val engine = factory.getScriptEngine
>
>    val globalBindings = engine.createBindings()
>    val engineBindings = engine.getBindings(ScriptContext.ENGINE_SCOPE)
>
>    val context = new SimpleScriptContext()
>    context.setBindings(globalBindings, ScriptContext.GLOBAL_SCOPE)
>    context.setBindings(engineBindings, ScriptContext.ENGINE_SCOPE)
>
>    engineBindings.put("program", this)
>    globalBindings.put("text", "initial text")
>
>    engine.eval(
>      """
>        |print(text);
>        |program.someMethod();
>        |print(text);
>        |
>      """.stripMargin, context)
>
>    /* I would expect the following text output:
>          initial text
>          another text
>          initial text
>
>        However I get:
>          initial text
>          another text
>          another text
>     */
>
>    def someMethod() = {
>
>      val globalBindings = engine.createBindings()
>
>      // a context with a new global bindings, same engine bindings
>      val context = new SimpleScriptContext()
>      context.setBindings(globalBindings, ScriptContext.GLOBAL_SCOPE)
>      context.setBindings(engineBindings, ScriptContext.ENGINE_SCOPE)
>
>      globalBindings.put("text", "another text")
>
>      engine.eval("print(text)", context)
>
>    }
> }
>
>
> On Tue, May 19, 2015 at 2:58 PM A. Sundararajan <
> sundararajan.athijegannathan at oracle.com> wrote:
>
>> Will you please post simple test program demonstrating the problem
>> you're facing?
>>
>> -Sundar
>>
>> Dima Golubets wrote:
>>> Hi!
>>>
>>> I call engine.eval, which calls some Java code which in turn calls eval
>>> again, but with another script context. However this new script context
>>> gets up the call stack somehow and the rest of the javascript code
>>> continues to execute with variables defined in that another context.
>>>
>>> Is it a bug, or eval inside eval is not supported?
>>>
>>



More information about the nashorn-dev mailing list