Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JRuby script engine mucks with parent globals #2239

Closed
byteit101 opened this issue Nov 24, 2014 · 2 comments
Closed

JRuby script engine mucks with parent globals #2239

byteit101 opened this issue Nov 24, 2014 · 2 comments
Milestone

Comments

@byteit101
Copy link
Member

@byteit101 byteit101 commented Nov 24, 2014

When in a ruby context, creating a new ScriptEngineManager and getting the jruby engine from it resets enclosing context's globals to nil, as does setting new bindings:

# using IRB jruby-1.7.16
sem = Java.javax.script.ScriptEngineManager.new
# => #<Java::JavaxScript::ScriptEngineManager:0x5bb21b69> 
$FOO
# => nil 
$FOO = "1"
# => "1" 
jr = sem.getEngineByName("jruby")
# => #<Java::OrgJrubyEmbedJsr223::JRubyEngine:0x7ce6a65d> 
jr.eval("$FOO")
# => "1" 
$FOO
# => nil # What? it stole the global!
$FOO = "2"
# => "2" 
jr.eval("$FOO")
# => "1" 
jr.setBindings(sem.getBindings, javax.script.ScriptContext.ENGINE_SCOPE)
# => nil 
jr.eval("$FOO")
# => "1" 
$FOO
# => nil # What? It reset the global!
$FOO = "3"
# => "3" 
$FOO
# => "3" 
jr.eval("$FOO")
# => "1" 
@yatsura
Copy link

@yatsura yatsura commented Dec 28, 2014

Have confirmed this happens under 1.7.18 and 1.7.11 too. Interestingly, this also happens for any global variable:

sem = Java.javax.script.ScriptEngineManager.new
# => #<Java::JavaxScript::ScriptEngineManager:0x23cdfde8>
$FOO
# => nil
$FOO = "1"
# => "1"
jr = sem.getEngineByName("jruby")
#  => #<Java::OrgJrubyEmbedJsr223::JRubyEngine:0x401845d4>
jr.eval("$FOO")
#  => "1"
$FOO
# => nil
$BAR = "2"
# => "2"
jr.eval("$FOO") # Really access foo again
# => "1"
$BAR
# => nil

@kares
Copy link
Member

@kares kares commented Mar 2, 2018

this will resolve with 91278e7 (in JRuby 9.2)
... for previous versions its a known limitation esp. for JRuby 1.7.x which is now considered dead

@kares kares closed this as completed Mar 2, 2018
@kares kares added this to the Won't Fix milestone Mar 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants