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

Remove 1.8 non-encoding branches

This commit is contained in:
Joshua Peek 2014-05-19 09:45:03 -04:00
parent a058a89fef
commit d3398065d3
5 changed files with 48 additions and 86 deletions

View file

@ -1,7 +1,6 @@
module ExecJS module ExecJS
# Encodes strings as UTF-8 # Encodes strings as UTF-8
module Encoding module Encoding
if "".respond_to?(:encode)
if RUBY_ENGINE == 'jruby' || RUBY_ENGINE == 'rbx' if RUBY_ENGINE == 'jruby' || RUBY_ENGINE == 'rbx'
# workaround for jruby bug http://jira.codehaus.org/browse/JRUBY-6588 # workaround for jruby bug http://jira.codehaus.org/browse/JRUBY-6588
# workaround for rbx bug https://github.com/rubinius/rubinius/issues/1729 # workaround for rbx bug https://github.com/rubinius/rubinius/issues/1729
@ -23,11 +22,5 @@ module ExecJS
string.encode('UTF-8') string.encode('UTF-8')
end end
end end
else
# Define no-op on 1.8
def encode(string)
string
end
end
end end
end end

View file

@ -69,21 +69,11 @@ module ExecJS
end end
end end
if "".respond_to?(:codepoints)
def encode_unicode_codepoints(str) def encode_unicode_codepoints(str)
str.gsub(/[\u0080-\uffff]/) do |ch| str.gsub(/[\u0080-\uffff]/) do |ch|
"\\u%04x" % ch.codepoints.to_a "\\u%04x" % ch.codepoints.to_a
end end
end end
else
def encode_unicode_codepoints(str)
str.gsub(/([\xC0-\xDF][\x80-\xBF]|
[\xE0-\xEF][\x80-\xBF]{2}|
[\xF0-\xF7][\x80-\xBF]{3})+/nx) do |ch|
"\\u%04x" % ch.unpack("U*")
end
end
end
end end
attr_reader :name attr_reader :name
@ -165,7 +155,6 @@ module ExecJS
end end
end end
if "".respond_to?(:force_encoding)
def sh(command) def sh(command)
output, options = nil, {} output, options = nil, {}
options[:external_encoding] = @encoding if @encoding options[:external_encoding] = @encoding if @encoding
@ -173,20 +162,6 @@ module ExecJS
IO.popen(command, options) { |f| output = f.read } IO.popen(command, options) { |f| output = f.read }
output output
end end
else
require "iconv"
def sh(command)
output = nil
IO.popen(command) { |f| output = f.read }
if @encoding
Iconv.new('UTF-8', @encoding).iconv(output)
else
output
end
end
end
if ExecJS.windows? if ExecJS.windows?
def shell_escape(*args) def shell_escape(*args)

View file

@ -47,9 +47,7 @@ module ExecJS
when function?(value) when function?(value)
nil nil
when string?(value) when string?(value)
value.respond_to?(:force_encoding) ? value.force_encoding('UTF-8')
value.force_encoding('UTF-8') :
value
when array?(value) when array?(value)
value.map { |v| unbox(v) } value.map { |v| unbox(v) }
when object?(value) when object?(value)

View file

@ -64,9 +64,7 @@ module ExecJS
vs vs
end end
when String when String
value.respond_to?(:force_encoding) ? value.force_encoding('UTF-8')
value.force_encoding('UTF-8') :
value
else else
value value
end end

View file

@ -83,7 +83,6 @@ class TestExecJS < Test::Unit::TestCase
assert_equal "\\", ExecJS.eval('"\\\\"') assert_equal "\\", ExecJS.eval('"\\\\"')
end end
if defined? Encoding
def test_encoding def test_encoding
utf8 = Encoding.find('UTF-8') utf8 = Encoding.find('UTF-8')
@ -119,7 +118,6 @@ class TestExecJS < Test::Unit::TestCase
context.eval(binary) context.eval(binary)
end end
end end
end
def test_compile def test_compile
context = ExecJS.compile("foo = function() { return \"bar\"; }") context = ExecJS.compile("foo = function() { return \"bar\"; }")