execjs 1.3.0 → 1.3.1

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.
@@ -1,3 +1,4 @@
1
+ require "multi_json"
1
2
  require "shellwords"
2
3
  require "tempfile"
3
4
 
@@ -15,7 +16,7 @@ module ExecJS
15
16
  source = source.encode('UTF-8') if source.respond_to?(:encode)
16
17
 
17
18
  if /\S/ =~ source
18
- exec("return eval(#{MultiJson.encode("(#{source})")})")
19
+ exec("return eval(#{json_encode("(#{source})")})")
19
20
  end
20
21
  end
21
22
 
@@ -29,7 +30,7 @@ module ExecJS
29
30
  end
30
31
 
31
32
  def call(identifier, *args)
32
- eval "#{identifier}.apply(this, #{MultiJson.encode(args)})"
33
+ eval "#{identifier}.apply(this, #{json_encode(args)})"
33
34
  end
34
35
 
35
36
  protected
@@ -49,7 +50,7 @@ module ExecJS
49
50
  end
50
51
  output.sub!('#{encoded_source}') do
51
52
  encoded_source = encode_unicode_codepoints(source)
52
- MultiJson.encode("(function(){ #{encoded_source} })()")
53
+ json_encode("(function(){ #{encoded_source} })()")
53
54
  end
54
55
  output.sub!('#{json2_source}') do
55
56
  IO.read(ExecJS.root + "/support/json2.js")
@@ -58,7 +59,7 @@ module ExecJS
58
59
  end
59
60
 
60
61
  def extract_result(output)
61
- status, value = output.empty? ? [] : MultiJson.decode(output)
62
+ status, value = output.empty? ? [] : json_decode(output)
62
63
  if status == "ok"
63
64
  value
64
65
  elsif value =~ /SyntaxError:/
@@ -83,6 +84,26 @@ module ExecJS
83
84
  end
84
85
  end
85
86
  end
87
+
88
+ if MultiJson.respond_to?(:load)
89
+ def json_decode(obj)
90
+ MultiJson.load(obj)
91
+ end
92
+ else
93
+ def json_decode(obj)
94
+ MultiJson.decode(obj)
95
+ end
96
+ end
97
+
98
+ if MultiJson.respond_to?(:dump)
99
+ def json_encode(obj)
100
+ MultiJson.dump(obj)
101
+ end
102
+ else
103
+ def json_encode(obj)
104
+ MultiJson.encode(obj)
105
+ end
106
+ end
86
107
  end
87
108
 
88
109
  attr_reader :name
@@ -112,7 +133,6 @@ module ExecJS
112
133
  end
113
134
 
114
135
  def available?
115
- require "multi_json"
116
136
  binary ? true : false
117
137
  end
118
138
 
@@ -1,3 +1,3 @@
1
1
  module ExecJS
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: execjs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 0
10
- version: 1.3.0
9
+ - 1
10
+ version: 1.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Stephenson
@@ -16,8 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-01-19 00:00:00 -08:00
20
- default_executable:
19
+ date: 2012-04-26 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: multi_json
@@ -132,7 +131,6 @@ files:
132
131
  - lib/execjs/support/spidermonkey_runner.js
133
132
  - lib/execjs/version.rb
134
133
  - lib/execjs.rb
135
- has_rdoc: true
136
134
  homepage: https://github.com/sstephenson/execjs
137
135
  licenses: []
138
136
 
@@ -162,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
160
  requirements: []
163
161
 
164
162
  rubyforge_project:
165
- rubygems_version: 1.6.2
163
+ rubygems_version: 1.8.15
166
164
  signing_key:
167
165
  specification_version: 3
168
166
  summary: Run JavaScript code from Ruby