execjs 2.7.0 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c281240b821b63764b2972d440a39405d77bca30
4
- data.tar.gz: f661c8d78fb1099bc3787e29c40b91b2e067be2e
2
+ SHA256:
3
+ metadata.gz: 6bd129488d607b71ba6aec4c087036583727f4114d632107be2297b96a6a20f2
4
+ data.tar.gz: fea27c5987305700a3c5adbbe8f2e282dc5d49e6c579d2c91369886739342c26
5
5
  SHA512:
6
- metadata.gz: d59815bb2b71498baa84e75f9ccdc5210e82a5dc474f22a1c9b749602eeee91a4e0844484e7580c05cee6dcfa94c6672b72e6e2133c23227e9d5011af3110632
7
- data.tar.gz: e38d3bfdfe65de9017d2ba829e40646c98c931d9fae56f8aa39cb345ce5da3e39a4b1c7199fa79dc89609f56d8afae24427d22ef64f67fba092456f60e8f4632
6
+ metadata.gz: 99fe4da9a1203aa378e4f73879db38d7f9737dedc92141c820e099229eac5d00e311ab56379d5a92ef41fa1323cedf2614ee2e971e0e5602096f30732aed1808
7
+ data.tar.gz: df6fb1647179df49bef56c5570fbc7148bfa1e290945e398482e369572764b60c1293c2220c6e3101d6bd9880d47d4084f2b1325c5f39d321a186ef4ec2ac639
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 hundreds of contributors. You're encouraged to submit pull requests, propose
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.call_prop(identifier.split("."), *args)
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', @popen_options) { |f| f.read }
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, @popen_options)
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
 
@@ -6,6 +6,7 @@ module ExecJS
6
6
  def initialize(runtime, source = "", options={})
7
7
  source = encode(source)
8
8
  @context = ::MiniRacer::Context.new
9
+ @context.eval("delete this.console");
9
10
  translate do
10
11
  @context.eval(source)
11
12
  end
@@ -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
- def call(properties, *args)
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
@@ -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: ["nodejs", "node"],
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: "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc",
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
- if name = ENV["EXECJS_RUNTIME"]
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,
@@ -2,6 +2,7 @@
2
2
  }, function(program) {
3
3
  var output;
4
4
  try {
5
+ delete this.console;
5
6
  result = program();
6
7
  if (typeof result == 'undefined' && result !== null) {
7
8
  print('["ok"]');
@@ -1,20 +1,34 @@
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
- var output, print = function(string) {
4
- process.stdout.write('' + string);
3
+ var __process__ = process;
4
+
5
+ var printFinal = function(string) {
6
+ process.stdout.write('' + string, function() {
7
+ __process__.exit(0);
8
+ });
5
9
  };
6
10
  try {
11
+ delete this.process;
12
+ delete this.console;
13
+ delete this.setTimeout;
14
+ delete this.setInterval;
15
+ delete this.clearTimeout;
16
+ delete this.clearInterval;
17
+ delete this.setImmediate;
18
+ delete this.clearImmediate;
7
19
  result = program();
20
+ this.process = __process__;
8
21
  if (typeof result == 'undefined' && result !== null) {
9
- print('["ok"]');
22
+ printFinal('["ok"]');
10
23
  } else {
11
24
  try {
12
- print(JSON.stringify(['ok', result]));
25
+ printFinal(JSON.stringify(['ok', result]));
13
26
  } catch (err) {
14
- print(JSON.stringify(['err', '' + err, err.stack]));
27
+ printFinal(JSON.stringify(['err', '' + err, err.stack]));
15
28
  }
16
29
  }
17
30
  } catch (err) {
18
- print(JSON.stringify(['err', '' + err, err.stack]));
31
+ this.process = __process__;
32
+ printFinal(JSON.stringify(['err', '' + err, err.stack]));
19
33
  }
20
34
  });
@@ -1,3 +1,3 @@
1
1
  module ExecJS
2
- VERSION = "2.7.0"
2
+ VERSION = "2.8.1"
3
3
  end
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.7.0
4
+ version: 2.8.1
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: 2016-05-20 00:00:00.000000000 Z
12
+ date: 2021-05-14 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
- rubyforge_project:
76
- rubygems_version: 2.5.1
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