I'm evaluating scripts in Ruby, and I'd like each script to have it's own sandbox with a global variable called $window. The $window variable should point to something different depending on which sandbox the script is running in. A thread-local variable would work, but I'm not using threads. I'm using the Ruby C API, so that opens the possibilities a bit.
Right now, I run each script within a Binding, so they are somewhat sandboxed there. A binding can have closed local variables, but not globals. Here's the idea:
sandbox1 = window1.get_binding
sandbox2 = window2.get_binding
sandbox3 = window3.get_binding
sandbox1.eval('$window.foo') # calls 'foo' on window 1
sandbox2.eval('$window.foo') # calls 'foo' on window 2
sandbox3.eval('$window.foo') # calls 'foo' on window 3
Is there any way to close a global variable within a Binding? I found a possible solution and posted it below.
javascriptandwebkit?