Skip to content

gf3/oxpecker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Oxpecker

Sandboxed javascript from ruby. Note: This is still super alpha, so don't complain.

Cool

I know, right? Anyway, Oxpecker is basically an interface to Mozilla's Rhino with some security precautions set in place. Oxpecker also cleans up some of the Java exceptions and return values, and makes them a bit more ruby-friendly.

It's possible to do this natively in Ruby by using JRuby to interface with the Java library. So yes, this needs to be run in JRuby.

Examples

For one-off script execution use the 'evaluate' class method:

Oxpecker.evaluate("1 + 1") # 2

Alternatively, you can create a new instance, and execute as much JS as you please within the same scope:

o = Oxpecker.new :source_name => "SexyScript"
o.evaluate("function hi(name){ return 'Hi, '+name+'.'; }") # nil
puts o.evaluate("hi('Fabio') + ' Nice to see you!'") # Hi, Fabio. Nice to see you!
o.close

You should always 'close' your Oxpecker instances when you're finished with them:

o = Oxpecker.new
begin
    o.evaluate "7 * 10"
ensure
    o.close
end

Todo

  1. Write a print method and make it available to JavaScript.

Author

Written by Gianni ChiappettaRunlevel6

About

Sandboxed javascript in ruby.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages