From 86f93d426991c5e4cee2f5a58640fc5e4ed657dc Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 23 Dec 2014 00:03:14 -0600 Subject: [PATCH 1/4] Test on jruby --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 9577abf..05d8d58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,3 +4,4 @@ rvm: - 2.0.0 - 2.1 - 2.2 + - jruby-19mode From 900da3c8176e0fc584957d1c28655fe9911f1d74 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 23 Dec 2014 00:06:26 -0600 Subject: [PATCH 2/4] Catch errors on context compile --- lib/execjs/ruby_rhino_runtime.rb | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/execjs/ruby_rhino_runtime.rb b/lib/execjs/ruby_rhino_runtime.rb index 65c3908..5875bc1 100644 --- a/lib/execjs/ruby_rhino_runtime.rb +++ b/lib/execjs/ruby_rhino_runtime.rb @@ -9,6 +9,8 @@ def initialize(runtime, source = "") @rhino_context = ::Rhino::Context.new fix_memory_limit! @rhino_context @rhino_context.eval(source) + rescue Exception => e + reraise_error(e) end def exec(source, options = {}) @@ -25,22 +27,14 @@ def eval(source, options = {}) if /\S/ =~ source unbox @rhino_context.eval("(#{source})") end - rescue ::Rhino::JSError => e - if e.message =~ /^syntax error/ - raise RuntimeError, e.message - else - raise ProgramError, e.message - end + rescue Exception => e + reraise_error(e) end def call(properties, *args) unbox @rhino_context.eval(properties).call(*args) - rescue ::Rhino::JSError => e - if e.message == "syntax error" - raise RuntimeError, e.message - else - raise ProgramError, e.message - end + rescue Exception => e + reraise_error(e) end def unbox(value) @@ -64,6 +58,19 @@ def unbox(value) end end + def reraise_error(e) + case e + when ::Rhino::JSError + if e.message == "syntax error" + raise RuntimeError, e.message + else + raise ProgramError, e.message + end + else + raise e + end + end + private # Disables bytecode compiling which limits you to 64K scripts def fix_memory_limit!(context) From 0ef664e93d0db38260d3e13f22563b902c5f969c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 23 Dec 2014 00:22:53 -0600 Subject: [PATCH 3/4] Always redirect stderr in jruby --- lib/execjs/external_runtime.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/execjs/external_runtime.rb b/lib/execjs/external_runtime.rb index f123cfe..bd51eae 100644 --- a/lib/execjs/external_runtime.rb +++ b/lib/execjs/external_runtime.rb @@ -169,6 +169,21 @@ def shell_escape(*args) arg }.join(" ") end + elsif RUBY_ENGINE == 'jruby' + require 'shellwords' + + def exec_runtime(filename) + command = "#{Shellwords.join(binary.split(' ') << filename)} 2>&1" + io = IO.popen(command, @popen_options) + output = io.read + io.close + + if $?.success? + output + else + raise RuntimeError, output + end + end else def exec_runtime(filename) io = IO.popen(binary.split(' ') << filename, @popen_options.merge({err: [:child, :out]})) From 06cd1463078950e3f2964f308b26fe85a1be2088 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 23 Dec 2014 00:29:15 -0600 Subject: [PATCH 4/4] Fix jruby signal exception --- Rakefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Rakefile b/Rakefile index b80407d..f4ba838 100644 --- a/Rakefile +++ b/Rakefile @@ -39,6 +39,12 @@ task :test do begin task.invoke + rescue SignalException => e + if e.message == "2" + skipped << task.name + else + failed << task.name + end rescue Exception => e if e.message[/Command failed with status \((\d+)\)/, 1] == "2" skipped << task.name