1
0
Fork 0
mirror of https://github.com/rails/execjs synced 2023-03-27 23:21:20 -04:00

Merge pull request #126 from sferik/remove_multi_json_dependency

Remove multi_json dependency
This commit is contained in:
Joshua Peek 2013-08-20 16:56:16 -07:00
commit e6a0e309e0
5 changed files with 14 additions and 37 deletions

View file

@ -1,11 +1,7 @@
language: ruby
rvm:
- 1.8.7
- rbx-19mode
- ruby-head
- 1.9.2
- 1.9.3
- jruby-18mode
- jruby-19mode
- jruby-head
- rbx-18mode
- rbx-19mode
- ree
- ruby-head
- 2.0.0

View file

@ -1,4 +1,4 @@
source :rubygems
source 'https://rubygems.org'
gemspec

View file

@ -14,6 +14,10 @@ Gem::Specification.new do |s|
s.add_dependency "multi_json", "~>1.0"
s.add_development_dependency "rake"
s.required_ruby_version = '>= 1.9.2'
s.licenses = ['MIT']
s.authors = ["Sam Stephenson", "Josh Peek"]
s.email = ["sstephenson@gmail.com", "josh@joshpeek.com"]
end

View file

@ -16,7 +16,7 @@ module ExecJS
source = encode(source)
if /\S/ =~ source
exec("return eval(#{JSON.encode("(#{source})")})")
exec("return eval(#{::JSON.dump("(#{source})")})")
end
end
@ -30,7 +30,7 @@ module ExecJS
end
def call(identifier, *args)
eval "#{identifier}.apply(this, #{JSON.encode(args)})"
eval "#{identifier}.apply(this, #{::JSON.dump(args)})"
end
protected
@ -50,7 +50,7 @@ module ExecJS
end
output.sub!('#{encoded_source}') do
encoded_source = encode_unicode_codepoints(source)
JSON.encode("(function(){ #{encoded_source} })()")
::JSON.dump("(function(){ #{encoded_source} })()")
end
output.sub!('#{json2_source}') do
IO.read(ExecJS.root + "/support/json2.js")
@ -59,7 +59,7 @@ module ExecJS
end
def extract_result(output)
status, value = output.empty? ? [] : JSON.decode(output)
status, value = output.empty? ? [] : ::JSON.load(output)
if status == "ok"
value
elsif value =~ /SyntaxError:/
@ -100,7 +100,7 @@ module ExecJS
end
def available?
require "execjs/json"
require 'json'
binary ? true : false
end

View file

@ -1,23 +0,0 @@
require "multi_json"
module ExecJS
module JSON
if MultiJson.respond_to?(:dump)
def self.decode(obj)
MultiJson.load(obj)
end
def self.encode(obj)
MultiJson.dump(obj)
end
else
def self.decode(obj)
MultiJson.decode(obj)
end
def self.encode(obj)
MultiJson.encode(obj)
end
end
end
end