Skip to content

Commit

Permalink
Merge pull request #117 from eregon/fix-symbol-conversion
Browse files Browse the repository at this point in the history
Convert Symbol explicitly to a JS String and add test
  • Loading branch information
byroot committed Jul 19, 2022
2 parents 82dbb78 + 9e0855d commit e553b3f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/execjs/graaljs_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ def convert_ruby_to_js(value)
case value
when nil, true, false, Integer, Float
value
when String
when String, Symbol
Truffle::Interop.as_truffle_string value
when Symbol
value.to_s
when Array
value.map { |e| convert_ruby_to_js(e) }
when Hash
Expand Down
3 changes: 3 additions & 0 deletions test/test_execjs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ def test_symbol
assert_equal "symbol", context.call("echo", :symbol)
assert_equal ["symbol"], context.call("echo", [:symbol])
assert_equal({"key" => "value"}, context.call("echo", {key: :value}))

context = ExecJS.compile("function myslice(str) { return str.slice(1); }")
assert_equal "ymbol", context.call("myslice", :symbol)
end

def test_additional_options
Expand Down

0 comments on commit e553b3f

Please sign in to comment.