diff --git a/lib/execjs/runtimes.rb b/lib/execjs/runtimes.rb index 4bc2489..9216bf4 100644 --- a/lib/execjs/runtimes.rb +++ b/lib/execjs/runtimes.rb @@ -17,6 +17,10 @@ module ExecJS :command => "node", :runner_path => runner_path("node.js") ) + + Spidermonkey = Runtime.new( + :command => "js", + :runner_path => runner_path("spidermonkey.js") ) V8 = Runtime.new( diff --git a/lib/execjs/runtimes/spidermonkey.js b/lib/execjs/runtimes/spidermonkey.js new file mode 100644 index 0000000..f7fbedb --- /dev/null +++ b/lib/execjs/runtimes/spidermonkey.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])); + } +}); diff --git a/test/test_runtimes.rb b/test/test_runtimes.rb index 7c3d656..7633941 100644 --- a/test/test_runtimes.rb +++ b/test/test_runtimes.rb @@ -55,6 +55,14 @@ class TestNodeRuntime < Test::Unit::TestCase end end +class TestSpidermonkeyRuntime < Test::Unit::TestCase + include TestRuntime + + def setup + @runtime = ExecJS::Runtimes::Spidermonkey + end +end + class TestV8Runtime < Test::Unit::TestCase include TestRuntime