execjs 2.6.0 → 2.7.0

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
2
  SHA1:
3
- metadata.gz: fcd62eb19c4e6aea5d447da64320e784832ee043
4
- data.tar.gz: 687511bf72f60e9bc628beb0ff96b5ee0b69cee1
3
+ metadata.gz: c281240b821b63764b2972d440a39405d77bca30
4
+ data.tar.gz: f661c8d78fb1099bc3787e29c40b91b2e067be2e
5
5
  SHA512:
6
- metadata.gz: ccc7750f0aa82f25d94eec847a4316c3a2ede069e26dd9dc312fceae32661ca44ca71e6f84f7db51e3bd0036d4d6b6d30700c115f56f2a92483506664617a929
7
- data.tar.gz: 6a8890a15c433afc9f5de23b70852e0947b0bd694b8c195c6f2e573bcd57832b628f97a5e68ecf818a4972e438969e7fec1d0d826e3ae342d3805b0c9a7a750c
6
+ metadata.gz: d59815bb2b71498baa84e75f9ccdc5210e82a5dc474f22a1c9b749602eeee91a4e0844484e7580c05cee6dcfa94c6672b72e6e2133c23227e9d5011af3110632
7
+ data.tar.gz: e38d3bfdfe65de9017d2ba829e40646c98c931d9fae56f8aa39cb345ce5da3e39a4b1c7199fa79dc89609f56d8afae24427d22ef64f67fba092456f60e8f4632
@@ -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
- # License
79
+ ExecJS is work of hundreds of contributors. You're encouraged to submit pull requests, propose
80
+ features and discuss issues.
77
81
 
78
- Copyright (c) 2015 Sam Stephenson and Josh Peek.
82
+ See [CONTRIBUTING](CONTRIBUTING.md).
79
83
 
80
- Released under the MIT license. See `LICENSE` for details.
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
@@ -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
@@ -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 RubyRacerRuntime < 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
  lock do
@@ -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
@@ -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 = context_class.new(self)
35
- context.exec(source)
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 = context_class.new(self)
40
- context.eval(source)
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.new(self, source)
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?
@@ -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 ||
@@ -72,10 +82,12 @@ module ExecJS
72
82
  RubyRacer,
73
83
  RubyRhino,
74
84
  Duktape,
85
+ MiniRacer,
75
86
  Node,
76
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
+ });
@@ -1,3 +1,3 @@
1
1
  module ExecJS
2
- VERSION = "2.6.0"
2
+ VERSION = "2.7.0"
3
3
  end
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.6.0
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: 2015-08-14 00:00:00.000000000 Z
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,9 +73,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
73
  version: '0'
72
74
  requirements: []
73
75
  rubyforge_project:
74
- rubygems_version: 2.4.7
76
+ rubygems_version: 2.5.1
75
77
  signing_key:
76
78
  specification_version: 4
77
79
  summary: Run JavaScript code from Ruby
78
80
  test_files: []
79
- has_rdoc: