Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 86 lines (71 sloc) 2.205 kb
0893e12 @sstephenson Add the ability to specify ExecJS.runtime via ENV["EXECJS_RUNTIME"].
authored
1 require "execjs/module"
2 require "execjs/external_runtime"
3 require "execjs/mustang_runtime"
4 require "execjs/ruby_racer_runtime"
5 require "execjs/ruby_rhino_runtime"
6
6ba90fc @sstephenson Initial commit
authored
7 module ExecJS
8 module Runtimes
d19c760 @sstephenson Less magic
authored
9 RubyRacer = RubyRacerRuntime.new
957d632 @sstephenson Add therubyracer V8 runtime implementation
authored
10
d19c760 @sstephenson Less magic
authored
11 RubyRhino = RubyRhinoRuntime.new
cdb4db4 @sstephenson Bump Rhino precedence
authored
12
a47882c @josh Still prefer therubyracer over mustang
josh authored
13 Mustang = MustangRuntime.new
14
d19c760 @sstephenson Less magic
authored
15 Node = ExternalRuntime.new(
16 :name => "Node.js (V8)",
17 :command => ["nodejs", "node"],
910ba90 @sstephenson Shift the paths aronud some more
authored
18 :runner_path => ExecJS.root + "/support/node_runner.js"
d19c760 @sstephenson Less magic
authored
19 )
c371fb4 @sstephenson Add Spidermonkey runtime
authored
20
d19c760 @sstephenson Less magic
authored
21 JavaScriptCore = ExternalRuntime.new(
22 :name => "JavaScriptCore",
23 :command => "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc",
24a41df @josh Fix JSC encoding
josh authored
24 :runner_path => ExecJS.root + "/support/basic_runner.js",
25 :conversion => { :from => "ISO8859-1", :to => "UTF-8" }
d19c760 @sstephenson Less magic
authored
26 )
3652589 @sstephenson Pick the best available runtime
authored
27
d19c760 @sstephenson Less magic
authored
28 Spidermonkey = ExternalRuntime.new(
29 :name => "Spidermonkey",
30 :command => "js",
910ba90 @sstephenson Shift the paths aronud some more
authored
31 :runner_path => ExecJS.root + "/support/basic_runner.js"
d19c760 @sstephenson Less magic
authored
32 )
8b22842 @sstephenson Add WSH JScript support
authored
33
d19c760 @sstephenson Less magic
authored
34 JScript = ExternalRuntime.new(
35 :name => "JScript",
36 :command => "cscript //E:jscript //Nologo",
8b22842 @sstephenson Add WSH JScript support
authored
37 :runner_path => ExecJS.root + "/support/jscript_runner.js"
d19c760 @sstephenson Less magic
authored
38 )
39
40
0893e12 @sstephenson Add the ability to specify ExecJS.runtime via ENV["EXECJS_RUNTIME"].
authored
41 def self.autodetect
42 from_environment || best_available ||
43 raise(RuntimeUnavailable, "Could not find a JavaScript runtime. " +
44 "See https://github.com/sstephenson/execjs for a list of available runtimes.")
45 end
46
d19c760 @sstephenson Less magic
authored
47 def self.best_available
313a290 @josh Move runtime error to ExecJS.runtime
josh authored
48 runtimes.find(&:available?)
d19c760 @sstephenson Less magic
authored
49 end
50
0893e12 @sstephenson Add the ability to specify ExecJS.runtime via ENV["EXECJS_RUNTIME"].
authored
51 def self.from_environment
52 if name = ENV["EXECJS_RUNTIME"]
53 if runtime = const_get(name)
54 if runtime.available?
55 runtime if runtime.available?
56 else
57 raise RuntimeUnavailable, "#{name} runtime is not available on this system"
58 end
59 elsif !name.empty?
60 raise RuntimeUnavailable, "#{name} runtime is not defined"
61 end
62 end
63 end
64
65 def self.names
66 constants
67 end
68
d19c760 @sstephenson Less magic
authored
69 def self.runtimes
70 @runtimes ||= [
71 RubyRacer,
72 RubyRhino,
a47882c @josh Still prefer therubyracer over mustang
josh authored
73 Mustang,
d19c760 @sstephenson Less magic
authored
74 Node,
75 JavaScriptCore,
76 Spidermonkey,
77 JScript
78 ]
79 end
6ba90fc @sstephenson Initial commit
authored
80 end
0893e12 @sstephenson Add the ability to specify ExecJS.runtime via ENV["EXECJS_RUNTIME"].
authored
81
82 def self.runtimes
83 Runtimes.runtimes
84 end
6ba90fc @sstephenson Initial commit
authored
85 end
Something went wrong with that request. Please try again.