mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Add direct V8 support (via d3
)
This commit is contained in:
parent
7ff2cec476
commit
99bdbb8067
4 changed files with 33 additions and 1 deletions
|
@ -2,6 +2,9 @@ language: ruby
|
||||||
cache: bundler
|
cache: bundler
|
||||||
sudo: false
|
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
|
script: bundle exec ruby test/test_execjs.rb
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
|
@ -40,3 +43,5 @@ matrix:
|
||||||
env: EXECJS_RUNTIME=Duktape
|
env: EXECJS_RUNTIME=Duktape
|
||||||
- os: osx
|
- os: osx
|
||||||
env: EXECJS_RUNTIME=RubyRacer
|
env: EXECJS_RUNTIME=RubyRacer
|
||||||
|
- os: osx
|
||||||
|
env: EXECJS_RUNTIME=V8
|
||||||
|
|
|
@ -15,6 +15,7 @@ ExecJS supports these runtimes:
|
||||||
* [Node.js](http://nodejs.org/)
|
* [Node.js](http://nodejs.org/)
|
||||||
* Apple JavaScriptCore - Included with Mac OS X
|
* Apple JavaScriptCore - Included with Mac OS X
|
||||||
* [Microsoft Windows Script Host](http://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx) (JScript)
|
* [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:
|
A short example:
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,13 @@ module ExecJS
|
||||||
encoding: 'UTF-16LE' # CScript with //U returns UTF-16LE
|
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
|
def self.autodetect
|
||||||
from_environment || best_available ||
|
from_environment || best_available ||
|
||||||
|
@ -75,7 +82,8 @@ module ExecJS
|
||||||
Node,
|
Node,
|
||||||
JavaScriptCore,
|
JavaScriptCore,
|
||||||
SpiderMonkey,
|
SpiderMonkey,
|
||||||
JScript
|
JScript,
|
||||||
|
V8
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
18
lib/execjs/support/v8_runner.js
Normal file
18
lib/execjs/support/v8_runner.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(JSON.stringify(['err', '' + err, err.stack]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
print(JSON.stringify(['err', '' + err, err.stack]));
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in a new issue