Browse files

Add JSC runtime

  • Loading branch information...
1 parent 9a5015e commit 378a9236bef3b2bec5d11e05a3a0154049c69a80 @sstephenson committed Feb 7, 2011
Showing with 40 additions and 0 deletions.
  1. +1 −0 lib/execjs/runtimes.rb
  2. +18 −0 lib/execjs/runtimes/jsc.js
  3. +13 −0 lib/execjs/runtimes/jsc.rb
  4. +8 −0 test/test_runtime.rb
View
1 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"
View
18 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]));
+ }
+});
View
13 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
View
8 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

0 comments on commit 378a923

Please sign in to comment.