mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
parent
b829dcd8b8
commit
c87c363379
3 changed files with 6 additions and 4 deletions
1
Rakefile
1
Rakefile
|
@ -56,4 +56,5 @@ task :test do
|
||||||
banner messages.join("\n")
|
banner messages.join("\n")
|
||||||
|
|
||||||
raise "test failures" if failed.any?
|
raise "test failures" if failed.any?
|
||||||
|
raise "all tests skipped" if !passed.any?
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,14 +2,14 @@ module ExecJS
|
||||||
class MustangRuntime
|
class MustangRuntime
|
||||||
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)
|
||||||
|
|
||||||
@v8_context = ::Mustang::Context.new
|
@v8_context = ::Mustang::Context.new
|
||||||
@v8_context.eval(source)
|
@v8_context.eval(source)
|
||||||
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
|
||||||
|
@ -17,7 +17,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 @v8_context.eval("(#{source})")
|
unbox @v8_context.eval("(#{source})")
|
||||||
|
|
|
@ -92,12 +92,13 @@ module ExecJS
|
||||||
end
|
end
|
||||||
|
|
||||||
if defined? Encoding
|
if defined? Encoding
|
||||||
if (!defined?(RUBY_ENGINE) || RUBY_ENGINE != "jruby")
|
if (!defined?(RUBY_ENGINE) || (RUBY_ENGINE != "jruby" && RUBY_ENGINE != "rbx"))
|
||||||
def self.encode(string)
|
def self.encode(string)
|
||||||
string.encode('UTF-8')
|
string.encode('UTF-8')
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# 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
|
||||||
def self.encode(string)
|
def self.encode(string)
|
||||||
if string.encoding.name == 'ASCII-8BIT'
|
if string.encoding.name == 'ASCII-8BIT'
|
||||||
data = string.dup
|
data = string.dup
|
||||||
|
|
Loading…
Reference in a new issue