Permalink
Browse files

Pick the best available runtime

  • Loading branch information...
1 parent b22082f commit 3652589056ad90c28bf1d6a55b784565a3455361 @sstephenson committed Feb 7, 2011
Showing with 21 additions and 16 deletions.
  1. +1 −1 lib/execjs.rb
  2. +20 −15 lib/execjs/runtimes.rb
View
@@ -15,6 +15,6 @@ def self.eval(source)
end
def self.runtime
- @runtime ||= Runtimes.runtime
+ @runtime ||= Runtimes.best_available
end
end
View
@@ -1,31 +1,36 @@
module ExecJS
module Runtimes
- def self.runtime
- V8
+ def self.best_available
+ runtimes.find(&:available?)
+ end
+
+ def self.runtimes
+ @runtimes ||= []
+ end
+
+ def self.define_runtime(name, options)
+ runtimes.push runtime = Runtime.new(options)
+ const_set(name, runtime)
end
def self.runner_path(path)
File.expand_path("../runtimes/#{path}", __FILE__)
end
- JSC = Runtime.new(
- :command => "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc",
- :runner_path => runner_path("jsc.js")
- )
+ define_runtime :V8,
+ :command => "v8",
+ :runner_path => runner_path("v8.js")
- Node = Runtime.new(
+ define_runtime :Node,
:command => "node",
:runner_path => runner_path("node.js")
- )
- Spidermonkey = Runtime.new(
+ define_runtime :JSC,
+ :command => "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc",
+ :runner_path => runner_path("jsc.js")
+
+ define_runtime :Spidermonkey,
:command => "js",
:runner_path => runner_path("spidermonkey.js")
- )
-
- V8 = Runtime.new(
- :command => "v8",
- :runner_path => runner_path("v8.js")
- )
end
end

0 comments on commit 3652589

Please sign in to comment.