lib/execjs/ruby_rhino_runtime.rb in execjs-2.8.1 vs lib/execjs/ruby_rhino_runtime.rb in execjs-2.9.0

- old
+ new

@@ -1,39 +1,44 @@ require "execjs/runtime" +require "json" module ExecJS class RubyRhinoRuntime < Runtime class Context < Runtime::Context def initialize(runtime, source = "", options = {}) - source = encode(source) + source = source.encode(Encoding::UTF_8) @rhino_context = ::Rhino::Context.new fix_memory_limit! @rhino_context @rhino_context.eval(source) rescue Exception => e raise wrap_error(e) end def exec(source, options = {}) - source = encode(source) + source = source.encode(Encoding::UTF_8) if /\S/ =~ source eval "(function(){#{source}})()", options end end def eval(source, options = {}) - source = encode(source) + source = source.encode(Encoding::UTF_8) if /\S/ =~ source unbox @rhino_context.eval("(#{source})") end rescue Exception => e raise wrap_error(e) 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 = JSON.parse(JSON.generate(args), create_additions: false) + + unbox @rhino_context.eval(properties).call(*converted_args) rescue Exception => e raise wrap_error(e) end def unbox(value)