Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Merge pull request #174 from sstephenson/rubyrhino
Browse files Browse the repository at this point in the history
Fix rubyrhino CI
  • Loading branch information
josh committed Dec 23, 2014
2 parents 1431396 + 06cd146 commit 3d605e9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -4,3 +4,4 @@ rvm:
- 2.0.0
- 2.1
- 2.2
- jruby-19mode
6 changes: 6 additions & 0 deletions Rakefile
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions lib/execjs/external_runtime.rb
Expand Up @@ -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]}))
Expand Down
31 changes: 19 additions & 12 deletions lib/execjs/ruby_rhino_runtime.rb
Expand Up @@ -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 = {})
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 3d605e9

Please sign in to comment.