Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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