I've been using Johnson's gem and have discovered some (sort of)
bugs, but still have no time to check what the precise problem
is.
There seems to be a compatibility problem between arrays from
the Ruby land in JS, as their behaviour is different:
require 'rubygems'
require 'johnson'
Js = Johnson::Runtime.new
Js['alert'] = lambda { |x| puts x }
# Let's test JS arrays
Js.evaluate('array = [1,2,3,4]')
Js.evaluate('for (i in array) { alert(i) }') # 0 1 2 3
Js.evaluate('for (i in array) { alert(array[i]) }') # 1 2 3 4
# Let's test Ruby arrays acting as JS arrays
Js['array'] = [1,2,3,4]
Js.evaluate('for (i in array) { alert(i) }') # 2 3 4 5 (should be 0 1 2 3)
Js.evaluate('for (i in array) { alert(array[i]) }') # 2 3 4 nil (should be 1 2 3 4)
Also, if I add a function to Array.prototype, it is not
available in arrays from the Ruby land, so there are
incompatibilities between JS & Ruby lands. Similarly, hashes
show different behaviours in each land.