mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Add V8 runtime
This commit is contained in:
parent
0be476df21
commit
9a5015e612
6 changed files with 55 additions and 7 deletions
|
@ -15,6 +15,6 @@ module ExecJS
|
|||
end
|
||||
|
||||
def self.runtime
|
||||
@runtime ||= Runtimes::Node.new
|
||||
@runtime ||= Runtimes.runtime
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
module ExecJS
|
||||
module Runtimes
|
||||
autoload :Node, "execjs/runtimes/node"
|
||||
autoload :V8, "execjs/runtimes/v8"
|
||||
|
||||
def self.runtime
|
||||
V8.new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
18
lib/execjs/runtimes/v8.js
Normal file
18
lib/execjs/runtimes/v8.js
Normal file
|
@ -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
lib/execjs/runtimes/v8.rb
Normal file
13
lib/execjs/runtimes/v8.rb
Normal file
|
@ -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
|
|
@ -9,8 +9,8 @@ ExecJS supports these runtimes:
|
|||
|
||||
* [therubyracer](https://github.com/cowboyd/therubyracer) - Google V8
|
||||
embedded within Ruby for exceptional performance
|
||||
* [Node.js](http://nodejs.org/)
|
||||
* [Google V8](http://code.google.com/p/v8/)
|
||||
* [Node.js](http://nodejs.org/)
|
||||
* Apple JavaScriptCore
|
||||
* [Mozilla Spidermonkey](http://www.mozilla.org/js/spidermonkey/)
|
||||
* [Mozilla Rhino](http://www.mozilla.org/rhino/)
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
require "execjs"
|
||||
require "test/unit"
|
||||
|
||||
class TestNodeRuntime < Test::Unit::TestCase
|
||||
def setup
|
||||
@runtime = ExecJS::Runtimes::Node.new
|
||||
end
|
||||
|
||||
module TestRuntime
|
||||
def test_exec
|
||||
assert_nil @runtime.exec("1")
|
||||
assert_nil @runtime.exec("return")
|
||||
|
@ -42,3 +38,19 @@ class TestNodeRuntime < Test::Unit::TestCase
|
|||
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
|
Loading…
Reference in a new issue