execjs 1.2.9 → 1.2.10

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.
@@ -94,7 +94,7 @@ module ExecJS
94
94
  @test_args = options[:test_args]
95
95
  @test_match = options[:test_match]
96
96
  @encoding = options[:encoding]
97
- @binary = locate_binary
97
+ @binary = nil
98
98
  end
99
99
 
100
100
  def exec(source)
@@ -113,16 +113,37 @@ module ExecJS
113
113
 
114
114
  def available?
115
115
  require "multi_json"
116
- @binary ? true : false
116
+ binary ? true : false
117
117
  end
118
118
 
119
+ private
120
+ def binary
121
+ @binary ||= locate_binary
122
+ end
123
+
124
+ def which_windows(name)
125
+ result = `#{shell_escape("#{ExecJS.root}/support/which.bat", name)}`
126
+ result.strip.split("\n").first
127
+ end
128
+
129
+ def which_unix(name)
130
+ if File.executable? cmd
131
+ cmd
132
+ else
133
+ path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |path|
134
+ File.executable? File.join(path, cmd)
135
+ }
136
+ path && File.expand_path(cmd, path)
137
+ end
138
+ end
139
+
119
140
  protected
120
141
  def runner_source
121
142
  @runner_source ||= IO.read(@runner_path)
122
143
  end
123
144
 
124
145
  def exec_runtime(filename)
125
- output = sh("#{shell_escape(*(@binary.split(' ') << filename))} 2>&1")
146
+ output = sh("#{shell_escape(*(binary.split(' ') << filename))} 2>&1")
126
147
  if $?.success?
127
148
  output
128
149
  else
@@ -142,19 +163,14 @@ module ExecJS
142
163
  end
143
164
 
144
165
  def which(command)
145
- Array(command).each do |name|
166
+ Array(command).find do |name|
146
167
  name, args = name.split(/\s+/, 2)
147
- result = if ExecJS.windows?
148
- `#{shell_escape("#{ExecJS.root}/support/which.bat", name)}`
149
- else
150
- `#{shell_escape('command', '-v', name)} 2>/dev/null`
151
- end
168
+ path = ExecJS.windows? ? which_windows(name) : which_unix(name)
152
169
 
153
- if path = result.strip.split("\n").first
154
- return args ? "#{path} #{args}" : path
155
- end
170
+ next unless path
171
+
172
+ args ? "#{path} #{args}" : path
156
173
  end
157
- nil
158
174
  end
159
175
 
160
176
  if "".respond_to?(:force_encoding)
@@ -1,3 +1,3 @@
1
1
  module ExecJS
2
- VERSION = "1.2.9"
2
+ VERSION = "1.2.10"
3
3
  end
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: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 9
10
- version: 1.2.9
9
+ - 10
10
+ version: 1.2.10
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-09-24 00:00:00 -05:00
19
+ date: 2011-12-05 00:00:00 -06:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency