execjs 2.3.0 → 2.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/execjs/external_runtime.rb +30 -10
- data/lib/execjs/ruby_racer_runtime.rb +17 -15
- data/lib/execjs/ruby_rhino_runtime.rb +15 -14
- data/lib/execjs/support/jsc_runner.js +2 -2
- data/lib/execjs/support/jscript_runner.js +2 -2
- data/lib/execjs/support/node_runner.js +2 -2
- data/lib/execjs/support/spidermonkey_runner.js +2 -2
- data/lib/execjs/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fde57c2c3957d81859359cf4c369f608a644551b
|
4
|
+
data.tar.gz: e28210a8d96d0c21c113f3cf7be58f763f42fb87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ee2ee0d5407bda28d4351701bbcfd0a9b39bbb0de18843c78c258cd89ee39ee73fbfb9ec2f1172b43027c2ffcf8320d9471dc98de80c3c9cfb4804be8dac8f5
|
7
|
+
data.tar.gz: ac21345c3a7c2283d70f65f86f7b4577f694d184783d5d93e4d1a72d93fe3fa95c6e31612728efeb503f8216d8f4dfd7558f77cf9e94440b62ed5dbf000cdffb
|
data/README.md
CHANGED
@@ -64,7 +64,7 @@ older stock runtimes like JSC on OSX and JScript on Windows may not. You should
|
|
64
64
|
only count on ES3 features being available. Prefer feature checking these APIs
|
65
65
|
rather than hard coding support for specific runtimes.
|
66
66
|
|
67
|
-
**Can
|
67
|
+
**Can ExecJS be used to sandbox scripts?**
|
68
68
|
|
69
69
|
No, ExecJS shouldn't be used for any security related sandboxing. Since runtimes
|
70
70
|
are automatically detected, each runtime has different sandboxing properties.
|
@@ -24,12 +24,12 @@ module ExecJS
|
|
24
24
|
|
25
25
|
def exec(source, options = {})
|
26
26
|
source = encode(source)
|
27
|
-
source = "#{@source}\n#{source}" if @source
|
27
|
+
source = "#{@source}\n#{source}" if @source != ""
|
28
28
|
source = @runtime.compile_source(source)
|
29
29
|
|
30
30
|
tmpfile = write_to_tempfile(source)
|
31
31
|
begin
|
32
|
-
extract_result(@runtime.exec_runtime(tmpfile.path))
|
32
|
+
extract_result(@runtime.exec_runtime(tmpfile.path), tmpfile.path)
|
33
33
|
ensure
|
34
34
|
File.unlink(tmpfile)
|
35
35
|
end
|
@@ -57,14 +57,25 @@ module ExecJS
|
|
57
57
|
tmpfile
|
58
58
|
end
|
59
59
|
|
60
|
-
def extract_result(output)
|
61
|
-
status, value = output.empty? ? [] : ::JSON.parse(output, create_additions: false)
|
60
|
+
def extract_result(output, filename)
|
61
|
+
status, value, stack = output.empty? ? [] : ::JSON.parse(output, create_additions: false)
|
62
62
|
if status == "ok"
|
63
63
|
value
|
64
|
-
elsif value =~ /SyntaxError:/
|
65
|
-
raise RuntimeError, value
|
66
64
|
else
|
67
|
-
|
65
|
+
stack ||= ""
|
66
|
+
real_filename = File.realpath(filename)
|
67
|
+
stack = stack.split("\n").map do |line|
|
68
|
+
line.sub(" at ", "")
|
69
|
+
.sub(real_filename, "(execjs)")
|
70
|
+
.sub(filename, "(execjs)")
|
71
|
+
.strip
|
72
|
+
end
|
73
|
+
stack.reject! { |line| ["eval code", "eval@[native code]"].include?(line) }
|
74
|
+
stack.shift unless stack[0].to_s.include?("(execjs)")
|
75
|
+
error_class = value =~ /SyntaxError:/ ? RuntimeError : ProgramError
|
76
|
+
error = error_class.new(value)
|
77
|
+
error.set_backtrace(stack + caller)
|
78
|
+
raise error
|
68
79
|
end
|
69
80
|
end
|
70
81
|
end
|
@@ -158,7 +169,7 @@ module ExecJS
|
|
158
169
|
if $?.success?
|
159
170
|
output
|
160
171
|
else
|
161
|
-
raise
|
172
|
+
raise exec_runtime_error(output)
|
162
173
|
end
|
163
174
|
end
|
164
175
|
|
@@ -181,7 +192,7 @@ module ExecJS
|
|
181
192
|
if $?.success?
|
182
193
|
output
|
183
194
|
else
|
184
|
-
raise
|
195
|
+
raise exec_runtime_error(output)
|
185
196
|
end
|
186
197
|
end
|
187
198
|
else
|
@@ -193,13 +204,22 @@ module ExecJS
|
|
193
204
|
if $?.success?
|
194
205
|
output
|
195
206
|
else
|
196
|
-
raise
|
207
|
+
raise exec_runtime_error(output)
|
197
208
|
end
|
198
209
|
end
|
199
210
|
end
|
200
211
|
# Internally exposed for Context.
|
201
212
|
public :exec_runtime
|
202
213
|
|
214
|
+
def exec_runtime_error(output)
|
215
|
+
error = RuntimeError.new(output)
|
216
|
+
lines = output.split("\n")
|
217
|
+
lineno = lines[0][/:(\d+)$/, 1] if lines[0]
|
218
|
+
lineno ||= 1
|
219
|
+
error.set_backtrace(["(execjs):#{lineno}"] + caller)
|
220
|
+
error
|
221
|
+
end
|
222
|
+
|
203
223
|
def which(command)
|
204
224
|
Array(command).find do |name|
|
205
225
|
name, args = name.split(/\s+/, 2)
|
@@ -12,11 +12,7 @@ module ExecJS
|
|
12
12
|
begin
|
13
13
|
@v8_context.eval(source)
|
14
14
|
rescue ::V8::JSError => e
|
15
|
-
|
16
|
-
raise RuntimeError, e.value.to_s
|
17
|
-
else
|
18
|
-
raise ProgramError, e.value.to_s
|
19
|
-
end
|
15
|
+
raise wrap_error(e)
|
20
16
|
end
|
21
17
|
end
|
22
18
|
end
|
@@ -37,11 +33,7 @@ module ExecJS
|
|
37
33
|
begin
|
38
34
|
unbox @v8_context.eval("(#{source})")
|
39
35
|
rescue ::V8::JSError => e
|
40
|
-
|
41
|
-
raise RuntimeError, e.value.to_s
|
42
|
-
else
|
43
|
-
raise ProgramError, e.value.to_s
|
44
|
-
end
|
36
|
+
raise wrap_error(e)
|
45
37
|
end
|
46
38
|
end
|
47
39
|
end
|
@@ -52,11 +44,7 @@ module ExecJS
|
|
52
44
|
begin
|
53
45
|
unbox @v8_context.eval(properties).call(*args)
|
54
46
|
rescue ::V8::JSError => e
|
55
|
-
|
56
|
-
raise RuntimeError, e.value.to_s
|
57
|
-
else
|
58
|
-
raise ProgramError, e.value.to_s
|
59
|
-
end
|
47
|
+
raise wrap_error(e)
|
60
48
|
end
|
61
49
|
end
|
62
50
|
end
|
@@ -96,6 +84,20 @@ module ExecJS
|
|
96
84
|
result
|
97
85
|
end
|
98
86
|
end
|
87
|
+
|
88
|
+
def wrap_error(e)
|
89
|
+
error_class = e.value["name"] == "SyntaxError" ? RuntimeError : ProgramError
|
90
|
+
|
91
|
+
stack = e.value["stack"] || ""
|
92
|
+
stack = stack.split("\n")
|
93
|
+
stack.shift
|
94
|
+
stack = [e.message[/<eval>:\d+:\d+/, 0]].compact if stack.empty?
|
95
|
+
stack = stack.map { |line| line.sub(" at ", "").sub("<eval>", "(execjs)").strip }
|
96
|
+
|
97
|
+
error = error_class.new(e.value.to_s)
|
98
|
+
error.set_backtrace(stack + caller)
|
99
|
+
error
|
100
|
+
end
|
99
101
|
end
|
100
102
|
|
101
103
|
def name
|
@@ -10,7 +10,7 @@ module ExecJS
|
|
10
10
|
fix_memory_limit! @rhino_context
|
11
11
|
@rhino_context.eval(source)
|
12
12
|
rescue Exception => e
|
13
|
-
|
13
|
+
raise wrap_error(e)
|
14
14
|
end
|
15
15
|
|
16
16
|
def exec(source, options = {})
|
@@ -28,13 +28,13 @@ module ExecJS
|
|
28
28
|
unbox @rhino_context.eval("(#{source})")
|
29
29
|
end
|
30
30
|
rescue Exception => e
|
31
|
-
|
31
|
+
raise wrap_error(e)
|
32
32
|
end
|
33
33
|
|
34
34
|
def call(properties, *args)
|
35
35
|
unbox @rhino_context.eval(properties).call(*args)
|
36
36
|
rescue Exception => e
|
37
|
-
|
37
|
+
raise wrap_error(e)
|
38
38
|
end
|
39
39
|
|
40
40
|
def unbox(value)
|
@@ -58,17 +58,18 @@ module ExecJS
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
def
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
61
|
+
def wrap_error(e)
|
62
|
+
return e unless e.is_a?(::Rhino::JSError)
|
63
|
+
|
64
|
+
error_class = e.message == "syntax error" ? RuntimeError : ProgramError
|
65
|
+
|
66
|
+
stack = e.backtrace
|
67
|
+
stack = stack.map { |line| line.sub(" at ", "").sub("<eval>", "(execjs)").strip }
|
68
|
+
stack.unshift("(execjs):1") if e.javascript_backtrace.empty?
|
69
|
+
|
70
|
+
error = error_class.new(e.value.to_s)
|
71
|
+
error.set_backtrace(stack)
|
72
|
+
error
|
72
73
|
end
|
73
74
|
|
74
75
|
private
|
@@ -9,10 +9,10 @@
|
|
9
9
|
try {
|
10
10
|
print(JSON.stringify(['ok', result]));
|
11
11
|
} catch (err) {
|
12
|
-
print('
|
12
|
+
print(JSON.stringify(['err', '' + err, err.stack]));
|
13
13
|
}
|
14
14
|
}
|
15
15
|
} catch (err) {
|
16
|
-
print(JSON.stringify(['err', '' + err]));
|
16
|
+
print(JSON.stringify(['err', '' + err, err.stack]));
|
17
17
|
}
|
18
18
|
});
|
@@ -13,10 +13,10 @@
|
|
13
13
|
try {
|
14
14
|
print(JSON.stringify(['ok', result]));
|
15
15
|
} catch (err) {
|
16
|
-
print('
|
16
|
+
print(JSON.stringify(['err', err.name + ': ' + err.message, err.stack]));
|
17
17
|
}
|
18
18
|
}
|
19
19
|
} catch (err) {
|
20
|
-
print(JSON.stringify(['err', err.name + ': ' + err.message]));
|
20
|
+
print(JSON.stringify(['err', err.name + ': ' + err.message, err.stack]));
|
21
21
|
}
|
22
22
|
});
|
@@ -11,10 +11,10 @@
|
|
11
11
|
try {
|
12
12
|
print(JSON.stringify(['ok', result]));
|
13
13
|
} catch (err) {
|
14
|
-
print('
|
14
|
+
print(JSON.stringify(['err', '' + err, err.stack]));
|
15
15
|
}
|
16
16
|
}
|
17
17
|
} catch (err) {
|
18
|
-
print(JSON.stringify(['err', '' + err]));
|
18
|
+
print(JSON.stringify(['err', '' + err, err.stack]));
|
19
19
|
}
|
20
20
|
});
|
@@ -9,10 +9,10 @@
|
|
9
9
|
try {
|
10
10
|
print(JSON.stringify(['ok', result]));
|
11
11
|
} catch (err) {
|
12
|
-
print('
|
12
|
+
print(JSON.stringify(['err', '' + err, err.stack]));
|
13
13
|
}
|
14
14
|
}
|
15
15
|
} catch (err) {
|
16
|
-
print(JSON.stringify(['err', '' + err]));
|
16
|
+
print(JSON.stringify(['err', '' + err, err.stack]));
|
17
17
|
}
|
18
18
|
});
|
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.4.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: 2015-
|
12
|
+
date: 2015-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
72
|
rubyforge_project:
|
73
|
-
rubygems_version: 2.
|
73
|
+
rubygems_version: 2.4.5
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
76
|
summary: Run JavaScript code from Ruby
|