execjs 2.7.0 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -3
- data/lib/execjs/duktape_runtime.rb +2 -1
- data/lib/execjs/external_runtime.rb +3 -3
- data/lib/execjs/mini_racer_runtime.rb +1 -0
- data/lib/execjs/runtime.rb +16 -1
- data/lib/execjs/runtimes.rb +8 -7
- data/lib/execjs/support/jsc_runner.js +1 -0
- data/lib/execjs/support/node_runner.js +13 -1
- data/lib/execjs/version.rb +1 -1
- metadata +6 -8
- data/lib/execjs/ruby_racer_runtime.rb +0 -114
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d8d9f5aa1c15a7f78fd46fac3e22c3341a196d4cf82212cbc37669bd49daa2a4
|
4
|
+
data.tar.gz: 4b720a645a2d68adbd09d7e9111b12e8034c4f038738a7fe2d7b1be928d80002
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2388cc21b50bc84c26546c5e2ecd5be158f712e77fb3d505bc5b61d8fa292cc9a82796c2c25c56181a6cd84b6f9e09af7950648e0eacf3421e5a88fccab60d6d
|
7
|
+
data.tar.gz: c761477dff8eaeba2534175722b4ea0f386499a5a524ae202bd5310c230d861f4bcf6efd4b489b63f7958756615b6cd56d2128805ca239d98abf7894d98b1223
|
data/README.md
CHANGED
@@ -7,8 +7,6 @@ returns the result to you as a Ruby object.
|
|
7
7
|
|
8
8
|
ExecJS supports these runtimes:
|
9
9
|
|
10
|
-
* [therubyracer](https://github.com/cowboyd/therubyracer) - Google V8
|
11
|
-
embedded within Ruby
|
12
10
|
* [therubyrhino](https://github.com/cowboyd/therubyrhino) - Mozilla
|
13
11
|
Rhino embedded within JRuby
|
14
12
|
* [Duktape.rb](https://github.com/judofyr/duktape.rb) - Duktape JavaScript interpreter
|
@@ -76,7 +74,7 @@ You shouldn't use `ExecJS.eval` on any inputs you wouldn't feel comfortable Ruby
|
|
76
74
|
|
77
75
|
## Contributing to ExecJS
|
78
76
|
|
79
|
-
ExecJS is work of
|
77
|
+
ExecJS is work of dozens of contributors. You're encouraged to submit pull requests, propose
|
80
78
|
features and discuss issues.
|
81
79
|
|
82
80
|
See [CONTRIBUTING](CONTRIBUTING.md).
|
@@ -26,7 +26,8 @@ module ExecJS
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def call(identifier, *args)
|
29
|
-
@ctx.
|
29
|
+
@ctx.exec_string("__execjs_duktape_call = #{identifier}", '(execjs)')
|
30
|
+
@ctx.call_prop("__execjs_duktape_call", *args)
|
30
31
|
rescue Exception => e
|
31
32
|
raise wrap_error(e)
|
32
33
|
end
|
@@ -173,7 +173,7 @@ module ExecJS
|
|
173
173
|
begin
|
174
174
|
command = binary.split(" ") << filename
|
175
175
|
`#{shell_escape(*command)} 2>&1 > #{path}`
|
176
|
-
output = File.open(path, 'rb',
|
176
|
+
output = File.open(path, 'rb', **@popen_options) { |f| f.read }
|
177
177
|
ensure
|
178
178
|
File.unlink(path) if path
|
179
179
|
end
|
@@ -197,7 +197,7 @@ module ExecJS
|
|
197
197
|
|
198
198
|
def exec_runtime(filename)
|
199
199
|
command = "#{Shellwords.join(binary.split(' ') << filename)} 2>&1"
|
200
|
-
io = IO.popen(command,
|
200
|
+
io = IO.popen(command, **@popen_options)
|
201
201
|
output = io.read
|
202
202
|
io.close
|
203
203
|
|
@@ -209,7 +209,7 @@ module ExecJS
|
|
209
209
|
end
|
210
210
|
else
|
211
211
|
def exec_runtime(filename)
|
212
|
-
io = IO.popen(binary.split(' ') << filename, @popen_options.merge({err: [:child, :out]}))
|
212
|
+
io = IO.popen(binary.split(' ') << filename, **(@popen_options.merge({err: [:child, :out]})))
|
213
213
|
output = io.read
|
214
214
|
io.close
|
215
215
|
|
data/lib/execjs/runtime.rb
CHANGED
@@ -9,15 +9,30 @@ module ExecJS
|
|
9
9
|
def initialize(runtime, source = "", options = {})
|
10
10
|
end
|
11
11
|
|
12
|
+
# Evaluates the +source+ in the context of a function body and returns the
|
13
|
+
# returned value.
|
14
|
+
#
|
15
|
+
# context.exec("return 1") # => 1
|
16
|
+
# context.exec("1") # => nil (nothing was returned)
|
12
17
|
def exec(source, options = {})
|
13
18
|
raise NotImplementedError
|
14
19
|
end
|
15
20
|
|
21
|
+
# Evaluates the +source+ as an expression and returns the result.
|
22
|
+
#
|
23
|
+
# context.eval("1") # => 1
|
24
|
+
# context.eval("return 1") # => Raises SyntaxError
|
16
25
|
def eval(source, options = {})
|
17
26
|
raise NotImplementedError
|
18
27
|
end
|
19
28
|
|
20
|
-
|
29
|
+
# Evaluates +source+ as an expression (which should be of type
|
30
|
+
# +function+), and calls the function with the given arguments.
|
31
|
+
# The function will be evaluated with the global object as +this+.
|
32
|
+
#
|
33
|
+
# context.call("function(a, b) { return a + b }", 1, 1) # => 2
|
34
|
+
# context.call("CoffeeScript.compile", "1 + 1")
|
35
|
+
def call(source, *args)
|
21
36
|
raise NotImplementedError
|
22
37
|
end
|
23
38
|
end
|
data/lib/execjs/runtimes.rb
CHANGED
@@ -2,7 +2,6 @@ require "execjs/module"
|
|
2
2
|
require "execjs/disabled_runtime"
|
3
3
|
require "execjs/duktape_runtime"
|
4
4
|
require "execjs/external_runtime"
|
5
|
-
require "execjs/ruby_racer_runtime"
|
6
5
|
require "execjs/ruby_rhino_runtime"
|
7
6
|
require "execjs/mini_racer_runtime"
|
8
7
|
|
@@ -12,22 +11,23 @@ module ExecJS
|
|
12
11
|
|
13
12
|
Duktape = DuktapeRuntime.new
|
14
13
|
|
15
|
-
RubyRacer = RubyRacerRuntime.new
|
16
|
-
|
17
14
|
RubyRhino = RubyRhinoRuntime.new
|
18
15
|
|
19
16
|
MiniRacer = MiniRacerRuntime.new
|
20
17
|
|
21
18
|
Node = ExternalRuntime.new(
|
22
19
|
name: "Node.js (V8)",
|
23
|
-
command: ["
|
20
|
+
command: ["node", "nodejs"],
|
24
21
|
runner_path: ExecJS.root + "/support/node_runner.js",
|
25
22
|
encoding: 'UTF-8'
|
26
23
|
)
|
27
24
|
|
28
25
|
JavaScriptCore = ExternalRuntime.new(
|
29
26
|
name: "JavaScriptCore",
|
30
|
-
command:
|
27
|
+
command: [
|
28
|
+
"/System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Helpers/jsc",
|
29
|
+
"/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc",
|
30
|
+
],
|
31
31
|
runner_path: ExecJS.root + "/support/jsc_runner.js"
|
32
32
|
)
|
33
33
|
|
@@ -64,7 +64,9 @@ module ExecJS
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def self.from_environment
|
67
|
-
|
67
|
+
env = ENV["EXECJS_RUNTIME"]
|
68
|
+
if env && !env.empty?
|
69
|
+
name = env
|
68
70
|
raise RuntimeUnavailable, "#{name} runtime is not defined" unless const_defined?(name)
|
69
71
|
runtime = const_get(name)
|
70
72
|
|
@@ -79,7 +81,6 @@ module ExecJS
|
|
79
81
|
|
80
82
|
def self.runtimes
|
81
83
|
@runtimes ||= [
|
82
|
-
RubyRacer,
|
83
84
|
RubyRhino,
|
84
85
|
Duktape,
|
85
86
|
MiniRacer,
|
@@ -1,10 +1,20 @@
|
|
1
|
-
(function(program, execJS) { execJS(program) })(function(global, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source}
|
1
|
+
(function(program, execJS) { execJS(program) })(function(global, process, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source}
|
2
2
|
}, function(program) {
|
3
3
|
var output, print = function(string) {
|
4
4
|
process.stdout.write('' + string);
|
5
5
|
};
|
6
6
|
try {
|
7
|
+
var __process__ = process;
|
8
|
+
delete this.process;
|
9
|
+
delete this.console;
|
10
|
+
delete this.setTimeout;
|
11
|
+
delete this.setInterval;
|
12
|
+
delete this.clearTimeout;
|
13
|
+
delete this.clearInterval;
|
14
|
+
delete this.setImmediate;
|
15
|
+
delete this.clearImmediate;
|
7
16
|
result = program();
|
17
|
+
this.process = __process__;
|
8
18
|
if (typeof result == 'undefined' && result !== null) {
|
9
19
|
print('["ok"]');
|
10
20
|
} else {
|
@@ -15,6 +25,8 @@
|
|
15
25
|
}
|
16
26
|
}
|
17
27
|
} catch (err) {
|
28
|
+
this.process = __process__;
|
18
29
|
print(JSON.stringify(['err', '' + err, err.stack]));
|
19
30
|
}
|
31
|
+
__process__.exit(0);
|
20
32
|
});
|
data/lib/execjs/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: execjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Stephenson
|
8
8
|
- Josh Peek
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-05-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -42,7 +42,6 @@ files:
|
|
42
42
|
- lib/execjs/external_runtime.rb
|
43
43
|
- lib/execjs/mini_racer_runtime.rb
|
44
44
|
- lib/execjs/module.rb
|
45
|
-
- lib/execjs/ruby_racer_runtime.rb
|
46
45
|
- lib/execjs/ruby_rhino_runtime.rb
|
47
46
|
- lib/execjs/runtime.rb
|
48
47
|
- lib/execjs/runtimes.rb
|
@@ -57,7 +56,7 @@ homepage: https://github.com/rails/execjs
|
|
57
56
|
licenses:
|
58
57
|
- MIT
|
59
58
|
metadata: {}
|
60
|
-
post_install_message:
|
59
|
+
post_install_message:
|
61
60
|
rdoc_options: []
|
62
61
|
require_paths:
|
63
62
|
- lib
|
@@ -72,9 +71,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
71
|
- !ruby/object:Gem::Version
|
73
72
|
version: '0'
|
74
73
|
requirements: []
|
75
|
-
|
76
|
-
|
77
|
-
signing_key:
|
74
|
+
rubygems_version: 3.2.15
|
75
|
+
signing_key:
|
78
76
|
specification_version: 4
|
79
77
|
summary: Run JavaScript code from Ruby
|
80
78
|
test_files: []
|
@@ -1,114 +0,0 @@
|
|
1
|
-
require "execjs/runtime"
|
2
|
-
|
3
|
-
module ExecJS
|
4
|
-
class RubyRacerRuntime < Runtime
|
5
|
-
class Context < Runtime::Context
|
6
|
-
def initialize(runtime, source = "", options = {})
|
7
|
-
source = encode(source)
|
8
|
-
|
9
|
-
lock do
|
10
|
-
@v8_context = ::V8::Context.new
|
11
|
-
|
12
|
-
begin
|
13
|
-
@v8_context.eval(source)
|
14
|
-
rescue ::V8::JSError => e
|
15
|
-
raise wrap_error(e)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def exec(source, options = {})
|
21
|
-
source = encode(source)
|
22
|
-
|
23
|
-
if /\S/ =~ source
|
24
|
-
eval "(function(){#{source}})()", options
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def eval(source, options = {})
|
29
|
-
source = encode(source)
|
30
|
-
|
31
|
-
if /\S/ =~ source
|
32
|
-
lock do
|
33
|
-
begin
|
34
|
-
unbox @v8_context.eval("(#{source})")
|
35
|
-
rescue ::V8::JSError => e
|
36
|
-
raise wrap_error(e)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def call(properties, *args)
|
43
|
-
lock do
|
44
|
-
begin
|
45
|
-
unbox @v8_context.eval(properties).call(*args)
|
46
|
-
rescue ::V8::JSError => e
|
47
|
-
raise wrap_error(e)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def unbox(value)
|
53
|
-
case value
|
54
|
-
when ::V8::Function
|
55
|
-
nil
|
56
|
-
when ::V8::Array
|
57
|
-
value.map { |v| unbox(v) }
|
58
|
-
when ::V8::Object
|
59
|
-
value.inject({}) do |vs, (k, v)|
|
60
|
-
vs[k] = unbox(v) unless v.is_a?(::V8::Function)
|
61
|
-
vs
|
62
|
-
end
|
63
|
-
when String
|
64
|
-
value.force_encoding('UTF-8')
|
65
|
-
else
|
66
|
-
value
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
def lock
|
72
|
-
result, exception = nil, nil
|
73
|
-
V8::C::Locker() do
|
74
|
-
begin
|
75
|
-
result = yield
|
76
|
-
rescue Exception => e
|
77
|
-
exception = e
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
if exception
|
82
|
-
raise exception
|
83
|
-
else
|
84
|
-
result
|
85
|
-
end
|
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
|
101
|
-
end
|
102
|
-
|
103
|
-
def name
|
104
|
-
"therubyracer (V8)"
|
105
|
-
end
|
106
|
-
|
107
|
-
def available?
|
108
|
-
require "v8"
|
109
|
-
true
|
110
|
-
rescue LoadError
|
111
|
-
false
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|