Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 91 lines (75 sloc) 2.435 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"],
642067e @josh node returns utf-8
josh authored
21 :runner_path => ExecJS.root + "/support/node_runner.js",
22 :encoding => 'UTF-8'
d19c760 @sstephenson Less magic
authored
23 )
c371fb4 @sstephenson Add Spidermonkey runtime
authored
24
d19c760 @sstephenson Less magic
authored
25 JavaScriptCore = ExternalRuntime.new(
26 :name => "JavaScriptCore",
9a815b3 @josh Remove jsc bin
josh authored
27 :command => "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc",
67c8927 @josh Encode JS unicode literals for JSC runner
josh authored
28 :runner_path => ExecJS.root + "/support/jsc_runner.js"
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",
e019c4b @josh Separate spidermonkey runner
josh authored
34 :runner_path => ExecJS.root + "/support/spidermonkey_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",
adc3312 @wagenet CScript Unicode fix
wagenet authored
39 :command => "cscript //E:jscript //Nologo //U",
40 :runner_path => ExecJS.root + "/support/jscript_runner.js",
41 :encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE
d19c760 @sstephenson Less magic
authored
42 )
43
44
0893e12 @sstephenson Add the ability to specify ExecJS.runtime via ENV["EXECJS_RUNTIME"].
authored
45 def self.autodetect
46 from_environment || best_available ||
47 raise(RuntimeUnavailable, "Could not find a JavaScript runtime. " +
48 "See https://github.com/sstephenson/execjs for a list of available runtimes.")
49 end
50
d19c760 @sstephenson Less magic
authored
51 def self.best_available
313a290 @josh Move runtime error to ExecJS.runtime
josh authored
52 runtimes.find(&:available?)
d19c760 @sstephenson Less magic
authored
53 end
54
0893e12 @sstephenson Add the ability to specify ExecJS.runtime via ENV["EXECJS_RUNTIME"].
authored
55 def self.from_environment
56 if name = ENV["EXECJS_RUNTIME"]
57 if runtime = const_get(name)
58 if runtime.available?
59 runtime if runtime.available?
60 else
6067438 @sstephenson Proper capitalization for SpiderMonkey
authored
61 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
62 end
63 elsif !name.empty?
64 raise RuntimeUnavailable, "#{name} runtime is not defined"
65 end
66 end
67 end
68
69 def self.names
6067438 @sstephenson Proper capitalization for SpiderMonkey
authored
70 @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
71 end
72
d19c760 @sstephenson Less magic
authored
73 def self.runtimes
74 @runtimes ||= [
75 RubyRacer,
76 RubyRhino,
b1eb16b @sstephenson Add support for embedded SpiderMonkey via Johnson
authored
77 Johnson,
a47882c @josh Still prefer therubyracer over mustang
josh authored
78 Mustang,
d19c760 @sstephenson Less magic
authored
79 Node,
80 JavaScriptCore,
6067438 @sstephenson Proper capitalization for SpiderMonkey
authored
81 SpiderMonkey,
d19c760 @sstephenson Less magic
authored
82 JScript
83 ]
84 end
6ba90fc @sstephenson Initial commit
authored
85 end
0893e12 @sstephenson Add the ability to specify ExecJS.runtime via ENV["EXECJS_RUNTIME"].
authored
86
87 def self.runtimes
88 Runtimes.runtimes
89 end
6ba90fc @sstephenson Initial commit
authored
90 end
Something went wrong with that request. Please try again.