Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

js + ruby

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 spec
Octocat-spinner-32 README.md
README.md

This rather experiments what API subset different embedded JavaScript engines have in common than being a spec.

libs = {
  'johnson' => proc { Johnson::Runtime }, # 'lyndon' => proc { Lyndon::Runtime },
  'v8'      => proc { V8::Context },      'rhino'  => proc { Rhino::Context }
}

lib, runtime = libs.detect do |path, block|
  begin
    require path
    true
  rescue LoadError
    false
  end
end

fail "no lib found" unless lib
js = runtime.call.new

js.load "my_file.js"

js.evaluate "x = 10"
js[:x] + 20 # => 30

js[:x] = 42
js.evaluate "x - 19" # => 23

block = js.evaluate "(function(val) { return val + 2; })"
block.call js[:x] # => 42
Something went wrong with that request. Please try again.