execjs 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,6 +45,10 @@ module ExecJS
45
45
  output.sub!('#{source}') do
46
46
  source
47
47
  end
48
+ output.sub!('#{encoded_source}') do
49
+ encoded_source = encode_unicode_codepoints(source)
50
+ MultiJson.encode("(function(){ #{encoded_source} })()")
51
+ end
48
52
  output.sub!('#{json2_source}') do
49
53
  IO.read(ExecJS.root + "/support/json2.js")
50
54
  end
@@ -55,10 +59,26 @@ module ExecJS
55
59
  status, value = output.empty? ? [] : MultiJson.decode(output)
56
60
  if status == "ok"
57
61
  value
62
+ elsif value == "SyntaxError: Parse error"
63
+ raise RuntimeError, value
58
64
  else
59
65
  raise ProgramError, value
60
66
  end
61
67
  end
68
+
69
+ if "".respond_to?(:codepoints)
70
+ def encode_unicode_codepoints(str)
71
+ str.gsub(/[\u0080-\uffff]/) do |ch|
72
+ "\\u%04x" % ch.codepoints.to_a
73
+ end
74
+ end
75
+ else
76
+ def encode_unicode_codepoints(str)
77
+ str.unpack("U*").map { |b|
78
+ b >= 128 ? "\\u%04x" % b : b.chr
79
+ }.join("")
80
+ end
81
+ end
62
82
  end
63
83
 
64
84
  attr_reader :name
@@ -69,7 +89,6 @@ module ExecJS
69
89
  @runner_path = options[:runner_path]
70
90
  @test_args = options[:test_args]
71
91
  @test_match = options[:test_match]
72
- @conversion = options[:conversion]
73
92
  @binary = locate_binary
74
93
  end
75
94
 
@@ -98,7 +117,8 @@ module ExecJS
98
117
  end
99
118
 
100
119
  def exec_runtime(filename)
101
- output = sh("#{@binary} #{filename} 2>&1")
120
+ output = nil
121
+ IO.popen("#{@binary} #{filename} 2>&1") { |f| output = f.read }
102
122
  if $?.success?
103
123
  output
104
124
  else
@@ -132,29 +152,5 @@ module ExecJS
132
152
  end
133
153
  nil
134
154
  end
135
-
136
- if "".respond_to?(:force_encoding)
137
- def sh(command)
138
- output, options = nil, {}
139
- options[:external_encoding] = 'UTF-8'
140
- options[:internal_encoding] = @conversion[:from] if @conversion
141
- IO.popen(command, options) { |f| output = f.read }
142
- output.force_encoding(@conversion[:to]) if @conversion
143
- output
144
- end
145
- else
146
- require "iconv"
147
-
148
- def sh(command)
149
- output = nil
150
- IO.popen(command) { |f| output = f.read }
151
-
152
- if @conversion
153
- Iconv.iconv(@conversion[:from], @conversion[:to], output).first
154
- else
155
- output
156
- end
157
- end
158
- end
159
155
  end
160
156
  end
@@ -7,7 +7,7 @@ module ExecJS
7
7
  end
8
8
 
9
9
  def exec(source, options = {})
10
- souce = source.encode('UTF-8') if source.respond_to?(:encode)
10
+ source = source.encode('UTF-8') if source.respond_to?(:encode)
11
11
 
12
12
  if /\S/ =~ source
13
13
  eval "(function(){#{source}})()", options
@@ -15,7 +15,7 @@ module ExecJS
15
15
  end
16
16
 
17
17
  def eval(source, options = {})
18
- souce = source.encode('UTF-8') if source.respond_to?(:encode)
18
+ source = source.encode('UTF-8') if source.respond_to?(:encode)
19
19
 
20
20
  if /\S/ =~ source
21
21
  unbox @runtime.evaluate("(#{source})")
@@ -42,14 +42,21 @@ module ExecJS
42
42
  end
43
43
 
44
44
  def unbox(value)
45
- case value
45
+ case value = ::Rhino::To.ruby(value)
46
46
  when ::Rhino::NativeFunction
47
47
  nil
48
48
  when ::Rhino::NativeObject
49
49
  value.inject({}) do |vs, (k, v)|
50
- vs[k] = unbox(v) unless v.is_a?(::Rhino::NativeFunction)
50
+ case v
51
+ when ::Rhino::NativeFunction, ::Rhino::J::Function
52
+ nil
53
+ else
54
+ vs[k] = unbox(v)
55
+ end
51
56
  vs
52
57
  end
58
+ when Array
59
+ value.map { |v| unbox(v) }
53
60
  else
54
61
  value
55
62
  end
