execjs 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,10 @@
1
1
  require "rbconfig"
2
2
 
3
3
  module ExecJS
4
- class Error < ::StandardError; end
5
- class RuntimeError < Error; end
6
- class ProgramError < Error; end
4
+ class Error < ::StandardError; end
5
+ class RuntimeError < Error; end
6
+ class ProgramError < Error; end
7
+ class RuntimeUnavailable < RuntimeError; end
7
8
 
8
9
  autoload :ExternalRuntime, "execjs/external_runtime"
9
10
  autoload :MustangRuntime, "execjs/mustang_runtime"
@@ -11,35 +12,40 @@ module ExecJS
11
12
  autoload :RubyRhinoRuntime, "execjs/ruby_rhino_runtime"
12
13
  autoload :Runtimes, "execjs/runtimes"
13
14
 
14
- def self.exec(source)
15
- runtime.exec(source)
16
- end
15
+ class << self
16
+ attr_reader :runtime
17
17
 
18
- def self.eval(source)
19
- runtime.eval(source)
20
- end
18
+ def exec(source)
19
+ runtime.exec(source)
20
+ end
21
21
 
22
- def self.compile(source)
23
- runtime.compile(source)
24
- end
22
+ def eval(source)
23
+ runtime.eval(source)
24
+ end
25
25
 
26
- def self.runtimes
27
- Runtimes.runtimes
28
- end
26
+ def compile(source)
27
+ runtime.compile(source)
28
+ end
29
29
 
30
- def self.runtime
31
- @runtime ||= Runtimes.best_available ||
32
- raise(ExecJS::RuntimeError, "Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.")
33
- end
30
+ def runtimes
31
+ Runtimes.runtimes
32
+ end
34
33
 
35
- def self.root
36
- @root ||= File.expand_path("../execjs", __FILE__)
37
- end
34
+ def runtime=(runtime)
35
+ raise RuntimeUnavailable, "#{runtime.name} is unavailable on this system" unless runtime.available?
36
+ @runtime = runtime
37
+ end
38
+
39
+ def root
40
+ @root ||= File.expand_path("../execjs", __FILE__)
41
+ end
38
42
 
39
- def self.windows?
40
- @windows ||= RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
43
+ def windows?
44
+ @windows ||= RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
45
+ end
41
46
  end
42
47
 
43
- # Eager detect runtime
44
- self.runtime
48
+ # Eagerly detect runtime
49
+ self.runtime ||= Runtimes.best_available ||
50
+ raise(RuntimeUnavailable, "Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.")
45
51
  end
@@ -16,6 +16,6 @@
16
16
  }
17
17
  }
18
18
  } catch (err) {
19
- print(JSON.stringify(['err', '' + err]));
19
+ print(JSON.stringify(['err', err.name + ': ' + err.message]));
20
20
  }
21
21
  });
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: execjs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
8
  - 4
10
- version: 0.3.4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Stephenson
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-12 00:00:00 -05:00
19
+ date: 2011-05-17 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  requirements: []
131
131
 
132
132
  rubyforge_project: execjs
133
- rubygems_version: 1.6.2
133
+ rubygems_version: 1.5.0
134
134
  signing_key:
135
135
  specification_version: 3
136
136
  summary: Run JavaScript code from Ruby