execjs 2.0.2 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa9a93a77554f102fc5a3e16c26d5b305c573ffb
4
- data.tar.gz: 072920c3b99406ac62c0e6aec41a03ef62ecbf31
3
+ metadata.gz: 021a19b46b741b3d85475f23e28ab2fcaa92f7fb
4
+ data.tar.gz: 7f284ac676523a23cff15992506f53e4538d0760
5
5
  SHA512:
6
- metadata.gz: 8f1a9db146000f618fb57bc2af26b2da6e0f6073fa783b9d6984fb00040254a0ef67b6227eb687010a231488a1529801fd22cd8b76974a822606db6da43a4945
7
- data.tar.gz: 6615b7125a6c6c3e8bd0b436a2d033090d9248db4c63972d1228b673dac43fcf130f93f5c01bd49f1077ba0a28bc4d0f24f2528674f7f7a905409769eb0a2511
6
+ metadata.gz: c77ce889ab7f9e871bc56d22ab505b0d175500b8dfd987fec7ba099b1211bae1d933a3001937f9d9d2285f3bc9bcfae37c8c02670e0af2d89392273b454720c2
7
+ data.tar.gz: 59748635e20cbe379fe90e7ab229fa9ac3a563f472ea31ce676e03791b721734a1c30ce092a986ae60d522d38c1242dd7dc397025f70eda85494ca0d76f97d40
data/LICENSE CHANGED
@@ -1,5 +1,5 @@
1
- Copyright (c) 2013 Sam Stephenson
2
- Copyright (c) 2013 Josh Peek
1
+ Copyright (c) 2014 Sam Stephenson
2
+ Copyright (c) 2014 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
@@ -17,26 +17,44 @@ ExecJS supports these runtimes:
17
17
 
18
18
  A short example:
19
19
 
20
- require "execjs"
21
- ExecJS.eval "'red yellow blue'.split(' ')"
22
- # => ["red", "yellow", "blue"]
20
+ ``` ruby
21
+ require "execjs"
22
+ ExecJS.eval "'red yellow blue'.split(' ')"
23
+ # => ["red", "yellow", "blue"]
24
+ ```
23
25
 
24
26
  A longer example, demonstrating how to invoke the CoffeeScript compiler:
25
27
 
26
- require "execjs"
27
- require "open-uri"
28
- source = open("http://jashkenas.github.com/coffee-script/extras/coffee-script.js").read
28
+ ``` ruby
29
+ require "execjs"
30
+ require "open-uri"
31
+ source = open("http://coffeescript.org/extras/coffee-script.js").read
29
32
 
30
- context = ExecJS.compile(source)
31
- context.call("CoffeeScript.compile", "square = (x) -> x * x", :bare => true)
32
- # => "var square;\nsquare = function(x) {\n return x * x;\n};"
33
+ context = ExecJS.compile(source)
34
+ context.call("CoffeeScript.compile", "square = (x) -> x * x", bare: true)
35
+ # => "var square;\nsquare = function(x) {\n return x * x;\n};"
36
+ ```
33
37
 
34
38
  # Installation
35
39
 
