Issue1535

classification
Title: JSR-223 - Cannot override engine scope's bindings
Type: Severity: major
Components: Core Versions: 2.5.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: nriley Nosy List: nriley, tiago182
Priority: Keywords:

Created on 2010-01-06.13:39:22 by tiago182, last changed 2010-01-24.00:38:11 by nriley.

Messages
msg5411 (view) Author: Tiago Fernandez (tiago182) Date: 2010-01-06.13:39:22
While processing scripts, Jython does not take into account the bindings it gets through PyScriptEngine.eval() method:

import org.junit.Test;

import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.SimpleBindings;

public class TestJSR223BindingsWithJython {

  @Test public void should_set_bindings_to_engine_scope() throws Exception {
    final ScriptEngineManager manager = new ScriptEngineManager();
    final ScriptEngine engine = manager.getEngineByName("jython");

    final Bindings bindings = new SimpleBindings();
    bindings.put("name", "Tiago");

    engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
    engine.eval("print \"Hello, \" + name + \"!\"");
  }

  @Test public void should_override_engine_scopes_bindings() throws Exception {
    final ScriptEngineManager manager = new ScriptEngineManager();
    final ScriptEngine engine = manager.getEngineByName("jython");

    final Bindings bindings = new SimpleBindings();
    bindings.put("name", "Tiago");

    engine.eval("print \"Hello, \" + name + \"!\"", bindings);
    
    /*
    javax.script.ScriptException: NameError: name 'name' is not defined in <script> at line number 1
      at org.python.jsr223.PyScriptEngine.scriptException(PyScriptEngine.java:182)
      at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:43)
      at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:33)
      at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:216)
      at TestJSR223BindingsWithJython.should_override_engine_scopes_bindings(TestJSR223BindingsWithJython.java:29)
      ...
    */
  }
}

Maybe it's related to #1426.
msg5451 (view) Author: Nicholas Riley (nriley) Date: 2010-01-24.00:38:11
This should be fixed in Jython trunk. Please let me know if it isn't.
History
Date User Action Args
2010-01-24 00:38:11nrileysetstatus: open -> closed
resolution: fixed
messages: + msg5451
2010-01-06 16:19:05nrileysetassignee: nriley
nosy: + nriley
2010-01-06 13:39:22tiago182create