From 378a9236bef3b2bec5d11e05a3a0154049c69a80 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Sun, 6 Feb 2011 19:44:32 -0600 Subject: [PATCH] Add JSC runtime --- lib/execjs/runtimes.rb | 1 + lib/execjs/runtimes/jsc.js | 18 ++++++++++++++++++ lib/execjs/runtimes/jsc.rb | 13 +++++++++++++ test/test_runtime.rb | 8 ++++++++ 4 files changed, 40 insertions(+) create mode 100644 lib/execjs/runtimes/jsc.js create mode 100644 lib/execjs/runtimes/jsc.rb 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 @@ def test_thrown_exception 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