diff --git a/lib/execjs/runtimes.rb b/lib/execjs/runtimes.rb index 30aa486..1bdda96 100644 --- a/lib/execjs/runtimes.rb +++ b/lib/execjs/runtimes.rb @@ -1,5 +1,6 @@ module ExecJS module Runtimes + autoload :JSC, "execjs/runtimes/jsc" autoload :Node, "execjs/runtimes/node" autoload :V8, "execjs/runtimes/v8" diff --git a/lib/execjs/runtimes/jsc.js b/lib/execjs/runtimes/jsc.js new file mode 100644 index 0000000..f7fbedb --- /dev/null +++ b/lib/execjs/runtimes/jsc.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/lib/execjs/runtimes/jsc.rb b/lib/execjs/runtimes/jsc.rb new file mode 100644 index 0000000..9d36cb1 --- /dev/null +++ b/lib/execjs/runtimes/jsc.rb @@ -0,0 +1,13 @@ +module ExecJS + module Runtimes + class JSC < Runtime + def command(filename) + "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc #{filename}" + end + + def runner_path + File.expand_path('../v8.js', __FILE__) + end + end + end +end diff --git a/test/test_runtime.rb b/test/test_runtime.rb index ef028e6..c06509c 100644 --- a/test/test_runtime.rb +++ b/test/test_runtime.rb @@ -39,6 +39,14 @@ module TestRuntime end end +class TestJSCRuntime < Test::Unit::TestCase + include TestRuntime + + def setup + @runtime = ExecJS::Runtimes::JSC.new + end +end + class TestNodeRuntime < Test::Unit::TestCase include TestRuntime