diff --git a/execjs.gemspec b/execjs.gemspec index 9a85306..3db8b7f 100644 --- a/execjs.gemspec +++ b/execjs.gemspec @@ -25,6 +25,7 @@ Gem::Specification.new do |s| "README.md" ] + s.add_dependency "multi_json", ">=1.0.0" s.add_development_dependency "mustang" s.add_development_dependency "therubyracer" s.add_development_dependency "therubyrhino" diff --git a/lib/execjs/external_runtime.rb b/lib/execjs/external_runtime.rb index a15e3f2..d98892b 100644 --- a/lib/execjs/external_runtime.rb +++ b/lib/execjs/external_runtime.rb @@ -1,4 +1,3 @@ -require "json" require "tempfile" module ExecJS @@ -11,7 +10,7 @@ module ExecJS def eval(source, options = {}) if /\S/ =~ source - exec("return eval(#{"(#{source})".to_json})") + exec("return eval(#{MultiJson.encode("(#{source})")})") end end @@ -22,7 +21,7 @@ module ExecJS end def call(identifier, *args) - eval "#{identifier}.apply(this, #{args.to_json})" + eval "#{identifier}.apply(this, #{MultiJson.encode(args)})" end protected @@ -47,7 +46,7 @@ module ExecJS end def extract_result(output) - status, value = output.empty? ? [] : JSON.parse(output) + status, value = output.empty? ? [] : MultiJson.decode(output) if status == "ok" value else @@ -83,6 +82,7 @@ module ExecJS end def available? + require "multi_json" @binary ? true : false end