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

Commit

Permalink
Add V8 runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
sstephenson committed Feb 7, 2011
1 parent 0be476d commit 9a5015e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/execjs.rb
Expand Up @@ -15,6 +15,6 @@ def self.eval(source)
end end


def self.runtime def self.runtime
@runtime ||= Runtimes::Node.new @runtime ||= Runtimes.runtime
end end
end end
5 changes: 5 additions & 0 deletions lib/execjs/runtimes.rb
@@ -1,5 +1,10 @@
module ExecJS module ExecJS
module Runtimes module Runtimes
autoload :Node, "execjs/runtimes/node" autoload :Node, "execjs/runtimes/node"
autoload :V8, "execjs/runtimes/v8"

def self.runtime
V8.new
end
end end
end end
18 changes: 18 additions & 0 deletions lib/execjs/runtimes/v8.js
@@ -0,0 +1,18 @@
(function(program, execJS) { execJS(program) })(function() { #{source}
}, function(program) {
var output;
try {
result = program();
if (typeof result == 'undefined' && result !== null) {
print('["ok"]');
} else {
try {
print(JSON.stringify(['ok', result]));
} catch (err) {
print('["err"]');
}
}
} catch (err) {
print(JSON.stringify(['err', '' + err]));
}
});
13 changes: 13 additions & 0 deletions lib/execjs/runtimes/v8.rb
@@ -0,0 +1,13 @@
module ExecJS
module Runtimes
class V8 < Runtime
def command(filename)
"v8 #{filename}"
end

def runner_path
File.expand_path('../v8.js', __FILE__)
end
end
end
end
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -9,8 +9,8 @@ ExecJS supports these runtimes:


* [therubyracer](https://github.com/cowboyd/therubyracer) - Google V8 * [therubyracer](https://github.com/cowboyd/therubyracer) - Google V8
embedded within Ruby for exceptional performance embedded within Ruby for exceptional performance
* [Node.js](http://nodejs.org/)
* [Google V8](http://code.google.com/p/v8/) * [Google V8](http://code.google.com/p/v8/)
* [Node.js](http://nodejs.org/)
* Apple JavaScriptCore * Apple JavaScriptCore
* [Mozilla Spidermonkey](http://www.mozilla.org/js/spidermonkey/) * [Mozilla Spidermonkey](http://www.mozilla.org/js/spidermonkey/)
* [Mozilla Rhino](http://www.mozilla.org/rhino/) * [Mozilla Rhino](http://www.mozilla.org/rhino/)
Expand Down
22 changes: 17 additions & 5 deletions test/test_node_runtime.rb → test/test_runtime.rb
@@ -1,11 +1,7 @@
require "execjs" require "execjs"
require "test/unit" require "test/unit"


class TestNodeRuntime < Test::Unit::TestCase module TestRuntime
def setup
@runtime = ExecJS::Runtimes::Node.new
end

def test_exec def test_exec
assert_nil @runtime.exec("1") assert_nil @runtime.exec("1")
assert_nil @runtime.exec("return") assert_nil @runtime.exec("return")
Expand Down Expand Up @@ -42,3 +38,19 @@ def test_thrown_exception
end end
end end
end end

class TestNodeRuntime < Test::Unit::TestCase
include TestRuntime

def setup
@runtime = ExecJS::Runtimes::Node.new
end
end

class TestV8Runtime < Test::Unit::TestCase
include TestRuntime

def setup
@runtime = ExecJS::Runtimes::V8.new
end
end

0 comments on commit 9a5015e

Please sign in to comment.