mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
fix for jruby 1.9 mode
This commit is contained in:
parent
f3b12493ff
commit
0b0b5690d1
3 changed files with 30 additions and 6 deletions
|
@ -6,14 +6,14 @@ module ExecJS
|
||||||
class ExternalRuntime
|
class ExternalRuntime
|
||||||
class Context
|
class Context
|
||||||
def initialize(runtime, source = "")
|
def initialize(runtime, source = "")
|
||||||
source = source.encode('UTF-8') if source.respond_to?(:encode)
|
source = ExecJS::encode(source) if source.respond_to?(:encode)
|
||||||
|
|
||||||
@runtime = runtime
|
@runtime = runtime
|
||||||
@source = source
|
@source = source
|
||||||
end
|
end
|
||||||
|
|
||||||
def eval(source, options = {})
|
def eval(source, options = {})
|
||||||
source = source.encode('UTF-8') if source.respond_to?(:encode)
|
source = ExecJS::encode(source) if source.respond_to?(:encode)
|
||||||
|
|
||||||
if /\S/ =~ source
|
if /\S/ =~ source
|
||||||
exec("return eval(#{json_encode("(#{source})")})")
|
exec("return eval(#{json_encode("(#{source})")})")
|
||||||
|
@ -21,7 +21,7 @@ module ExecJS
|
||||||
end
|
end
|
||||||
|
|
||||||
def exec(source, options = {})
|
def exec(source, options = {})
|
||||||
source = source.encode('UTF-8') if source.respond_to?(:encode)
|
source = ExecJS::encode(source) if source.respond_to?(:encode)
|
||||||
source = "#{@source}\n#{source}" if @source
|
source = "#{@source}\n#{source}" if @source
|
||||||
|
|
||||||
compile_to_tempfile(source) do |file|
|
compile_to_tempfile(source) do |file|
|
||||||
|
|
|
@ -2,7 +2,7 @@ module ExecJS
|
||||||
class RubyRhinoRuntime
|
class RubyRhinoRuntime
|
||||||
class Context
|
class Context
|
||||||
def initialize(source = "")
|
def initialize(source = "")
|
||||||
source = source.encode('UTF-8') if source.respond_to?(:encode)
|
source = ExecJS::encode(source) if source.respond_to?(:encode)
|
||||||
|
|
||||||
@rhino_context = ::Rhino::Context.new
|
@rhino_context = ::Rhino::Context.new
|
||||||
fix_memory_limit! @rhino_context
|
fix_memory_limit! @rhino_context
|
||||||
|
@ -10,7 +10,7 @@ module ExecJS
|
||||||
end
|
end
|
||||||
|
|
||||||
def exec(source, options = {})
|
def exec(source, options = {})
|
||||||
source = source.encode('UTF-8') if source.respond_to?(:encode)
|
source = ExecJS::encode(source) if source.respond_to?(:encode)
|
||||||
|
|
||||||
if /\S/ =~ source
|
if /\S/ =~ source
|
||||||
eval "(function(){#{source}})()", options
|
eval "(function(){#{source}})()", options
|
||||||
|
@ -18,7 +18,7 @@ module ExecJS
|
||||||
end
|
end
|
||||||
|
|
||||||
def eval(source, options = {})
|
def eval(source, options = {})
|
||||||
source = source.encode('UTF-8') if source.respond_to?(:encode)
|
source = ExecJS::encode(source) if source.respond_to?(:encode)
|
||||||
|
|
||||||
if /\S/ =~ source
|
if /\S/ =~ source
|
||||||
unbox @rhino_context.eval("(#{source})")
|
unbox @rhino_context.eval("(#{source})")
|
||||||
|
|
|
@ -90,4 +90,28 @@ module ExecJS
|
||||||
def self.runtimes
|
def self.runtimes
|
||||||
Runtimes.runtimes
|
Runtimes.runtimes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if defined? Encoding
|
||||||
|
if (!defined?(RUBY_ENGINE) || RUBY_ENGINE != "jruby")
|
||||||
|
def self.encode(string)
|
||||||
|
string.encode('UTF-8')
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# workaround for jruby bug http://jira.codehaus.org/browse/JRUBY-6588
|
||||||
|
def self.encode(string)
|
||||||
|
if string.encoding.name == 'ASCII-8BIT'
|
||||||
|
data = string.dup
|
||||||
|
data.force_encoding('utf-8')
|
||||||
|
|
||||||
|
unless data.valid_encoding?
|
||||||
|
raise Encoding::UndefinedConversionError, "Could not encode ASCII-8BIT data #{string.dump} as UTF-8"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
data = string.encode('utf-8')
|
||||||
|
end
|
||||||
|
data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue