Skip to content

Commit 7a4f7de

Browse files
committed
Add test for passing Symbol to JS and fix it for GraalJSRuntime and RubyRhinoRuntime
1 parent 39118e2 commit 7a4f7de

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

lib/execjs/graaljs_runtime.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def convert_js_to_ruby(value)
9494

9595
def convert_ruby_to_js(value)
9696
case value
97-
when nil, true, false, Integer, Float, String
97+
when nil, true, false, Integer, Float, String, Symbol
9898
value
9999
when Array
100100
value.map { |e| convert_ruby_to_js(e) }

lib/execjs/ruby_rhino_runtime.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ def eval(source, options = {})
3232
end
3333

3434
def call(properties, *args)
35-
unbox @rhino_context.eval(properties).call(*args)
35+
# Might no longer be necessary if therubyrhino handles Symbols directly:
36+
# https://github.com/rubyjs/therubyrhino/issues/43
37+
converted_args = args.map { |arg| Symbol === arg ? arg.to_s : arg }
38+
39+
unbox @rhino_context.eval(properties).call(*converted_args)
3640
rescue Exception => e
3741
raise wrap_error(e)
3842
end

test/test_execjs.rb

+5
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ def test_context_call_missing_function
167167
end
168168
end
169169

170+
def test_symbol
171+
context = ExecJS.compile("function echo(test) { return test; }")
172+
assert_equal "symbol", context.call("echo", :symbol)
173+
end
174+
170175
def test_additional_options
171176
assert ExecJS.eval("true", :foo => true)
172177
assert ExecJS.exec("return true", :foo => true)

0 commit comments

Comments
 (0)