opal 0.6.3 → 0.7.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.spectator +2 -0
  4. data/.spectator-mspec +3 -0
  5. data/.travis.yml +8 -11
  6. data/CHANGELOG.md +33 -0
  7. data/CONTRIBUTING.md +8 -43
  8. data/Gemfile +15 -4
  9. data/Guardfile +77 -0
  10. data/README.md +15 -9
  11. data/Rakefile +36 -12
  12. data/benchmarks/operators.rb +11 -0
  13. data/bin/opal +10 -13
  14. data/bin/opal-build +4 -4
  15. data/bin/opal-mspec +10 -0
  16. data/bin/opal-repl +4 -3
  17. data/examples/sinatra/Gemfile +1 -1
  18. data/examples/sinatra/config.ru +3 -3
  19. data/lib/mspec/opal/main.rb.erb +2 -2
  20. data/lib/mspec/opal/rake_task.rb +31 -24
  21. data/lib/mspec/opal/runner.rb +18 -1
  22. data/lib/mspec/opal/sprockets.js +17 -0
  23. data/lib/opal.rb +1 -34
  24. data/lib/opal/builder.rb +92 -58
  25. data/lib/opal/builder_processors.rb +165 -0
  26. data/lib/opal/cli.rb +85 -144
  27. data/lib/opal/cli_options.rb +136 -90
  28. data/lib/opal/cli_runners.rb +10 -0
  29. data/lib/opal/cli_runners/nodejs.rb +56 -0
  30. data/lib/opal/cli_runners/phantom.js +35 -0
  31. data/lib/opal/cli_runners/phantomjs.rb +28 -0
  32. data/lib/opal/cli_runners/server.rb +54 -0
  33. data/lib/opal/compiler.rb +35 -16
  34. data/lib/opal/erb.rb +29 -15
  35. data/lib/opal/hike_path_finder.rb +18 -0
  36. data/lib/opal/nodes.rb +1 -0
  37. data/lib/opal/nodes/call.rb +107 -26
  38. data/lib/opal/nodes/call_special.rb +31 -6
  39. data/lib/opal/nodes/class.rb +2 -2
  40. data/lib/opal/nodes/constants.rb +5 -20
  41. data/lib/opal/nodes/def.rb +4 -4
  42. data/lib/opal/nodes/defined.rb +3 -3
  43. data/lib/opal/nodes/definitions.rb +1 -1
  44. data/lib/opal/nodes/for.rb +35 -0
  45. data/lib/opal/nodes/helpers.rb +2 -2
  46. data/lib/opal/nodes/iter.rb +3 -3
  47. data/lib/opal/nodes/literal.rb +10 -2
  48. data/lib/opal/nodes/masgn.rb +2 -2
  49. data/lib/opal/nodes/module.rb +2 -2
  50. data/lib/opal/nodes/scope.rb +1 -0
  51. data/lib/opal/nodes/singleton_class.rb +2 -2
  52. data/lib/opal/nodes/super.rb +2 -2
  53. data/lib/opal/nodes/top.rb +30 -3
  54. data/lib/opal/parser.rb +15 -1
  55. data/lib/opal/parser/grammar.rb +2571 -2452
  56. data/lib/opal/parser/grammar.y +37 -5
  57. data/lib/opal/parser/keywords.rb +2 -0
  58. data/lib/opal/parser/lexer.rb +21 -11
  59. data/lib/opal/path_reader.rb +28 -0
  60. data/lib/opal/paths.rb +38 -0
  61. data/lib/opal/source_map.rb +32 -15
  62. data/lib/opal/sprockets/environment.rb +9 -2
  63. data/lib/opal/sprockets/erb.rb +1 -2
  64. data/lib/opal/sprockets/path_reader.rb +34 -0
  65. data/lib/opal/sprockets/processor.rb +40 -39
  66. data/lib/opal/sprockets/server.rb +47 -33
  67. data/lib/opal/version.rb +1 -1
  68. data/opal.gemspec +10 -5
  69. data/opal/README.md +6 -0
  70. data/opal/corelib/array.rb +36 -4
  71. data/opal/corelib/array/inheritance.rb +6 -6
  72. data/opal/corelib/basic_object.rb +9 -9
  73. data/opal/corelib/boolean.rb +1 -1
  74. data/opal/corelib/class.rb +12 -12
  75. data/opal/corelib/dir.rb +20 -0
  76. data/opal/corelib/enumerable.rb +42 -42
  77. data/opal/corelib/enumerator.rb +1 -1
  78. data/opal/corelib/error.rb +2 -2
  79. data/opal/corelib/file.rb +56 -0
  80. data/opal/corelib/hash.rb +5 -5
  81. data/opal/corelib/helpers.rb +3 -3
  82. data/opal/corelib/io.rb +13 -10
  83. data/opal/corelib/kernel.rb +44 -68
  84. data/opal/corelib/method.rb +1 -1
  85. data/opal/corelib/module.rb +89 -114
  86. data/opal/corelib/nil_class.rb +1 -1
  87. data/opal/corelib/numeric.rb +27 -23
  88. data/opal/corelib/proc.rb +5 -5
  89. data/opal/corelib/range.rb +8 -4
  90. data/opal/corelib/regexp.rb +5 -5
  91. data/opal/corelib/runtime.js +589 -272
  92. data/opal/corelib/string.rb +52 -37
  93. data/opal/corelib/string/inheritance.rb +5 -5
  94. data/opal/corelib/time.rb +102 -52
  95. data/opal/corelib/variables.rb +3 -3
  96. data/opal/opal.rb +2 -0
  97. data/package.json +9 -0
  98. data/spec/filters/bugs/array.rb +0 -6
  99. data/spec/filters/bugs/language.rb +4 -0
  100. data/spec/filters/bugs/numeric.rb +7 -6
  101. data/spec/filters/bugs/opal.rb +2 -0
  102. data/spec/filters/bugs/regexp.rb +4 -0
  103. data/spec/filters/bugs/string.rb +0 -7
  104. data/spec/filters/bugs/stringscanner.rb +4 -1
  105. data/spec/filters/unsupported/private_methods.rb +2 -0
  106. data/spec/lib/builder_processors_spec.rb +27 -0
  107. data/spec/lib/builder_spec.rb +66 -0
  108. data/spec/{cli → lib}/cli_spec.rb +60 -5
  109. data/spec/{cli → lib}/compiler_spec.rb +66 -5
  110. data/spec/{cli → lib}/dependency_resolver_spec.rb +1 -1
  111. data/spec/lib/fixtures/no_requires.rb +1 -0
  112. data/spec/{cli → lib}/fixtures/opal_file.rb +0 -0
  113. data/spec/lib/fixtures/require_tree_test.rb +3 -0
  114. data/spec/lib/fixtures/required_tree_test/required_file1.rb +1 -0
  115. data/spec/lib/fixtures/required_tree_test/required_file2.rb +1 -0
  116. data/spec/lib/fixtures/requires.rb +7 -0
  117. data/spec/{cli → lib}/fixtures/sprockets_file.js.rb +0 -0
  118. data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
  119. data/spec/lib/hike_path_finder_spec.rb +23 -0
  120. data/spec/{cli → lib}/lexer_spec.rb +1 -1
  121. data/spec/{cli → lib}/parser/alias_spec.rb +1 -1
  122. data/spec/{cli → lib}/parser/and_spec.rb +1 -1
  123. data/spec/{cli → lib}/parser/attrasgn_spec.rb +1 -1
  124. data/spec/{cli → lib}/parser/begin_spec.rb +1 -1
  125. data/spec/{cli → lib}/parser/block_spec.rb +1 -1
  126. data/spec/{cli → lib}/parser/break_spec.rb +1 -1
  127. data/spec/{cli → lib}/parser/call_spec.rb +1 -1
  128. data/spec/{cli → lib}/parser/class_spec.rb +1 -1
  129. data/spec/{cli → lib}/parser/comments_spec.rb +1 -1
  130. data/spec/{cli → lib}/parser/def_spec.rb +1 -1
  131. data/spec/{cli → lib}/parser/if_spec.rb +1 -1
  132. data/spec/{cli → lib}/parser/iter_spec.rb +1 -1
  133. data/spec/{cli → lib}/parser/lambda_spec.rb +1 -1
  134. data/spec/{cli → lib}/parser/literal_spec.rb +1 -1
  135. data/spec/{cli → lib}/parser/masgn_spec.rb +1 -1
  136. data/spec/{cli → lib}/parser/module_spec.rb +1 -1
  137. data/spec/{cli → lib}/parser/not_spec.rb +1 -1
  138. data/spec/{cli → lib}/parser/op_asgn1_spec.rb +1 -1
  139. data/spec/{cli → lib}/parser/op_asgn2_spec.rb +1 -1
  140. data/spec/{cli → lib}/parser/or_spec.rb +1 -1
  141. data/spec/{cli → lib}/parser/return_spec.rb +1 -1
  142. data/spec/{cli → lib}/parser/sclass_spec.rb +1 -1
  143. data/spec/{cli → lib}/parser/string_spec.rb +8 -1
  144. data/spec/{cli → lib}/parser/super_spec.rb +1 -1
  145. data/spec/lib/parser/unary_spec.rb +48 -0
  146. data/spec/{cli → lib}/parser/undef_spec.rb +1 -1
  147. data/spec/{cli → lib}/parser/unless_spec.rb +1 -1
  148. data/spec/{cli → lib}/parser/variables_spec.rb +1 -1
  149. data/spec/{cli → lib}/parser/while_spec.rb +1 -1
  150. data/spec/{cli → lib}/parser/yield_spec.rb +1 -1
  151. data/spec/lib/path_reader_spec.rb +24 -0
  152. data/spec/lib/shared/path_finder_shared.rb +19 -0
  153. data/spec/lib/shared/path_reader_shared.rb +31 -0
  154. data/spec/lib/spec_helper.rb +9 -0
  155. data/spec/lib/sprockets/environment_spec.rb +30 -0
  156. data/spec/{cli → lib}/sprockets/erb_spec.rb +1 -1
  157. data/spec/lib/sprockets/path_reader_spec.rb +25 -0
  158. data/spec/{cli → lib}/sprockets/processor_spec.rb +9 -2
  159. data/spec/lib/sprockets/server_spec.rb +20 -0
  160. data/spec/opal/compiler/irb_spec.rb +11 -11
  161. data/spec/opal/core/fixtures/require_tree_files/file 1.rb +1 -0
  162. data/spec/opal/core/fixtures/require_tree_files/file 2.rb +1 -0
  163. data/spec/opal/core/fixtures/require_tree_files/file 3.rb +1 -0
  164. data/spec/opal/core/fixtures/require_tree_files/file 4.rb +1 -0
  165. data/spec/opal/core/fixtures/require_tree_files/file 5.rb +1 -0
  166. data/spec/opal/core/kernel/require_tree_spec.rb +7 -0
  167. data/spec/opal/core/kernel/respond_to_spec.rb +2 -2
  168. data/spec/opal/core/runtime/method_missing_spec.rb +19 -0
  169. data/spec/opal/core/source_map_spec.rb +2 -2
  170. data/spec/opal/core/string_spec.rb +11 -0
  171. data/spec/opal/stdlib/erb/erb_spec.rb +0 -1
  172. data/spec/opal/stdlib/thread/mutex_spec.rb +40 -0
  173. data/spec/opal/stdlib/thread/thread_queue_spec.rb +32 -0
  174. data/spec/opal/stdlib/thread/thread_spec.rb +60 -0
  175. data/spec/rubyspecs +54 -11
  176. data/spec/spec_helper.rb +18 -3
  177. data/spec/support/mspec_rspec_adapter.rb +33 -0
  178. data/spec/{cli/spec_helper.rb → support/parser_helpers.rb} +10 -10
  179. data/stdlib/README.md +3 -0
  180. data/stdlib/benchmark.rb +10 -0
  181. data/stdlib/date.rb +2 -2
  182. data/stdlib/dir.rb +1 -5
  183. data/stdlib/file.rb +1 -7
  184. data/stdlib/json.rb +10 -1
  185. data/stdlib/native.rb +5 -5
  186. data/stdlib/nodejs.rb +5 -0
  187. data/stdlib/nodejs/dir.rb +13 -0
  188. data/stdlib/nodejs/file.rb +98 -0
  189. data/stdlib/nodejs/fileutils.rb +26 -0
  190. data/stdlib/nodejs/io.rb +2 -0
  191. data/stdlib/nodejs/irb.rb +45 -0
  192. data/stdlib/nodejs/process.rb +16 -0
  193. data/stdlib/nodejs/require.rb +32 -0
  194. data/stdlib/nodejs/rubygems.rb +68 -0
  195. data/stdlib/nodejs/runtime.rb +25 -0
  196. data/stdlib/nodejs/yaml.rb +11 -0
  197. data/stdlib/opal-parser.rb +1 -2
  198. data/stdlib/opal-source-maps.rb +2 -0
  199. data/stdlib/phantomjs.rb +8 -0
  200. data/stdlib/process.rb +10 -0
  201. data/stdlib/promise.rb +12 -4
  202. data/stdlib/set.rb +27 -0
  203. data/stdlib/source_map.rb +5 -63
  204. data/stdlib/source_map/map.rb +220 -0
  205. data/stdlib/source_map/mapping.rb +26 -0
  206. data/stdlib/source_map/offset.rb +88 -0
  207. data/stdlib/source_map/version.rb +3 -0
  208. data/stdlib/source_map/vlq.rb +77 -101
  209. data/stdlib/sourcemap.rb +1 -0
  210. data/stdlib/strscan.rb +7 -1
  211. data/stdlib/template.rb +1 -1
  212. data/stdlib/thread.rb +147 -7
  213. metadata +238 -104
  214. data/lib/mspec/opal/mspec_fixes.rb +0 -87
  215. data/spec/cli/sprockets/environment_spec.rb +0 -14
  216. data/spec/filters/bugs/symbol.rb +0 -5
  217. data/spec/opal/core/kernel/warn_spec.rb +0 -83
  218. data/spec/opal/core/language/numbers_spec.rb +0 -60
  219. data/stdlib/opal-source-maps.js.erb +0 -2
  220. data/stdlib/source_map/generator.rb +0 -251
  221. data/stdlib/source_map/parser.rb +0 -102
