execjs 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/execjs/external_runtime.rb +57 -40
- data/lib/execjs/support/jsc_runner.js +1 -1
- data/lib/execjs/support/jscript_runner.js +1 -1
- data/lib/execjs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6c21deff91972c3dd78ad9cd59ac2b0c155aac7
|
4
|
+
data.tar.gz: bc434905c2f108e8e3a8a03b4c4acea3de19d481
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 148ae528714f32a5c08728b48d24464a8f2a45ae8cae92dd5ac66b9b7e2618ca0236dcdcad4cec465298036e19cefec0fd533bed7cef198a5cc7daebf531227d
|
7
|
+
data.tar.gz: 76ad76dbcdb7cf54895e9d8137f9ecd2c9a7aee2c75b0704fe1afbfe6fa45ce7e3b42f69b1025be88c88ed9c41140bc11da123ff948085eae14fcc06cc66ecaf
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "tmpdir"
|
2
2
|
require "execjs/runtime"
|
3
3
|
|
4
4
|
module ExecJS
|
@@ -22,9 +22,13 @@ module ExecJS
|
|
22
22
|
def exec(source, options = {})
|
23
23
|
source = encode(source)
|
24
24
|
source = "#{@source}\n#{source}" if @source
|
25
|
+
source = @runtime.compile_source(source)
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
tmpfile = write_to_tempfile(source)
|
28
|
+
begin
|
29
|
+
extract_result(@runtime.exec_runtime(tmpfile.path))
|
30
|
+
ensure
|
31
|
+
File.unlink(tmpfile)
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
@@ -33,28 +37,21 @@ module ExecJS
|
|
33
37
|
end
|
34
38
|
|
35
39
|
protected
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
# See Tempfile.create on Ruby 2.1
|
41
|
+
def create_tempfile(basename)
|
42
|
+
tmpfile = nil
|
43
|
+
Dir::Tmpname.create(basename) do |tmpname|
|
44
|
+
mode = File::WRONLY | File::CREAT | File::EXCL
|
45
|
+
tmpfile = File.open(tmpname, mode, 0600)
|
46
|
+
end
|
47
|
+
tmpfile
|
43
48
|
end
|
44
49
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
output.sub!('#{encoded_source}') do
|
51
|
-
encoded_source = encode_unicode_codepoints(source)
|
52
|
-
::JSON.generate("(function(){ #{encoded_source} })()", quirks_mode: true)
|
53
|
-
end
|
54
|
-
output.sub!('#{json2_source}') do
|
55
|
-
IO.read(ExecJS.root + "/support/json2.js")
|
56
|
-
end
|
57
|
-
end
|
50
|
+
def write_to_tempfile(contents)
|
51
|
+
tmpfile = create_tempfile(['execjs', 'js'])
|
52
|
+
tmpfile.write(contents)
|
53
|
+
tmpfile.close
|
54
|
+
tmpfile
|
58
55
|
end
|
59
56
|
|
60
57
|
def extract_result(output)
|
@@ -67,12 +64,6 @@ module ExecJS
|
|
67
64
|
raise ProgramError, value
|
68
65
|
end
|
69
66
|
end
|
70
|
-
|
71
|
-
def encode_unicode_codepoints(str)
|
72
|
-
str.gsub(/[\u0080-\uffff]/) do |ch|
|
73
|
-
"\\u%04x" % ch.codepoints.to_a
|
74
|
-
end
|
75
|
-
end
|
76
67
|
end
|
77
68
|
|
78
69
|
attr_reader :name
|
@@ -84,6 +75,14 @@ module ExecJS
|
|
84
75
|
@encoding = options[:encoding]
|
85
76
|
@deprecated = !!options[:deprecated]
|
86
77
|
@binary = nil
|
78
|
+
|
79
|
+
@popen_options = {}
|
80
|
+
@popen_options[:external_encoding] = @encoding if @encoding
|
81
|
+
@popen_options[:internal_encoding] = ::Encoding.default_internal || 'UTF-8'
|
82
|
+
|
83
|
+
if @runner_path
|
84
|
+
instance_eval generate_compile_method(@runner_path)
|
85
|
+
end
|
87
86
|
end
|
88
87
|
|
89
88
|
def available?
|
@@ -117,18 +116,44 @@ module ExecJS
|
|
117
116
|
end
|
118
117
|
|
119
118
|
protected
|
120
|
-
def
|
121
|
-
|
119
|
+
def generate_compile_method(path)
|
120
|
+
<<-RUBY
|
121
|
+
def compile_source(source)
|
122
|
+
<<-RUNNER
|
123
|
+
#{IO.read(path)}
|
124
|
+
RUNNER
|
125
|
+
end
|
126
|
+
RUBY
|
127
|
+
end
|
128
|
+
|
129
|
+
def json2_source
|
130
|
+
@json2_source ||= IO.read(ExecJS.root + "/support/json2.js")
|
131
|
+
end
|
132
|
+
|
133
|
+
def encode_source(source)
|
134
|
+
encoded_source = encode_unicode_codepoints(source)
|
135
|
+
::JSON.generate("(function(){ #{encoded_source} })()", quirks_mode: true)
|
136
|
+
end
|
137
|
+
|
138
|
+
def encode_unicode_codepoints(str)
|
139
|
+
str.gsub(/[\u0080-\uffff]/) do |ch|
|
140
|
+
"\\u%04x" % ch.codepoints.to_a
|
141
|
+
end
|
122
142
|
end
|
123
143
|
|
124
144
|
def exec_runtime(filename)
|
125
|
-
|
145
|
+
io = IO.popen(binary.split(' ') + [filename, {err: [:child, :out]}], @popen_options)
|
146
|
+
output = io.read
|
147
|
+
io.close
|
148
|
+
|
126
149
|
if $?.success?
|
127
150
|
output
|
128
151
|
else
|
129
152
|
raise RuntimeError, output
|
130
153
|
end
|
131
154
|
end
|
155
|
+
# Internally exposed for Context.
|
156
|
+
public :exec_runtime
|
132
157
|
|
133
158
|
def which(command)
|
134
159
|
Array(command).find do |name|
|
@@ -140,13 +165,5 @@ module ExecJS
|
|
140
165
|
args ? "#{path} #{args}" : path
|
141
166
|
end
|
142
167
|
end
|
143
|
-
|
144
|
-
def sh(command)
|
145
|
-
output, options = nil, {}
|
146
|
-
options[:external_encoding] = @encoding if @encoding
|
147
|
-
options[:internal_encoding] = ::Encoding.default_internal || 'UTF-8'
|
148
|
-
IO.popen(command, options) { |f| output = f.read }
|
149
|
-
output
|
150
|
-
end
|
151
168
|
end
|
152
169
|
end
|
data/lib/execjs/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: execjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Stephenson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|