Skip to content

Commit

Permalink
Add test for passing Symbol to JS and fix it for GraalJSRuntime and R…
Browse files Browse the repository at this point in the history
…ubyRhinoRuntime
  • Loading branch information
eregon committed Jan 27, 2022
1 parent 39118e2 commit 7a4f7de
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/execjs/graaljs_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def convert_js_to_ruby(value)

def convert_ruby_to_js(value)
case value
when nil, true, false, Integer, Float, String
when nil, true, false, Integer, Float, String, Symbol
value
when Array
value.map { |e| convert_ruby_to_js(e) }
Expand Down
6 changes: 5 additions & 1 deletion lib/execjs/ruby_rhino_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def eval(source, options = {})
end

def call(properties, *args)
unbox @rhino_context.eval(properties).call(*args)
# Might no longer be necessary if therubyrhino handles Symbols directly:
# https://github.com/rubyjs/therubyrhino/issues/43
converted_args = args.map { |arg| Symbol === arg ? arg.to_s : arg }

unbox @rhino_context.eval(properties).call(*converted_args)
rescue Exception => e
raise wrap_error(e)
end
Expand Down
5 changes: 5 additions & 0 deletions test/test_execjs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ def test_context_call_missing_function
end
end

def test_symbol
context = ExecJS.compile("function echo(test) { return test; }")
assert_equal "symbol", context.call("echo", :symbol)
end

def test_additional_options
assert ExecJS.eval("true", :foo => true)
assert ExecJS.exec("return true", :foo => true)
Expand Down

0 comments on commit 7a4f7de

Please sign in to comment.