36
- $ gem install execjs
40
+ ```
41
+ $ gem install execjs
42
+ ```
43
+
44
+
45
+ # FAQ
46
+
47
+ **Why can't I use CommonJS `require()` inside ExecJS?**
48
+
49
+ ExecJS provides a lowest common denominator interface to any JavaScript runtime.
50
+ Use ExecJS when it doesn't matter which JavaScript interpreter your code runs
51
+ in. If you want to access the Node API, you should check another library like
52
+ [commonjs.rb](https://github.com/cowboyd/commonjs.rb) designed to provide a
53
+ consistent interface.
54
+
37
55
 
38
56
  # License
39
57
 
40
- Copyright (c) 2013 Sam Stephenson and Josh Peek.
58
+ Copyright (c) 2014 Sam Stephenson and Josh Peek.
41
59
 
42
60
  Released under the MIT license. See `LICENSE` for details.
@@ -1,32 +1,25 @@
1
1
  module ExecJS
2
2
  # Encodes strings as UTF-8
3
3
  module Encoding
4
- if "".respond_to?(:encode)
5
- if RUBY_ENGINE == 'jruby' || RUBY_ENGINE == 'rbx'
6
- # workaround for jruby bug http://jira.codehaus.org/browse/JRUBY-6588
7
- # workaround for rbx bug https://github.com/rubinius/rubinius/issues/1729
8
- def encode(string)
9
- if string.encoding.name == 'ASCII-8BIT'
10
- data = string.dup
11
- data.force_encoding('UTF-8')
4
+ if RUBY_ENGINE == 'jruby' || RUBY_ENGINE == 'rbx'
5
+ # workaround for jruby bug http://jira.codehaus.org/browse/JRUBY-6588
6
+ # workaround for rbx bug https://github.com/rubinius/rubinius/issues/1729
7
+ def encode(string)
8
+ if string.encoding.name == 'ASCII-8BIT'
9
+ data = string.dup
10
+ data.force_encoding('UTF-8')
12
11
 
13
- unless data.valid_encoding?
14
- raise ::Encoding::UndefinedConversionError, "Could not encode ASCII-8BIT data #{string.dump} as UTF-8"
15
- end
16
- else
17
- data = string.encode('UTF-8')
12
+ unless data.valid_encoding?
13
+ raise ::Encoding::UndefinedConversionError, "Could not encode ASCII-8BIT data #{string.dump} as UTF-8"
18
14
  end
19
- data
20
- end
21
- else
22
- def encode(string)
23
- string.encode('UTF-8')
15
+ else
16
+ data = string.encode('UTF-8')
24
17
  end
18
+ data
25
19
  end
26
20
  else
27
- # Define no-op on 1.8
28
21
  def encode(string)
29
- string
22
+ string.encode('UTF-8')
30
23
  end
31
24
  end
32
25
  end
@@ -1,4 +1,3 @@
1
- require "shellwords"
2
1
  require "tempfile"
3
2
  require "execjs/runtime"
4
3
 
@@ -16,7 +15,7 @@ module ExecJS
16
15
  source = encode(source)
17
16
 
18
17
  if /\S/ =~ source
19
- exec("return eval(#{::JSON.generate("(#{source})", :quirks_mode => true)})")
18
+ exec("return eval(#{::JSON.generate("(#{source})", quirks_mode: true)})")
20
19
  end
21
20
  end
22
21
 
@@ -50,7 +49,7 @@ module ExecJS
50
49
  end
51
50
  output.sub!('#{encoded_source}') do
52
51
  encoded_source = encode_unicode_codepoints(source)
53
- ::JSON.generate("(function(){ #{encoded_source} })()", :quirks_mode => true)
52
+ ::JSON.generate("(function(){ #{encoded_source} })()", quirks_mode: true)
54
53
  end
55
54
  output.sub!('#{json2_source}') do
56
55
  IO.read(ExecJS.root + "/support/json2.js")
@@ -59,7 +58,7 @@ module ExecJS
59
58
  end
60
59
 
61
60
  def extract_result(output)
62
- status, value = output.empty? ? [] : ::JSON.parse(output, :create_additions => false)
61
+ status, value = output.empty? ? [] : ::JSON.parse(output, create_additions: false)
63
62
  if status == "ok"
64
63
  value
65
64
  elsif value =~ /SyntaxError:/
@@ -69,19 +68,9 @@ module ExecJS
69
68
  end
70
69
  end
71
70
 
72
- if "".respond_to?(:codepoints)
73
- def encode_unicode_codepoints(str)
74
- str.gsub(/[\u0080-\uffff]/) do |ch|
75
- "\\u%04x" % ch.codepoints.to_a
76
- end
77
- end
78
- else
79
- def encode_unicode_codepoints(str)
80
- str.gsub(/([\xC0-\xDF][\x80-\xBF]|
81
- [\xE0-\xEF][\x80-\xBF]{2}|
82
- [\xF0-\xF7][\x80-\xBF]{3})+/nx) do |ch|
83
- "\\u%04x" % ch.unpack("U*")
84
- end
71
+ def encode_unicode_codepoints(str)
72
+ str.gsub(/[\u0080-\uffff]/) do |ch|
73
+ "\\u%04x" % ch.codepoints.to_a
85
74
  end
86
75
  end
87
76
  end
@@ -92,8 +81,6 @@ module ExecJS
92
81
  @name = options[:name]
93
82
  @command = options[:command]
94
83
  @runner_path = options[:runner_path]
95
- @test_args = options[:test_args]
96
- @test_match = options[:test_match]
97
84
  @encoding = options[:encoding]
98
85
  @deprecated = !!options[:deprecated]
99
86
  @binary = nil
@@ -110,7 +97,7 @@ module ExecJS
110
97
 
111
98
  private
112
99
  def binary
113
- @binary ||= locate_binary
100
+ @binary ||= which(@command)
114
101
  end
115
102
 
116
103
  def locate_executable(cmd)
@@ -135,7 +122,7 @@ module ExecJS
135
122
  end
136
123
 
137
124
  def exec_runtime(filename)
138
- output = sh("#{shell_escape(*(binary.split(' ') << filename))} 2>&1")
125
+ output = sh(binary.split(' ') + [filename, {err: [:child, :out]}])
139
126
  if $?.success?
140
127
  output
141
128
  else
@@ -143,17 +130,6 @@ module ExecJS
143
130
  end
144
131
  end
145
132
 
146
- def locate_binary
147
- if binary = which(@command)
148
- if @test_args
149
- output = `#{shell_escape(binary, @test_args)} 2>&1`
150
- binary if output.match(@test_match)
151
- else
152
- binary
153
- end
154
- end
155
- end
156
-
157
133
  def which(command)
158
134
  Array(command).find do |name|
159
135
  name, args = name.split(/\s+/, 2)
@@ -165,41 +141,12 @@ module ExecJS
165
141
  end
166
142
  end
167
143
 
168
- if "".respond_to?(:force_encoding)
169
- def sh(command)
170
- output, options = nil, {}
171
- options[:external_encoding] = @encoding if @encoding
172
- options[:internal_encoding] = ::Encoding.default_internal || 'UTF-8'
173
- IO.popen(command, options) { |f| output = f.read }
174
- output
175
- end
176
- else
177
- require "iconv"
178
-
179
- def sh(command)
180
- output = nil
181
- IO.popen(command) { |f| output = f.read }
182
-
183
- if @encoding
184
- Iconv.new('UTF-8', @encoding).iconv(output)
185
- else
186
- output
187
- end
188
- end
189
- end
190
-
191
- if ExecJS.windows?
192
- def shell_escape(*args)
193
- # see http://technet.microsoft.com/en-us/library/cc723564.aspx#XSLTsection123121120120
194
- args.map { |arg|
195
- arg = %Q("#{arg.gsub('"','""')}") if arg.match(/[&|()<>^ "]/)
196
- arg
197
- }.join(" ")
198
- end
199
- else
200
- def shell_escape(*args)
201
- Shellwords.join(args)
202
- end
144
+ def sh(command)
145
+ output, options = nil, {}
146
+ options[:external_encoding] = @encoding if @encoding
147
+ options[:internal_encoding] = ::Encoding.default_internal || 'UTF-8'
148
+ IO.popen(command, options) { |f| output = f.read }
149
+ output
203
150
  end
204
151
  end
205
152
  end
@@ -47,9 +47,7 @@ module ExecJS
47
47
  when function?(value)
48
48
  nil
49
49
  when string?(value)
50
- value.respond_to?(:force_encoding) ?
51
- value.force_encoding('UTF-8') :
52
- value
50
+ value.force_encoding('UTF-8')
53
51
  when array?(value)
54
52
  value.map { |v| unbox(v) }
55
53
  when object?(value)
@@ -64,9 +64,7 @@ module ExecJS
64
64
  vs
65
65
  end
66
66
  when String
67
- value.respond_to?(:force_encoding) ?
68
- value.force_encoding('UTF-8') :
69
- value
67
+ value.force_encoding('UTF-8')
70
68
  else
71
69
  value
72
70
  end
@@ -19,30 +19,30 @@ module ExecJS
19
19
  Mustang = MustangRuntime.new
20
20
 
21
21
  Node = ExternalRuntime.new(
22
- :name => "Node.js (V8)",
23
- :command => ["nodejs", "node"],
24
- :runner_path => ExecJS.root + "/support/node_runner.js",
25
- :encoding => 'UTF-8'
22
+ name: "Node.js (V8)",
23
+ command: ["nodejs", "node"],
24
+ runner_path: ExecJS.root + "/support/node_runner.js",
25
+ encoding: 'UTF-8'
26
26
  )
27
27
 
28
28
  JavaScriptCore = ExternalRuntime.new(
29
- :name => "JavaScriptCore",
30
- :command => "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc",
31
- :runner_path => ExecJS.root + "/support/jsc_runner.js"
29
+ name: "JavaScriptCore",
30
+ command: "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc",
31
+ runner_path: ExecJS.root + "/support/jsc_runner.js"
32
32
  )
33
33
 
34
34
  SpiderMonkey = Spidermonkey = ExternalRuntime.new(
35
- :name => "SpiderMonkey",
36
- :command => "js",
37
- :runner_path => ExecJS.root + "/support/spidermonkey_runner.js",
38
- :deprecated => true
35
+ name: "SpiderMonkey",
36
+ command: "js",
37
+ runner_path: ExecJS.root + "/support/spidermonkey_runner.js",
38
+ deprecated: true
39
39
  )
40
40
 
41
41
  JScript = ExternalRuntime.new(
42
- :name => "JScript",
43
- :command => "cscript //E:jscript //Nologo //U",
44
- :runner_path => ExecJS.root + "/support/jscript_runner.js",
45
- :encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE
42
+ name: "JScript",
43
+ command: "cscript //E:jscript //Nologo //U",
44
+ runner_path: ExecJS.root + "/support/jscript_runner.js",
45
+ encoding: 'UTF-16LE' # CScript with //U returns UTF-16LE
46
46
  )
47
47
 
48
48
 
@@ -1,3 +1,3 @@
1
1
  module ExecJS
2
- VERSION = "2.0.2"
2
+ VERSION = "2.1.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.0.2
4
+ version: 2.1.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: 2013-09-27 00:00:00.000000000 Z
12
+ date: 2014-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake