execjs 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/execjs.rb +3 -50
- data/lib/execjs/module.rb +39 -0
- data/lib/execjs/runtimes.rb +34 -0
- metadata +27 -2
data/lib/execjs.rb
CHANGED
@@ -1,53 +1,6 @@
|
|
1
|
-
require "
|
1
|
+
require "execjs/module"
|
2
|
+
require "execjs/runtimes"
|
2
3
|
|
3
4
|
module ExecJS
|
4
|
-
|
5
|
-
|
6
|
-
class Error < ::StandardError; end
|
7
|
-
class RuntimeError < Error; end
|
8
|
-
class ProgramError < Error; end
|
9
|
-
class RuntimeUnavailable < RuntimeError; end
|
10
|
-
|
11
|
-
autoload :ExternalRuntime, "execjs/external_runtime"
|
12
|
-
autoload :MustangRuntime, "execjs/mustang_runtime"
|
13
|
-
autoload :RubyRacerRuntime, "execjs/ruby_racer_runtime"
|
14
|
-
autoload :RubyRhinoRuntime, "execjs/ruby_rhino_runtime"
|
15
|
-
autoload :Runtimes, "execjs/runtimes"
|
16
|
-
|
17
|
-
class << self
|
18
|
-
attr_reader :runtime
|
19
|
-
|
20
|
-
def exec(source)
|
21
|
-
runtime.exec(source)
|
22
|
-
end
|
23
|
-
|
24
|
-
def eval(source)
|
25
|
-
runtime.eval(source)
|
26
|
-
end
|
27
|
-
|
28
|
-
def compile(source)
|
29
|
-
runtime.compile(source)
|
30
|
-
end
|
31
|
-
|
32
|
-
def runtimes
|
33
|
-
Runtimes.runtimes
|
34
|
-
end
|
35
|
-
|
36
|
-
def runtime=(runtime)
|
37
|
-
raise RuntimeUnavailable, "#{runtime.name} is unavailable on this system" unless runtime.available?
|
38
|
-
@runtime = runtime
|
39
|
-
end
|
40
|
-
|
41
|
-
def root
|
42
|
-
@root ||= File.expand_path("../execjs", __FILE__)
|
43
|
-
end
|
44
|
-
|
45
|
-
def windows?
|
46
|
-
@windows ||= RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Eagerly detect runtime
|
51
|
-
self.runtime ||= Runtimes.best_available ||
|
52
|
-
raise(RuntimeUnavailable, "Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.")
|
5
|
+
self.runtime ||= Runtimes.autodetect
|
53
6
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "rbconfig"
|
2
|
+
|
3
|
+
module ExecJS
|
4
|
+
VERSION = "1.1.0"
|
5
|
+
|
6
|
+
class Error < ::StandardError; end
|
7
|
+
class RuntimeError < Error; end
|
8
|
+
class ProgramError < Error; end
|
9
|
+
class RuntimeUnavailable < RuntimeError; end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_reader :runtime
|
13
|
+
|
14
|
+
def runtime=(runtime)
|
15
|
+
raise RuntimeUnavailable, "#{runtime.name} is unavailable on this system" unless runtime.available?
|
16
|
+
@runtime = runtime
|
17
|
+
end
|
18
|
+
|
19
|
+
def exec(source)
|
20
|
+
runtime.exec(source)
|
21
|
+
end
|
22
|
+
|
23
|
+
def eval(source)
|
24
|
+
runtime.eval(source)
|
25
|
+
end
|
26
|
+
|
27
|
+
def compile(source)
|
28
|
+
runtime.compile(source)
|
29
|
+
end
|
30
|
+
|
31
|
+
def root
|
32
|
+
@root ||= File.expand_path("..", __FILE__)
|
33
|
+
end
|
34
|
+
|
35
|
+
def windows?
|
36
|
+
@windows ||= RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/execjs/runtimes.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
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
|
+
|
1
7
|
module ExecJS
|
2
8
|
module Runtimes
|
3
9
|
RubyRacer = RubyRacerRuntime.new
|
@@ -32,10 +38,34 @@ module ExecJS
|
|
32
38
|
)
|
33
39
|
|
34
40
|
|
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
|
+
|
35
47
|
def self.best_available
|
36
48
|
runtimes.find(&:available?)
|
37
49
|
end
|
38
50
|
|
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
|
+
|
39
69
|
def self.runtimes
|
40
70
|
@runtimes ||= [
|
41
71
|
RubyRacer,
|
@@ -48,4 +78,8 @@ module ExecJS
|
|
48
78
|
]
|
49
79
|
end
|
50
80
|
end
|
81
|
+
|
82
|
+
def self.runtimes
|
83
|
+
Runtimes.runtimes
|
84
|
+
end
|
51
85
|
end
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: execjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Sam Stephenson
|
@@ -11,7 +16,7 @@ autorequire:
|
|
11
16
|
bindir: bin
|
12
17
|
cert_chain: []
|
13
18
|
|
14
|
-
date: 2011-
|
19
|
+
date: 2011-06-01 00:00:00 -05:00
|
15
20
|
default_executable:
|
16
21
|
dependencies:
|
17
22
|
- !ruby/object:Gem::Dependency
|
@@ -22,6 +27,10 @@ dependencies:
|
|
22
27
|
requirements:
|
23
28
|
- - ~>
|
24
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 15
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 0
|
25
34
|
version: "1.0"
|
26
35
|
type: :runtime
|
27
36
|
version_requirements: *id001
|
@@ -33,6 +42,9 @@ dependencies:
|
|
33
42
|
requirements:
|
34
43
|
- - ">="
|
35
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
36
48
|
version: "0"
|
37
49
|
type: :development
|
38
50
|
version_requirements: *id002
|
@@ -44,6 +56,9 @@ dependencies:
|
|
44
56
|
requirements:
|
45
57
|
- - ">="
|
46
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
47
62
|
version: "0"
|
48
63
|
type: :development
|
49
64
|
version_requirements: *id003
|
@@ -55,6 +70,9 @@ dependencies:
|
|
55
70
|
requirements:
|
56
71
|
- - ">="
|
57
72
|
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
58
76
|
version: "0"
|
59
77
|
type: :development
|
60
78
|
version_requirements: *id004
|
@@ -71,6 +89,7 @@ extra_rdoc_files: []
|
|
71
89
|
files:
|
72
90
|
- lib/execjs.rb
|
73
91
|
- lib/execjs/external_runtime.rb
|
92
|
+
- lib/execjs/module.rb
|
74
93
|
- lib/execjs/mustang_runtime.rb
|
75
94
|
- lib/execjs/ruby_racer_runtime.rb
|
76
95
|
- lib/execjs/ruby_rhino_runtime.rb
|
@@ -96,12 +115,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
115
|
requirements:
|
97
116
|
- - ">="
|
98
117
|
- !ruby/object:Gem::Version
|
118
|
+
hash: 3
|
119
|
+
segments:
|
120
|
+
- 0
|
99
121
|
version: "0"
|
100
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
123
|
none: false
|
102
124
|
requirements:
|
103
125
|
- - ">="
|
104
126
|
- !ruby/object:Gem::Version
|
127
|
+
hash: 3
|
128
|
+
segments:
|
129
|
+
- 0
|
105
130
|
version: "0"
|
106
131
|
requirements: []
|
107
132
|
|