@@ -1,6 +1,8 @@
1
1
  require 'rack/file'
2
+ require 'rack/static'
2
3
  require 'rack/urlmap'
3
4
  require 'rack/builder'
5
+ require 'rack/deflater'
4
6
  require 'rack/directory'
5
7
  require 'rack/showexceptions'
6
8
  require 'opal/source_map'
@@ -10,40 +12,54 @@ require 'erb'
10
12
  module Opal
11
13
 
12
14
  class SourceMapServer
13
- def initialize sprockets
15
+ def initialize sprockets, prefix = '/'
14
16
  @sprockets = sprockets
17
+ @prefix = prefix
15
18
  end
16
19
 
17
- attr_reader :sprockets
18
-
19
- attr_writer :prefix
20
-
21
- def prefix
22
- @prefix ||= '/__opal_source_maps__'
23
- end
20
+ attr_reader :sprockets, :prefix
24
21
 
25
22
  def inspect
26
23
  "#<#{self.class}:#{object_id}>"
27
24
  end
28
25
 
29
26
  def call(env)
30
- path_info = env['PATH_INFO']
27
+ prefix_regex = %r{^(?:#{prefix}/|/)}
28
+ path_info = env['PATH_INFO'].to_s.sub(prefix_regex, '')
31
29
 
32
- if path_info =~ /\.js\.map$/
33
- path = env['PATH_INFO'].gsub(/^\/|\.js\.map$/, '')
30
+ case path_info
31
+ when %r{^(.*)\.map$}
32
+ path = $1
34
33
  asset = sprockets[path]
35
- return [404, {}, []] if asset.nil?
34
+ return not_found(path) if asset.nil?
36
35
 
37
- return [200, {"Content-Type" => "text/json"}, [$OPAL_SOURCE_MAPS[asset.pathname].to_s]]
36
+ # "logical_name" of a BundledAsset keeps the .js extension
37
+ source = register[asset.logical_path.sub(/\.js$/, '')]
38
+ return not_found(asset) if source.nil?
39
+
40
+ return [200, {"Content-Type" => "text/json"}, [source.to_s]]
41
+ when %r{^(.*)\.rb$}
42
+ source = File.read(sprockets.resolve(path_info))
43
+ return not_found(path_info) if source.nil?
44
+ return [200, {"Content-Type" => "text/ruby"}, [source]]
38
45
  else
39
- return [200, {"Content-Type" => "text/text"}, [File.read(sprockets.resolve(path_info))]]
46
+ not_found(path_info)
40
47
  end
41
48
  end
49
+
50
+ def not_found(*messages)
51
+ not_found = [404, {}, [{not_found: messages, keys: register.keys}.inspect]]
52
+ end
53
+
54
+ def register
55
+ Opal::Processor.source_map_register
56
+ end
42
57
  end
43
58
 
44
59
  class Server
45
60
 
46
- attr_accessor :debug, :use_index, :index_path, :main, :public_root, :public_urls, :sprockets
61
+ attr_accessor :debug, :use_index, :index_path, :main, :public_root,
62
+ :public_urls, :sprockets, :prefix
47
63
 
48
64
  def initialize debug_or_options = {}
49
65
  unless Hash === debug_or_options
@@ -59,6 +75,7 @@ module Opal
59
75
  @public_urls = ['/']
60
76
  @sprockets = Environment.new
61
77
  @debug = options.fetch(:debug, true)
78
+ @prefix = options.fetch(:prefix, '/assets')
62
79
 
63
80
  yield self if block_given?
64
81
  create_app
@@ -86,24 +103,21 @@ module Opal
86
103
  end
87
104
 
88
105
  def create_app
89
- server, sprockets = self, @sprockets
90
-
106
+ server, sprockets, prefix = self, @sprockets, self.prefix
107
+ sprockets.logger.level ||= Logger::DEBUG
91
108
  @app = Rack::Builder.app do
92
109
  not_found = lambda { |env| [404, {}, []] }
93
-
94
110
  use Rack::Deflater
95
111
  use Rack::ShowExceptions
96
- map('/assets') { run sprockets }
97
- map(server.source_maps.prefix) { run server.source_maps } if server.source_map_enabled
98
112
  use Index, server if server.use_index
113
+ assets = []
114
+ assets << SourceMapServer.new(sprockets, prefix) if server.source_map_enabled
115
+ assets << sprockets
116
+ map(prefix) { run Rack::Cascade.new(assets) }
99
117
  run Rack::Static.new(not_found, :root => server.public_root, :urls => server.public_urls)
100
118
  end
101
119
  end
102
120
 
103
- def source_maps
104
- @source_maps ||= SourceMapServer.new(@sprockets)
105
- end
106
-
107
121
  def call(env)
108
122
  @app.call env
109
123
  end
@@ -151,15 +165,15 @@ module Opal
151
165
  end
152
166
 
153
167
  SOURCE = <<-HTML
154
- <!DOCTYPE html>
155
- <html>
156
- <head>
157
- <title>Opal Server</title>
158
- </head>
159
- <body>
160
- <%= javascript_include_tag @server.main %>
161
- </body>
162
- </html>
168
+ <!DOCTYPE html>
169
+ <html>
170
+ <head>
171
+ <title>Opal Server</title>
172
+ </head>
173
+ <body>
174
+ <%= javascript_include_tag @server.main %>
175
+ </body>
176
+ </html>
163
177
  HTML
164
178
  end
165
179
  end
data/lib/opal/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Opal
2
- VERSION = '0.6.3'
2
+ VERSION = '0.7.0.beta1'
3
3
  end
data/opal.gemspec CHANGED
@@ -18,14 +18,19 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.require_paths = ['lib']
20
20
 
21
- s.add_dependency 'source_map'
22
- s.add_dependency 'sprockets'
21
+ required_ruby_version = '>= 1.9.3'
22
+
23
+ s.add_dependency 'sourcemap', '~> 0.1.0'
24
+ s.add_dependency 'sprockets', '>= 2.2.1', '< 4.0.0'
25
+ s.add_dependency 'hike', '~> 1.2'
26
+ s.add_dependency 'tilt', '~> 1.4'
23
27
 
24
28
  s.add_development_dependency 'mspec', '1.5.20'
25
29
  s.add_development_dependency 'rake'
26
30
  s.add_development_dependency 'racc'
27
- s.add_development_dependency 'rspec', '~> 2.14'
31
+ s.add_development_dependency 'rspec', '~> 2.99'
28
32
  s.add_development_dependency 'octokit', '~> 2.4.0'
29
- s.add_development_dependency 'bundler', '~> 1.6'
30
- s.add_development_dependency 'yard'
33
+ s.add_development_dependency 'bundler', '~> 1.5'
34
+ s.add_development_dependency 'yard', '~> 0.8.7'
35
+ s.add_development_dependency 'rack-test'
31
36
  end
data/opal/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # Opal corelib
2
+
3
+ This is the Opal corelib implementation API documentation.
4
+ The whole corelib is loaded upon `require 'opal'`.
5
+
6
+ The `runtime.js` documentation is [availble here](runtime.js.html)
@@ -4,7 +4,7 @@ class Array
4
4
  include Enumerable
5
5
 
6
6
  # Mark all javascript arrays as being valid ruby arrays
7
- `def._isArray = true`
7
+ `def.$$is_array = true`
8
8
 
9
9
  def self.[](*objects)
10
10
  objects
@@ -95,6 +95,38 @@ class Array
95
95
  }
96
96
  end
97
97
 
98
+ def |(other)
99
+ if Array === other
100
+ other = other.to_a
101
+ else
102
+ other = Opal.coerce_to(other, Array, :to_ary).to_a
103
+ end
104
+
105
+ %x{
106
+ var result = [],
107
+ seen = {};
108
+
109
+ for (var i = 0, length = self.length; i < length; i++) {
110
+ var item = self[i];
111
+
112
+ if (!seen[item]) {
113
+ seen[item] = true;
114
+ result.push(item);
115
+ }
116
+ }
117
+
118
+ for (var i = 0, length = other.length; i < length; i++) {
119
+ var item = other[i];
120
+
121
+ if (!seen[item]) {
122
+ seen[item] = true;
123
+ result.push(item);
124
+ }
125
+ }
126
+ return result;
127
+ }
128
+ end
129
+
98
130
  def *(other)
99
131
  return `self.join(#{other.to_str})` if other.respond_to? :to_str
100
132
 
@@ -212,7 +244,7 @@ class Array
212
244
  var a = self[i],
213
245
  b = other[i];
214
246
 
215
- if (a._isArray && b._isArray && (a === self)) {
247
+ if (a.$$is_array && b.$$is_array && (a === self)) {
216
248
  continue;
217
249
  }
218
250
 
@@ -689,7 +721,7 @@ class Array
689
721
  var a = self[i],
690
722
  b = other[i];
691
723
 
692
- if (a._isArray && b._isArray && (a === self)) {
724
+ if (a.$$is_array && b.$$is_array && (a === self)) {
693
725
  continue;
694
726
  }
695
727
 
@@ -884,7 +916,7 @@ class Array
884
916
  end
885
917
 
886
918
  def hash
887
- `self._id || (self._id = Opal.uid())`
919
+ `self.$$id || (self.$$id = Opal.uid())`
888
920
  end
889
921
 
890
922
  def include?(member)
@@ -3,10 +3,10 @@ class Array
3
3
  replace = Class.new(Array::Wrapper)
4
4
 
5
5
  %x{
6
- klass._proto = replace._proto;
7
- klass._proto._klass = klass;
8
- klass._alloc = replace._alloc;
9
- klass.__parent = #{Array::Wrapper};
6
+ klass.$$proto = replace.$$proto;
7
+ klass.$$proto.$$class = klass;
8
+ klass.$$alloc = replace.$$alloc;
9
+ klass.$$parent = #{Array::Wrapper};
10
10
 
11
11
  klass.$allocate = replace.$allocate;
12
12
  klass.$new = replace.$new;
@@ -79,7 +79,7 @@ class Array::Wrapper
79
79
  %x{
80
80
  var result = #{@literal * other};
81
81
 
82
- if (result._isArray) {
82
+ if (result.$$is_array) {
83
83
  return #{self.class.allocate(`result`)}
84
84
  }
85
85
  else {
@@ -92,7 +92,7 @@ class Array::Wrapper
92
92
  %x{
93
93
  var result = #{@literal.slice(index, length)};
94
94
 
95
- if (result._isArray && (index._isRange || length !== undefined)) {
95
+ if (result.$$is_array && (index.$$is_range || length !== undefined)) {
96
96
  return #{self.class.allocate(`result`)}
97
97
  }
98
98
  else {
@@ -7,7 +7,7 @@ class BasicObject
7
7
  end
8
8
 
9
9
  def __id__
10
- `self._id || (self._id = Opal.uid())`
10
+ `self.$$id || (self.$$id = Opal.uid())`
11
11
  end
12
12
 
13
13
  def __send__(symbol, *args, &block)
@@ -16,14 +16,14 @@ class BasicObject
16
16
 
17
17
  if (func) {
18
18
  if (block !== nil) {
19
- func._p = block;
19
+ func.$$p = block;
20
20
  }
21
21
 
22
22
  return func.apply(self, args);
23
23
  }
24
24
 
25
25
  if (block !== nil) {
26
- self.$method_missing._p = block;
26
+ self.$method_missing.$$p = block;
27
27
  }
28
28
 
29
29
  return self.$method_missing.apply(self, [symbol].concat(args));
@@ -41,12 +41,12 @@ class BasicObject
41
41
  Kernel.raise ArgumentError, "no block given" unless block
42
42
 
43
43
  %x{
44
- var old = block._s,
44
+ var old = block.$$s,
45
45
  result;
46
46
 
47
- block._s = null;
47
+ block.$$s = null;
48
48
  result = block.call(self, self);
49
- block._s = old;
49
+ block.$$s = old;
50
50
 
51
51
  return result;
52
52
  }
@@ -56,12 +56,12 @@ class BasicObject
56
56
  Kernel.raise ArgumentError, "no block given" unless block
57
57
 
58
58
  %x{
59
- var block_self = block._s,
59
+ var block_self = block.$$s,
60
60
  result;
61
61
 
62
- block._s = null;
62
+ block.$$s = null;
63
63
  result = block.apply(self, args);
64
- block._s = block_self;
64
+ block.$$s = block_self;
65
65
 
66
66
  return result;
67
67
  }
@@ -1,5 +1,5 @@
1
1
  class Boolean
2
- `def._isBoolean = true`
2
+ `def.$$is_boolean = true`
3
3
 
4
4
  class << self
5
5
  undef_method :new
@@ -3,25 +3,25 @@ require 'corelib/module'
3
3
  class Class
4
4
  def self.new(sup = Object, &block)
5
5
  %x{
6
- if (!sup._isClass || sup.__mod__) {
6
+ if (!sup.$$is_class || sup.$$is_mod) {
7
7
  #{raise TypeError, "superclass must be a Class"};
8
8
  }
9
9
 
10
10
  function AnonClass(){};
11
- var klass = Opal.boot(sup, AnonClass)
12
- klass._name = nil;
13
- klass.__parent = sup;
11
+ var klass = Opal.boot(sup, AnonClass)
12
+ klass.$$name = nil;
13
+ klass.$$parent = sup;
14
14
 
15
15
  // inherit scope from parent
16
- $opal.create_scope(sup._scope, klass);
16
+ $opal.create_scope(sup.$$scope, klass);
17
17
 
18
18
  sup.$inherited(klass);
19
19
 
20
20
  if (block !== nil) {
21
- var block_self = block._s;
22
- block._s = null;
21
+ var block_self = block.$$s;
22
+ block.$$s = null;
23
23
  block.call(klass);
24
- block._s = block_self;
24
+ block.$$s = block_self;
25
25
  }
26
26
 
27
27
  return klass;
@@ -30,8 +30,8 @@ class Class
30
30
 
31
31
  def allocate
32
32
  %x{
33
- var obj = new self._alloc;
34
- obj._id = Opal.uid();
33
+ var obj = new self.$$alloc;
34
+ obj.$$id = Opal.uid();
35
35
  return obj;
36
36
  }
37
37
  end
@@ -43,13 +43,13 @@ class Class
43
43
  %x{
44
44
  var obj = #{allocate};
45
45
 
46
- obj.$initialize._p = block;
46
+ obj.$initialize.$$p = block;
47
47
  obj.$initialize.apply(obj, args);
48
48
  return obj;
49
49
  }
50
50
  end
51
51
 
52
52
  def superclass
53
- `self._super || nil`
53
+ `self.$$super || nil`
54
54
  end
55
55
  end
@@ -0,0 +1,20 @@
1
+ class Dir
2
+ class << self
3
+ def chdir(dir)
4
+ prev_cwd = `$opal.current_dir`
5
+ `$opal.current_dir = #{dir}`
6
+ yield
7
+ ensure
8
+ `$opal.current_dir = #{prev_cwd}`
9
+ end
10
+
11
+ def pwd
12
+ `$opal.current_dir` || '.'
13
+ end
14
+ alias getwd pwd
15
+
16
+ def home
17
+ ENV['HOME'] || '.'
18
+ end
19
+ end
20
+ end
@@ -4,7 +4,7 @@ module Enumerable
4
4
  var result = true;
5
5
 
6
6
  if (block !== nil) {
7
- self.$each._p = function() {
7
+ self.$each.$$p = function() {
8
8
  var value = $opal.$yieldX(block, arguments);
9
9
 
10
10
  if (value === $breaker) {
@@ -19,7 +19,7 @@ module Enumerable
19
19
  }
20
20
  }
21
21
  else {
22
- self.$each._p = function(obj) {
22
+ self.$each.$$p = function(obj) {
23
23
  if (arguments.length == 1 && #{Opal.falsy?(`obj`)}) {
24
24
  result = false;
25
25
  return $breaker;
@@ -38,7 +38,7 @@ module Enumerable
38
38
  var result = false;
39
39
 
40
40
  if (block !== nil) {
41
- self.$each._p = function() {
41
+ self.$each.$$p = function() {
42
42
  var value = $opal.$yieldX(block, arguments);
43
43
 
44
44
  if (value === $breaker) {
@@ -53,7 +53,7 @@ module Enumerable
53
53
  };
54
54
  }
55
55
  else {
56
- self.$each._p = function(obj) {
56
+ self.$each.$$p = function(obj) {
57
57
  if (arguments.length != 1 || #{Opal.truthy?(`obj`)}) {
58
58
  result = true;
59
59
  return $breaker;
@@ -77,7 +77,7 @@ module Enumerable
77
77
  %x{
78
78
  var result = [];
79
79
 
80
- self.$each._p = function() {
80
+ self.$each.$$p = function() {
81
81
  var value = $opal.$yieldX(block, arguments);
82
82
 
83
83
  if (value === $breaker) {
@@ -112,7 +112,7 @@ module Enumerable
112
112
  block = function() { return true; };
113
113
  }
114
114
 
115
- self.$each._p = function() {
115
+ self.$each.$$p = function() {
116
116
  var value = $opal.$yieldX(block, arguments);
117
117
 
118
118
  if (value === $breaker) {
@@ -144,7 +144,7 @@ module Enumerable
144
144
  var result,
145
145
  all = [];
146
146
 
147
- self.$each._p = function() {
147
+ self.$each.$$p = function() {
148
148
  var param = #{Opal.destructure(`arguments`)},
149
149
  value = $opal.$yield1(block, param);
150
150
 
@@ -202,7 +202,7 @@ module Enumerable
202
202
  %x{
203
203
  var result = undefined;
204
204
 
205
- self.$each._p = function() {
205
+ self.$each.$$p = function() {
206
206
  var params = #{Opal.destructure(`arguments`)},
207
207
  value = $opal.$yield1(block, params);
208
208
 
@@ -243,7 +243,7 @@ module Enumerable
243
243
  var result = [],
244
244
  current = 0;
245
245
 
246
- self.$each._p = function() {
246
+ self.$each.$$p = function() {
247
247
  if (number <= current) {
248
248
  result.push(#{Opal.destructure(`arguments`)});
249
249
  }
@@ -264,7 +264,7 @@ module Enumerable
264
264
  var result = [],
265
265
  dropping = true;
266
266
 
267
- self.$each._p = function() {
267
+ self.$each.$$p = function() {
268
268
  var param = #{Opal.destructure(`arguments`)};
269
269
 
270
270
  if (dropping) {
@@ -312,7 +312,7 @@ module Enumerable
312
312
  var result,
313
313
  slice = []
314
314
 
315
- self.$each._p = function() {
315
+ self.$each.$$p = function() {
316
316
  var param = #{Opal.destructure(`arguments`)};
317
317
 
318
318
  slice.push(param);
@@ -351,7 +351,7 @@ module Enumerable
351
351
  var result,
352
352
  index = 0;
353
353
 
354
- self.$each._p = function() {
354
+ self.$each.$$p = function() {
355
355
  var param = #{Opal.destructure(`arguments`)},
356
356
  value = block(param, index);
357
357
 
@@ -379,7 +379,7 @@ module Enumerable
379
379
  %x{
380
380
  var result;
381
381
 
382
- self.$each._p = function() {
382
+ self.$each.$$p = function() {
383
383
  var param = #{Opal.destructure(`arguments`)},
384
384
  value = block(param, object);
385
385
 
@@ -403,7 +403,7 @@ module Enumerable
403
403
  %x{
404
404
  var result = [];
405
405
 
406
- self.$each._p = function() {
406
+ self.$each.$$p = function() {
407
407
  result.push(#{Opal.destructure(`arguments`)});
408
408
  };
409
409
 
@@ -421,7 +421,7 @@ module Enumerable
421
421
  %x{
422
422
  var result = [];
423
423
 
424
- self.$each._p = function() {
424
+ self.$each.$$p = function() {
425
425
  var param = #{Opal.destructure(`arguments`)},
426
426
  value = $opal.$yield1(block, param);
427
427
 
@@ -449,7 +449,7 @@ module Enumerable
449
449
  index = 0;
450
450
 
451
451
  if (object != null) {
452
- self.$each._p = function() {
452
+ self.$each.$$p = function() {
453
453
  var param = #{Opal.destructure(`arguments`)};
454
454
 
455
455
  if (#{`param` == `object`}) {
@@ -461,7 +461,7 @@ module Enumerable
461
461
  };
462
462
  }
463
463
  else if (block !== nil) {
464
- self.$each._p = function() {
464
+ self.$each.$$p = function() {
465
465
  var value = $opal.$yieldX(block, arguments);
466
466
 
467
467
  if (value === $breaker) {
@@ -489,7 +489,7 @@ module Enumerable
489
489
  result = nil
490
490
 
491
491
  %x{
492
- self.$each._p = function() {
492
+ self.$each.$$p = function() {
493
493
  result = #{Opal.destructure(`arguments`)};
494
494
 
495
495
  return $breaker;
@@ -513,7 +513,7 @@ module Enumerable
513
513
  var current = 0,
514
514
  number = #{Opal.coerce_to number, Integer, :to_int};
515
515
 
516
- self.$each._p = function() {
516
+ self.$each.$$p = function() {
517
517
  result.push(#{Opal.destructure(`arguments`)});
518
518
 
519
519
  if (number <= ++current) {
@@ -535,7 +535,7 @@ module Enumerable
535
535
  var result = [];
536
536
 
537
537
  if (block !== nil) {
538
- self.$each._p = function() {
538
+ self.$each.$$p = function() {
539
539
  var param = #{Opal.destructure(`arguments`)},
540
540
  value = #{pattern === `param`};
541
541
 
@@ -552,7 +552,7 @@ module Enumerable
552
552
  };
553
553
  }
554
554
  else {
555
- self.$each._p = function() {
555
+ self.$each.$$p = function() {
556
556
  var param = #{Opal.destructure(`arguments`)},
557
557
  value = #{pattern === `param`};
558
558
 
@@ -576,7 +576,7 @@ module Enumerable
576
576
  %x{
577
577
  var result;
578
578
 
579
- self.$each._p = function() {
579
+ self.$each.$$p = function() {
580
580
  var param = #{Opal.destructure(`arguments`)},
581
581
  value = $opal.$yield1(block, param);
582
582
 
@@ -602,7 +602,7 @@ module Enumerable
602
602
  %x{
603
603
  var result = false;
604
604
 
605
- self.$each._p = function() {
605
+ self.$each.$$p = function() {
606
606
  var param = #{Opal.destructure(`arguments`)};
607
607
 
608
608
  if (#{`param` == obj}) {
@@ -622,7 +622,7 @@ module Enumerable
622
622
  var result = object;
623
623
 
624
624
  if (block !== nil && sym === undefined) {
625
- self.$each._p = function() {
625
+ self.$each.$$p = function() {
626
626
  var value = #{Opal.destructure(`arguments`)};
627
627
 
628
628
  if (result === undefined) {
@@ -650,7 +650,7 @@ module Enumerable
650
650
  result = undefined;
651
651
  }
652
652
 
653
- self.$each._p = function() {
653
+ self.$each.$$p = function() {
654
654
  var value = #{Opal.destructure(`arguments`)};
655
655
 
656
656
  if (result === undefined) {
@@ -686,7 +686,7 @@ module Enumerable
686
686
  var result;
687
687
 
688
688
  if (block !== nil) {
689
- self.$each._p = function() {
689
+ self.$each.$$p = function() {
690
690
  var param = #{Opal.destructure(`arguments`)};
691
691
 
692
692
  if (result === undefined) {
@@ -711,7 +711,7 @@ module Enumerable
711
711
  };
712
712
  }
713
713
  else {
714
- self.$each._p = function() {
714
+ self.$each.$$p = function() {
715
715
  var param = #{Opal.destructure(`arguments`)};
716
716
 
717
717
  if (result === undefined) {
@@ -738,7 +738,7 @@ module Enumerable
738
738
  var result,
739
739
  by;
740
740
 
741
- self.$each._p = function() {
741
+ self.$each.$$p = function() {
742
742
  var param = #{Opal.destructure(`arguments`)},
743
743
  value = $opal.$yield1(block, param);
744
744
 
@@ -772,7 +772,7 @@ module Enumerable
772
772
  var result;
773
773
 
774
774
  if (block !== nil) {
775
- self.$each._p = function() {
775
+ self.$each.$$p = function() {
776
776
  var param = #{Opal.destructure(`arguments`)};
777
777
 
778
778
  if (result === undefined) {
@@ -797,7 +797,7 @@ module Enumerable
797
797
  };
798
798
  }
799
799
  else {
800
- self.$each._p = function() {
800
+ self.$each.$$p = function() {
801
801
  var param = #{Opal.destructure(`arguments`)};
802
802
 
803
803
  if (result === undefined) {
@@ -824,7 +824,7 @@ module Enumerable
824
824
  var result,
825
825
  by;
826
826
 
827
- self.$each._p = function() {
827
+ self.$each.$$p = function() {
828
828
  var param = #{Opal.destructure(`arguments`)},
829
829
  value = $opal.$yield1(block, param);
830
830
 
@@ -864,7 +864,7 @@ module Enumerable
864
864
  var result = true;
865
865
 
866
866
  if (block !== nil) {
867
- self.$each._p = function() {
867
+ self.$each.$$p = function() {
868
868
  var value = $opal.$yieldX(block, arguments);
869
869
 
870
870
  if (value === $breaker) {
@@ -879,7 +879,7 @@ module Enumerable
879
879
  }
880
880
  }
881
881
  else {
882
- self.$each._p = function() {
882
+ self.$each.$$p = function() {
883
883
  var value = #{Opal.destructure(`arguments`)};
884
884
 
885
885
  if (#{Opal.truthy?(`value`)}) {
@@ -900,7 +900,7 @@ module Enumerable
900
900
  var result = false;
901
901
 
902
902
  if (block !== nil) {
903
- self.$each._p = function() {
903
+ self.$each.$$p = function() {
904
904
  var value = $opal.$yieldX(block, arguments);
905
905
 
906
906
  if (value === $breaker) {
@@ -919,7 +919,7 @@ module Enumerable
919
919
  }
920
920
  }
921
921
  else {
922
- self.$each._p = function() {
922
+ self.$each.$$p = function() {
923
923
  var value = #{Opal.destructure(`arguments`)};
924
924
 
925
925
  if (#{Opal.truthy?(`value`)}) {
@@ -945,7 +945,7 @@ module Enumerable
945
945
  %x{
946
946
  var truthy = [], falsy = [];
947
947
 
948
- self.$each._p = function() {
948
+ self.$each.$$p = function() {
949
949
  var param = #{Opal.destructure(`arguments`)},
950
950
  value = $opal.$yield1(block, param);
951
951
 
@@ -976,7 +976,7 @@ module Enumerable
976
976
  %x{
977
977
  var result = [];
978
978
 
979
- self.$each._p = function() {
979
+ self.$each.$$p = function() {
980
980
  var param = #{Opal.destructure(`arguments`)},
981
981
  value = $opal.$yield1(block, param);
982
982
 
@@ -1002,7 +1002,7 @@ module Enumerable
1002
1002
  %x{
1003
1003
  var result = [];
1004
1004
 
1005
- self.$each._p = function() {
1005
+ self.$each.$$p = function() {
1006
1006
  result.push(arguments);
1007
1007
  };
1008
1008
 
@@ -1029,7 +1029,7 @@ module Enumerable
1029
1029
 
1030
1030
  if (block !== nil) {
1031
1031
  if (pattern === undefined) {
1032
- self.$each._p = function() {
1032
+ self.$each.$$p = function() {
1033
1033
  var param = #{Opal.destructure(`arguments`)},
1034
1034
  value = $opal.$yield1(block, param);
1035
1035
 
@@ -1042,7 +1042,7 @@ module Enumerable
1042
1042
  };
1043
1043
  }
1044
1044
  else {
1045
- self.$each._p = function() {
1045
+ self.$each.$$p = function() {
1046
1046
  var param = #{Opal.destructure(`arguments`)},
1047
1047
  value = block(param, #{pattern.dup});
1048
1048
 
@@ -1056,7 +1056,7 @@ module Enumerable
1056
1056
  }
1057
1057
  }
1058
1058
  else {
1059
- self.$each._p = function() {
1059
+ self.$each.$$p = function() {
1060
1060
  var param = #{Opal.destructure(`arguments`)},
1061
1061
  value = #{pattern === `param`};
1062
1062
 
@@ -1102,7 +1102,7 @@ module Enumerable
1102
1102
  %x{
1103
1103
  var result = [];
1104
1104
 
1105
- self.$each._p = function() {
1105
+ self.$each.$$p = function() {
1106
1106
  var param = #{Opal.destructure(`arguments`)},
1107
1107
  value = $opal.$yield1(block, param);
1108
1108