mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Fix unboxing nested functions on RubyRhino
This commit is contained in:
parent
8deaaf16a8
commit
6ffac45215
2 changed files with 11 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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('"\\\\"')
|
||||
|
|
Loading…
Reference in a new issue