lib/execjs/external_runtime.rb in execjs-1.4.1 vs lib/execjs/external_runtime.rb in execjs-2.0.0
- old
+ new
@@ -14,11 +14,11 @@
def eval(source, options = {})
source = encode(source)
if /\S/ =~ source
- exec("return eval(#{JSON.encode("(#{source})")})")
+ exec("return eval(#{::JSON.dump("(#{source})")})")
end
end
def exec(source, options = {})
source = encode(source)
@@ -28,11 +28,11 @@
extract_result(@runtime.send(:exec_runtime, file.path))
end
end
def call(identifier, *args)
- eval "#{identifier}.apply(this, #{JSON.encode(args)})"
+ eval "#{identifier}.apply(this, #{::JSON.dump(args)})"
end
protected
def compile_to_tempfile(source)
tempfile = Tempfile.open(['execjs', '.js'])
@@ -48,20 +48,20 @@
output.sub!('#{source}') do
source
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")
end
end
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:/
raise RuntimeError, value
else
@@ -98,11 +98,11 @@
@deprecated = !!options[:deprecated]
@binary = nil
end
def available?
- require "execjs/json"
+ require 'json'
binary ? true : false
end
def deprecated?
@deprecated
@@ -132,36 +132,15 @@
protected
def runner_source
@runner_source ||= IO.read(@runner_path)
end
- if ExecJS.windows?
- def exec_runtime(filename)
- path = Dir::Tmpname.create(['execjs', 'json']) {}
- begin
- `#{shell_escape(*(binary.split(' ') << filename))} 2>&1 > #{path}`
- options = {}
- options[:external_encoding] = @encoding if @encoding
- options[:internal_encoding] = ::Encoding.default_internal || 'UTF-8'
- output = File.open(path, 'rb', options) { |f| f.read }
- ensure
- File.unlink(path) if path
- end
-
- if $?.success?
- output
- else
- raise RuntimeError, output
- end
- end
- else
- def exec_runtime(filename)
- output = sh("#{shell_escape(*(binary.split(' ') << filename))} 2>&1")
- if $?.success?
- output
- else
- raise RuntimeError, output
- end
+ def exec_runtime(filename)
+ output = sh("#{shell_escape(*(binary.split(' ') << filename))} 2>&1")
+ if $?.success?
+ output
+ else
+ raise RuntimeError, output
end
end
def locate_binary
if binary = which(@command)