Skip to content

Commit

Permalink
Merge pull request #25 from ojab/master
Browse files Browse the repository at this point in the history
Add direct V8 support (via `d3`)
  • Loading branch information
rafaelfranca committed Sep 9, 2015
2 parents 7ff2cec + 99bdbb8 commit 4fe3fd6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ language: ruby
cache: bundler
sudo: false

before_install:
- if [ "$EXECJS_RUNTIME" == "V8" ]; then brew update; fi
- if [ "$EXECJS_RUNTIME" == "V8" ]; then brew install v8; fi
script: bundle exec ruby test/test_execjs.rb

matrix:
Expand Down Expand Up @@ -40,3 +43,5 @@ matrix:
env: EXECJS_RUNTIME=Duktape
- os: osx
env: EXECJS_RUNTIME=RubyRacer
- os: osx
env: EXECJS_RUNTIME=V8
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ExecJS supports these runtimes:
* [Node.js](http://nodejs.org/)
* Apple JavaScriptCore - Included with Mac OS X
* [Microsoft Windows Script Host](http://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx) (JScript)
* [Google V8](http://code.google.com/p/v8/)

A short example:

Expand Down
10 changes: 9 additions & 1 deletion lib/execjs/runtimes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ module Runtimes
encoding: 'UTF-16LE' # CScript with //U returns UTF-16LE
)

V8 = ExternalRuntime.new(
name: "V8",
command: "d8",
runner_path: ExecJS.root + "/support/v8_runner.js",
encoding: 'UTF-8'
)


def self.autodetect
from_environment || best_available ||
Expand Down Expand Up @@ -75,7 +82,8 @@ def self.runtimes
Node,
JavaScriptCore,
SpiderMonkey,
JScript
JScript,
V8
]
end
end
Expand Down
18 changes: 18 additions & 0 deletions lib/execjs/support/v8_runner.js
Original file line number Diff line number Diff line change
@@ -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(JSON.stringify(['err', '' + err, err.stack]));
}
}
} catch (err) {
print(JSON.stringify(['err', '' + err, err.stack]));
}
});

0 comments on commit 4fe3fd6

Please sign in to comment.