diff --git a/lib/execjs/ruby_rhino_runtime.rb b/lib/execjs/ruby_rhino_runtime.rb index b971bd6..e6d5f8a 100644 --- a/lib/execjs/ruby_rhino_runtime.rb +++ b/lib/execjs/ruby_rhino_runtime.rb @@ -42,14 +42,21 @@ module ExecJS end def unbox(value) - case value + case value = ::Rhino::To.ruby(value) when ::Rhino::NativeFunction nil when ::Rhino::NativeObject value.inject({}) do |vs, (k, v)| - vs[k] = unbox(v) unless v.is_a?(::Rhino::NativeFunction) + case v + when ::Rhino::NativeFunction, ::Rhino::J::Function + nil + else + vs[k] = unbox(v) + end vs end + when Array + value.map { |v| unbox(v) } else value end diff --git a/test/test_runtime.rb b/test/test_runtime.rb index 2b4f44e..313cf29 100644 --- a/test/test_runtime.rb +++ b/test/test_runtime.rb @@ -29,8 +29,10 @@ class TestRuntime < Test::Unit::TestCase assert_equal 0, @runtime.eval("0") assert_equal true, @runtime.eval("true") assert_equal [1, 2], @runtime.eval("[1, 2]") + assert_equal [1, nil], @runtime.eval("[1, function() {}]") assert_equal "hello", @runtime.eval("'hello'") assert_equal({"a"=>1,"b"=>2}, @runtime.eval("{a:1,b:2}")) + assert_equal({"a"=>true}, @runtime.eval("{a:true,b:function (){}}")) assert_equal "café", @runtime.eval("'café'") assert_equal "☃", @runtime.eval('"☃"') assert_equal "\\", @runtime.eval('"\\\\"')