@@ -24,8 +24,7 @@ module ExecJS
24
24
  JavaScriptCore = ExternalRuntime.new(
25
25
  :name => "JavaScriptCore",
26
26
  :command => "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc",
27
- :runner_path => ExecJS.root + "/support/basic_runner.js",
28
- :conversion => { :from => "ISO8859-1", :to => "UTF-8" }
27
+ :runner_path => ExecJS.root + "/support/jsc_runner.js"
29
28
  )
30
29
 
31
30
  SpiderMonkey = Spidermonkey = ExternalRuntime.new(
@@ -1,3 +1,3 @@
1
1
  module ExecJS
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
metadata CHANGED
@@ -1,113 +1,93 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: execjs
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 2
8
- - 1
9
- version: 1.2.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.2
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Sam Stephenson
13
9
  - Josh Peek
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2011-07-28 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2011-08-03 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: multi_json
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70354656032380 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
19
+ requirements:
27
20
  - - ~>
28
- - !ruby/object:Gem::Version
29
- segments:
30
- - 1
31
- - 0
32
- version: "1.0"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.0'
33
23
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: johnson
37
24
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *70354656032380
26
+ - !ruby/object:Gem::Dependency
27
+ name: johnson
28
+ requirement: &70354656031960 !ruby/object:Gem::Requirement
39
29
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- version: "0"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
46
34
  type: :development
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: mustang
50
35
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *70354656031960
37
+ - !ruby/object:Gem::Dependency
38
+ name: mustang
39
+ requirement: &70354656031500 !ruby/object:Gem::Requirement
52
40
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- segments:
57
- - 0
58
- version: "0"
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
59
45
  type: :development
60
- version_requirements: *id003
61
- - !ruby/object:Gem::Dependency
62
- name: rake
63
46
  prerelease: false
64
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *70354656031500
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: &70354656031080 !ruby/object:Gem::Requirement
65
51
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- segments:
70
- - 0
71
- version: "0"
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
72
56
  type: :development
73
- version_requirements: *id004
74
- - !ruby/object:Gem::Dependency
75
- name: therubyracer
76
57
  prerelease: false
77
- requirement: &id005 !ruby/object:Gem::Requirement
58
+ version_requirements: *70354656031080
59
+ - !ruby/object:Gem::Dependency
60
+ name: therubyracer
61
+ requirement: &70354656030660 !ruby/object:Gem::Requirement
78
62
  none: false
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- segments:
83
- - 0
84
- version: "0"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
85
67
  type: :development
86
- version_requirements: *id005
87
- - !ruby/object:Gem::Dependency
88
- name: therubyrhino
89
68
  prerelease: false
90
- requirement: &id006 !ruby/object:Gem::Requirement
69
+ version_requirements: *70354656030660
70
+ - !ruby/object:Gem::Dependency
71
+ name: therubyrhino
72
+ requirement: &70354656030240 !ruby/object:Gem::Requirement
91
73
  none: false
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- segments:
96
- - 0
97
- version: "0"
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
98
78
  type: :development
99
- version_requirements: *id006
100
- description: " ExecJS lets you run JavaScript code from Ruby.\n"
101
- email:
79
+ prerelease: false
80
+ version_requirements: *70354656030240
81
+ description: ! ' ExecJS lets you run JavaScript code from Ruby.
82
+
83
+ '
84
+ email:
102
85
  - sstephenson@gmail.com
103
86
  - josh@joshpeek.com
104
87
  executables: []
105
-
106
88
  extensions: []
107
-
108
89
  extra_rdoc_files: []
109
-
110
- files:
90
+ files:
111
91
  - lib/execjs.rb
112
92
  - lib/execjs/external_runtime.rb
113
93
  - lib/execjs/johnson_runtime.rb
@@ -124,37 +104,28 @@ files:
124
104
  - lib/execjs/support/which.bat
125
105
  - LICENSE
126
106
  - README.md
127
- has_rdoc: true
128
107
  homepage: https://github.com/sstephenson/execjs
129
108
  licenses: []
130
-
131
109
  post_install_message:
132
110
  rdoc_options: []
133
-
134
- require_paths:
111
+ require_paths:
135
112
  - lib
136
- required_ruby_version: !ruby/object:Gem::Requirement
113
+ required_ruby_version: !ruby/object:Gem::Requirement
137
114
  none: false
138
- requirements:
139
- - - ">="
140
- - !ruby/object:Gem::Version
141
- segments:
142
- - 0
143
- version: "0"
144
- required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
120
  none: false
146
- requirements:
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- segments:
150
- - 0
151
- version: "0"
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
152
125
  requirements: []
153
-
154
126
  rubyforge_project:
155
- rubygems_version: 1.3.7
127
+ rubygems_version: 1.8.6
156
128
  signing_key:
157
129
  specification_version: 3
158
130
  summary: Run JavaScript code from Ruby
159
131
  test_files: []
160
-