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

View file

@ -69,21 +69,11 @@ module ExecJS
end
end
if "".respond_to?(:codepoints)
def encode_unicode_codepoints(str)
str.gsub(/[\u0080-\uffff]/) do |ch|
"\\u%04x" % ch.codepoints.to_a
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
attr_reader :name
@ -165,7 +155,6 @@ module ExecJS
end
end
if "".respond_to?(:force_encoding)
def sh(command)
output, options = nil, {}
options[:external_encoding] = @encoding if @encoding
@ -173,20 +162,6 @@ module ExecJS
IO.popen(command, options) { |f| output = f.read }
output
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?
def shell_escape(*args)

View file

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

View file

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

View file

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