execjs 2.5.2 → 2.7.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/{LICENSE → MIT-LICENSE} +2 -2
- data/README.md +9 -4
- data/lib/execjs/disabled_runtime.rb +3 -3
- data/lib/execjs/duktape_runtime.rb +1 -1
- data/lib/execjs/external_runtime.rb +18 -13
- data/lib/execjs/mini_racer_runtime.rb +102 -0
- data/lib/execjs/module.rb +6 -6
- data/lib/execjs/ruby_racer_runtime.rb +1 -1
- data/lib/execjs/ruby_rhino_runtime.rb +1 -1
- data/lib/execjs/runtime.rb +23 -9
- data/lib/execjs/runtimes.rb +15 -3
- data/lib/execjs/support/v8_runner.js +18 -0
- data/lib/execjs/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c281240b821b63764b2972d440a39405d77bca30
|
4
|
+
data.tar.gz: f661c8d78fb1099bc3787e29c40b91b2e067be2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d59815bb2b71498baa84e75f9ccdc5210e82a5dc474f22a1c9b749602eeee91a4e0844484e7580c05cee6dcfa94c6672b72e6e2133c23227e9d5011af3110632
|
7
|
+
data.tar.gz: e38d3bfdfe65de9017d2ba829e40646c98c931d9fae56f8aa39cb345ce5da3e39a4b1c7199fa79dc89609f56d8afae24427d22ef64f67fba092456f60e8f4632
|
data/{LICENSE → MIT-LICENSE}
RENAMED
@@ -1,5 +1,5 @@
|
|
1
|
-
Copyright (c) 2015 Sam Stephenson
|
2
|
-
Copyright (c) 2015 Josh Peek
|
1
|
+
Copyright (c) 2015-2016 Sam Stephenson
|
2
|
+
Copyright (c) 2015-2016 Josh Peek
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -15,6 +15,9 @@ ExecJS supports these runtimes:
|
|
15
15
|
* [Node.js](http://nodejs.org/)
|
16
16
|
* Apple JavaScriptCore - Included with Mac OS X
|
17
17
|
* [Microsoft Windows Script Host](http://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx) (JScript)
|
18
|
+
* [Google V8](http://code.google.com/p/v8/)
|
19
|
+
* [mini_racer](https://github.com/discourse/mini_racer) - Google V8
|
20
|
+
embedded within Ruby
|
18
21
|
|
19
22
|
A short example:
|
20
23
|
|
@@ -42,7 +45,6 @@ context.call("CoffeeScript.compile", "square = (x) -> x * x", bare: true)
|
|
42
45
|
$ gem install execjs
|
43
46
|
```
|
44
47
|
|
45
|
-
|
46
48
|
# FAQ
|
47
49
|
|
48
50
|
**Why can't I use CommonJS `require()` inside ExecJS?**
|
@@ -72,9 +74,12 @@ are automatically detected, each runtime has different sandboxing properties.
|
|
72
74
|
You shouldn't use `ExecJS.eval` on any inputs you wouldn't feel comfortable Ruby
|
73
75
|
`eval()`ing.
|
74
76
|
|
77
|
+
## Contributing to ExecJS
|
75
78
|
|
76
|
-
|
79
|
+
ExecJS is work of hundreds of contributors. You're encouraged to submit pull requests, propose
|
80
|
+
features and discuss issues.
|
77
81
|
|
78
|
-
|
82
|
+
See [CONTRIBUTING](CONTRIBUTING.md).
|
79
83
|
|
80
|
-
|
84
|
+
## License
|
85
|
+
ExecJS is released under the [MIT License](MIT-LICENSE).
|
@@ -6,15 +6,15 @@ module ExecJS
|
|
6
6
|
"Disabled"
|
7
7
|
end
|
8
8
|
|
9
|
-
def exec(source)
|
9
|
+
def exec(source, options = {})
|
10
10
|
raise Error, "ExecJS disabled"
|
11
11
|
end
|
12
12
|
|
13
|
-
def eval(source)
|
13
|
+
def eval(source, options = {})
|
14
14
|
raise Error, "ExecJS disabled"
|
15
15
|
end
|
16
16
|
|
17
|
-
def compile(source)
|
17
|
+
def compile(source, options = {})
|
18
18
|
raise Error, "ExecJS disabled"
|
19
19
|
end
|
20
20
|
|
@@ -4,7 +4,7 @@ require "json"
|
|
4
4
|
module ExecJS
|
5
5
|
class DuktapeRuntime < Runtime
|
6
6
|
class Context < Runtime::Context
|
7
|
-
def initialize(runtime, source = "")
|
7
|
+
def initialize(runtime, source = "", options = {})
|
8
8
|
@ctx = Duktape::Context.new(complex_object: nil)
|
9
9
|
@ctx.exec_string(encode(source), '(execjs)')
|
10
10
|
rescue Exception => e
|
@@ -4,7 +4,7 @@ require "execjs/runtime"
|
|
4
4
|
module ExecJS
|
5
5
|
class ExternalRuntime < Runtime
|
6
6
|
class Context < Runtime::Context
|
7
|
-
def initialize(runtime, source = "")
|
7
|
+
def initialize(runtime, source = "", options = {})
|
8
8
|
source = encode(source)
|
9
9
|
|
10
10
|
@runtime = runtime
|
@@ -120,20 +120,25 @@ module ExecJS
|
|
120
120
|
@binary ||= which(@command)
|
121
121
|
end
|
122
122
|
|
123
|
-
def locate_executable(
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
if File.executable? cmd
|
129
|
-
cmd
|
130
|
-
else
|
131
|
-
path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |p|
|
132
|
-
full_path = File.join(p, cmd)
|
133
|
-
File.executable?(full_path) && File.file?(full_path)
|
123
|
+
def locate_executable(command)
|
124
|
+
commands = Array(command)
|
125
|
+
if ExecJS.windows? && File.extname(command) == ""
|
126
|
+
ENV['PATHEXT'].split(File::PATH_SEPARATOR).each { |p|
|
127
|
+
commands << (command + p)
|
134
128
|
}
|
135
|
-
path && File.expand_path(cmd, path)
|
136
129
|
end
|
130
|
+
|
131
|
+
commands.find { |cmd|
|
132
|
+
if File.executable? cmd
|
133
|
+
cmd
|
134
|
+
else
|
135
|
+
path = ENV['PATH'].split(File::PATH_SEPARATOR).find { |p|
|
136
|
+
full_path = File.join(p, cmd)
|
137
|
+
File.executable?(full_path) && File.file?(full_path)
|
138
|
+
}
|
139
|
+
path && File.expand_path(cmd, path)
|
140
|
+
end
|
141
|
+
}
|
137
142
|
end
|
138
143
|
|
139
144
|
protected
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require "execjs/runtime"
|
2
|
+
|
3
|
+
module ExecJS
|
4
|
+
class MiniRacerRuntime < Runtime
|
5
|
+
class Context < Runtime::Context
|
6
|
+
def initialize(runtime, source = "", options={})
|
7
|
+
source = encode(source)
|
8
|
+
@context = ::MiniRacer::Context.new
|
9
|
+
translate do
|
10
|
+
@context.eval(source)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def exec(source, options = {})
|
15
|
+
source = encode(source)
|
16
|
+
|
17
|
+
if /\S/ =~ source
|
18
|
+
eval "(function(){#{source}})()"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def eval(source, options = {})
|
23
|
+
source = encode(source)
|
24
|
+
|
25
|
+
if /\S/ =~ source
|
26
|
+
translate do
|
27
|
+
@context.eval("(#{source})")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def call(identifier, *args)
|
33
|
+
# TODO optimise generate
|
34
|
+
eval "#{identifier}.apply(this, #{::JSON.generate(args)})"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def strip_functions!(value)
|
40
|
+
if Array === value
|
41
|
+
value.map! do |v|
|
42
|
+
if MiniRacer::JavaScriptFunction === value
|
43
|
+
nil
|
44
|
+
else
|
45
|
+
strip_functions!(v)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
elsif Hash === value
|
49
|
+
value.each do |k,v|
|
50
|
+
if MiniRacer::JavaScriptFunction === v
|
51
|
+
value.delete k
|
52
|
+
else
|
53
|
+
value[k] = strip_functions!(v)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
value
|
57
|
+
elsif MiniRacer::JavaScriptFunction === value
|
58
|
+
nil
|
59
|
+
else
|
60
|
+
value
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def translate
|
65
|
+
begin
|
66
|
+
strip_functions! yield
|
67
|
+
rescue MiniRacer::RuntimeError => e
|
68
|
+
ex = ProgramError.new e.message
|
69
|
+
if backtrace = e.backtrace
|
70
|
+
backtrace = backtrace.map { |line|
|
71
|
+
if line =~ /JavaScript at/
|
72
|
+
line.sub("JavaScript at ", "")
|
73
|
+
.sub("<anonymous>", "(execjs)")
|
74
|
+
.strip
|
75
|
+
else
|
76
|
+
line
|
77
|
+
end
|
78
|
+
}
|
79
|
+
ex.set_backtrace backtrace
|
80
|
+
end
|
81
|
+
raise ex
|
82
|
+
rescue MiniRacer::ParseError => e
|
83
|
+
ex = RuntimeError.new e.message
|
84
|
+
ex.set_backtrace(["(execjs):1"] + e.backtrace)
|
85
|
+
raise ex
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
def name
|
92
|
+
"mini_racer (V8)"
|
93
|
+
end
|
94
|
+
|
95
|
+
def available?
|
96
|
+
require "mini_racer"
|
97
|
+
true
|
98
|
+
rescue LoadError
|
99
|
+
false
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/execjs/module.rb
CHANGED
@@ -15,16 +15,16 @@ module ExecJS
|
|
15
15
|
@runtime = runtime
|
16
16
|
end
|
17
17
|
|
18
|
-
def exec(source)
|
19
|
-
runtime.exec(source)
|
18
|
+
def exec(source, options = {})
|
19
|
+
runtime.exec(source, options)
|
20
20
|
end
|
21
21
|
|
22
|
-
def eval(source)
|
23
|
-
runtime.eval(source)
|
22
|
+
def eval(source, options = {})
|
23
|
+
runtime.eval(source, options)
|
24
24
|
end
|
25
25
|
|
26
|
-
def compile(source)
|
27
|
-
runtime.compile(source)
|
26
|
+
def compile(source, options = {})
|
27
|
+
runtime.compile(source, options)
|
28
28
|
end
|
29
29
|
|
30
30
|
def root
|
@@ -3,7 +3,7 @@ require "execjs/runtime"
|
|
3
3
|
module ExecJS
|
4
4
|
class RubyRhinoRuntime < Runtime
|
5
5
|
class Context < Runtime::Context
|
6
|
-
def initialize(runtime, source = "")
|
6
|
+
def initialize(runtime, source = "", options = {})
|
7
7
|
source = encode(source)
|
8
8
|
|
9
9
|
@rhino_context = ::Rhino::Context.new
|
data/lib/execjs/runtime.rb
CHANGED
@@ -6,7 +6,7 @@ module ExecJS
|
|
6
6
|
class Context
|
7
7
|
include Encoding
|
8
8
|
|
9
|
-
def initialize(runtime, source = "")
|
9
|
+
def initialize(runtime, source = "", options = {})
|
10
10
|
end
|
11
11
|
|
12
12
|
def exec(source, options = {})
|
@@ -30,18 +30,32 @@ module ExecJS
|
|
30
30
|
self.class::Context
|
31
31
|
end
|
32
32
|
|
33
|
-
def exec(source)
|
34
|
-
context =
|
35
|
-
|
33
|
+
def exec(source, options = {})
|
34
|
+
context = compile("", options)
|
35
|
+
|
36
|
+
if context.method(:exec).arity == 1
|
37
|
+
context.exec(source)
|
38
|
+
else
|
39
|
+
context.exec(source, options)
|
40
|
+
end
|
36
41
|
end
|
37
42
|
|
38
|
-
def eval(source)
|
39
|
-
context =
|
40
|
-
|
43
|
+
def eval(source, options = {})
|
44
|
+
context = compile("", options)
|
45
|
+
|
46
|
+
if context.method(:eval).arity == 1
|
47
|
+
context.eval(source)
|
48
|
+
else
|
49
|
+
context.eval(source, options)
|
50
|
+
end
|
41
51
|
end
|
42
52
|
|
43
|
-
def compile(source)
|
44
|
-
context_class.
|
53
|
+
def compile(source, options = {})
|
54
|
+
if context_class.instance_method(:initialize).arity == 2
|
55
|
+
context_class.new(self, source)
|
56
|
+
else
|
57
|
+
context_class.new(self, source, options)
|
58
|
+
end
|
45
59
|
end
|
46
60
|
|
47
61
|
def deprecated?
|
data/lib/execjs/runtimes.rb
CHANGED
@@ -4,6 +4,7 @@ require "execjs/duktape_runtime"
|
|
4
4
|
require "execjs/external_runtime"
|
5
5
|
require "execjs/ruby_racer_runtime"
|
6
6
|
require "execjs/ruby_rhino_runtime"
|
7
|
+
require "execjs/mini_racer_runtime"
|
7
8
|
|
8
9
|
module ExecJS
|
9
10
|
module Runtimes
|
@@ -15,6 +16,8 @@ module ExecJS
|
|
15
16
|
|
16
17
|
RubyRhino = RubyRhinoRuntime.new
|
17
18
|
|
19
|
+
MiniRacer = MiniRacerRuntime.new
|
20
|
+
|
18
21
|
Node = ExternalRuntime.new(
|
19
22
|
name: "Node.js (V8)",
|
20
23
|
command: ["nodejs", "node"],
|
@@ -42,6 +45,13 @@ module ExecJS
|
|
42
45
|
encoding: 'UTF-16LE' # CScript with //U returns UTF-16LE
|
43
46
|
)
|
44
47
|
|
48
|
+
V8 = ExternalRuntime.new(
|
49
|
+
name: "V8",
|
50
|
+
command: "d8",
|
51
|
+
runner_path: ExecJS.root + "/support/v8_runner.js",
|
52
|
+
encoding: 'UTF-8'
|
53
|
+
)
|
54
|
+
|
45
55
|
|
46
56
|
def self.autodetect
|
47
57
|
from_environment || best_available ||
|
@@ -57,7 +67,7 @@ module ExecJS
|
|
57
67
|
if name = ENV["EXECJS_RUNTIME"]
|
58
68
|
raise RuntimeUnavailable, "#{name} runtime is not defined" unless const_defined?(name)
|
59
69
|
runtime = const_get(name)
|
60
|
-
|
70
|
+
|
61
71
|
raise RuntimeUnavailable, "#{runtime.name} runtime is not available on this system" unless runtime.available?
|
62
72
|
runtime
|
63
73
|
end
|
@@ -72,10 +82,12 @@ module ExecJS
|
|
72
82
|
RubyRacer,
|
73
83
|
RubyRhino,
|
74
84
|
Duktape,
|
75
|
-
|
85
|
+
MiniRacer,
|
76
86
|
Node,
|
87
|
+
JavaScriptCore,
|
77
88
|
SpiderMonkey,
|
78
|
-
JScript
|
89
|
+
JScript,
|
90
|
+
V8
|
79
91
|
]
|
80
92
|
end
|
81
93
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
(function(program, execJS) { execJS(program) })(function() { #{source}
|
2
|
+
}, function(program) {
|
3
|
+
var output;
|
4
|
+
try {
|
5
|
+
result = program();
|
6
|
+
if (typeof result == 'undefined' && result !== null) {
|
7
|
+
print('["ok"]');
|
8
|
+
} else {
|
9
|
+
try {
|
10
|
+
print(JSON.stringify(['ok', result]));
|
11
|
+
} catch (err) {
|
12
|
+
print(JSON.stringify(['err', '' + err, err.stack]));
|
13
|
+
}
|
14
|
+
}
|
15
|
+
} catch (err) {
|
16
|
+
print(JSON.stringify(['err', '' + err, err.stack]));
|
17
|
+
}
|
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.7.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:
|
12
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -33,13 +33,14 @@ executables: []
|
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
|
-
- LICENSE
|
36
|
+
- MIT-LICENSE
|
37
37
|
- README.md
|
38
38
|
- lib/execjs.rb
|
39
39
|
- lib/execjs/disabled_runtime.rb
|
40
40
|
- lib/execjs/duktape_runtime.rb
|
41
41
|
- lib/execjs/encoding.rb
|
42
42
|
- lib/execjs/external_runtime.rb
|
43
|
+
- lib/execjs/mini_racer_runtime.rb
|
43
44
|
- lib/execjs/module.rb
|
44
45
|
- lib/execjs/ruby_racer_runtime.rb
|
45
46
|
- lib/execjs/ruby_rhino_runtime.rb
|
@@ -50,6 +51,7 @@ files:
|
|
50
51
|
- lib/execjs/support/json2.js
|
51
52
|
- lib/execjs/support/node_runner.js
|
52
53
|
- lib/execjs/support/spidermonkey_runner.js
|
54
|
+
- lib/execjs/support/v8_runner.js
|
53
55
|
- lib/execjs/version.rb
|
54
56
|
homepage: https://github.com/rails/execjs
|
55
57
|
licenses:
|
@@ -71,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
73
|
version: '0'
|
72
74
|
requirements: []
|
73
75
|
rubyforge_project:
|
74
|
-
rubygems_version: 2.
|
76
|
+
rubygems_version: 2.5.1
|
75
77
|
signing_key:
|
76
78
|
specification_version: 4
|
77
79
|
summary: Run JavaScript code from Ruby
|