opal 1.3.2 → 1.4.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -0
  3. data/.github/workflows/build.yml +0 -3
  4. data/.rubocop.yml +5 -1
  5. data/UNRELEASED.md +66 -2
  6. data/benchmark-ips/bm_truthy.rb +30 -0
  7. data/bin/opal-mspec +1 -3
  8. data/bin/opal-repl +1 -2
  9. data/bin/remove-filters +1 -4
  10. data/docs/compiled_ruby.md +10 -6
  11. data/exe/opal-repl +1 -3
  12. data/lib/opal/ast/builder.rb +1 -1
  13. data/lib/opal/cli.rb +2 -2
  14. data/lib/opal/cli_runners/nodejs.rb +9 -2
  15. data/lib/opal/cli_runners/source-map-support-browser.js +80 -216
  16. data/lib/opal/cli_runners/source-map-support-node.js +80 -216
  17. data/lib/opal/cli_runners/source-map-support.js +5 -1
  18. data/lib/opal/cli_runners/system_runner.rb +10 -4
  19. data/lib/opal/compiler.rb +3 -5
  20. data/lib/opal/fragment.rb +5 -1
  21. data/lib/opal/nodes/args/extract_block_arg.rb +1 -8
  22. data/lib/opal/nodes/args/extract_kwoptarg.rb +1 -3
  23. data/lib/opal/nodes/args/extract_optarg.rb +1 -3
  24. data/lib/opal/nodes/args/extract_post_arg.rb +2 -5
  25. data/lib/opal/nodes/args/extract_post_optarg.rb +2 -7
  26. data/lib/opal/nodes/args/initialize_iterarg.rb +1 -3
  27. data/lib/opal/nodes/args/prepare_post_args.rb +5 -1
  28. data/lib/opal/nodes/base.rb +3 -2
  29. data/lib/opal/nodes/call.rb +20 -9
  30. data/lib/opal/nodes/call_special.rb +50 -0
  31. data/lib/opal/nodes/class.rb +24 -15
  32. data/lib/opal/nodes/constants.rb +23 -5
  33. data/lib/opal/nodes/def.rb +20 -23
  34. data/lib/opal/nodes/defined.rb +5 -5
  35. data/lib/opal/nodes/definitions.rb +2 -2
  36. data/lib/opal/nodes/defs.rb +2 -5
  37. data/lib/opal/nodes/helpers.rb +48 -18
  38. data/lib/opal/nodes/if.rb +109 -8
  39. data/lib/opal/nodes/iter.rb +23 -16
  40. data/lib/opal/nodes/literal.rb +18 -4
  41. data/lib/opal/nodes/logic.rb +2 -1
  42. data/lib/opal/nodes/masgn.rb +4 -9
  43. data/lib/opal/nodes/module.rb +29 -19
  44. data/lib/opal/nodes/node_with_args.rb +1 -7
  45. data/lib/opal/nodes/scope.rb +54 -15
  46. data/lib/opal/nodes/singleton_class.rb +5 -3
  47. data/lib/opal/nodes/super.rb +3 -3
  48. data/lib/opal/nodes/top.rb +34 -31
  49. data/lib/opal/nodes/variables.rb +2 -2
  50. data/lib/opal/nodes/x_string.rb +3 -0
  51. data/lib/opal/nodes.rb +0 -1
  52. data/lib/opal/parser/patch.rb +75 -0
  53. data/lib/opal/parser/with_ruby_lexer.rb +1 -1
  54. data/lib/opal/regexp_anchors.rb +7 -7
  55. data/lib/opal/requires.rb +19 -0
  56. data/lib/opal/rewriters/pattern_matching.rb +1 -1
  57. data/lib/opal/rewriters/returnable_logic.rb +102 -4
  58. data/lib/opal/util.rb +2 -2
  59. data/lib/opal/version.rb +1 -1
  60. data/lib/opal.rb +1 -17
  61. data/opal/corelib/array/pack.rb +11 -11
  62. data/opal/corelib/array.rb +193 -152
  63. data/opal/corelib/basic_object.rb +14 -14
  64. data/opal/corelib/binding.rb +7 -7
  65. data/opal/corelib/boolean.rb +12 -15
  66. data/opal/corelib/class.rb +23 -1
  67. data/opal/corelib/comparable.rb +8 -8
  68. data/opal/corelib/complex/base.rb +2 -2
  69. data/opal/corelib/complex.rb +79 -88
  70. data/opal/corelib/constants.rb +9 -9
  71. data/opal/corelib/dir.rb +4 -3
  72. data/opal/corelib/enumerable.rb +140 -127
  73. data/opal/corelib/enumerator/arithmetic_sequence.rb +177 -0
  74. data/opal/corelib/enumerator/chain.rb +42 -0
  75. data/opal/corelib/enumerator/generator.rb +35 -0
  76. data/opal/corelib/enumerator/lazy.rb +243 -0
  77. data/opal/corelib/enumerator/yielder.rb +36 -0
  78. data/opal/corelib/enumerator.rb +45 -300
  79. data/opal/corelib/error/errno.rb +47 -0
  80. data/opal/corelib/error.rb +62 -60
  81. data/opal/corelib/file.rb +26 -12
  82. data/opal/corelib/hash.rb +98 -107
  83. data/opal/corelib/helpers.rb +62 -13
  84. data/opal/corelib/io.rb +47 -34
  85. data/opal/corelib/kernel/format.rb +29 -29
  86. data/opal/corelib/kernel.rb +86 -83
  87. data/opal/corelib/main.rb +14 -12
  88. data/opal/corelib/marshal/read_buffer.rb +15 -15
  89. data/opal/corelib/marshal/write_buffer.rb +45 -44
  90. data/opal/corelib/marshal.rb +3 -3
  91. data/opal/corelib/math.rb +50 -50
  92. data/opal/corelib/method.rb +12 -8
  93. data/opal/corelib/module.rb +96 -79
  94. data/opal/corelib/nil.rb +9 -11
  95. data/opal/corelib/number.rb +113 -118
  96. data/opal/corelib/numeric.rb +37 -33
  97. data/opal/corelib/object_space.rb +11 -10
  98. data/opal/corelib/pack_unpack/format_string_parser.rb +3 -3
  99. data/opal/corelib/pattern_matching/base.rb +7 -7
  100. data/opal/corelib/pattern_matching.rb +1 -1
  101. data/opal/corelib/proc.rb +15 -16
  102. data/opal/corelib/process/base.rb +2 -2
  103. data/opal/corelib/process/status.rb +21 -0
  104. data/opal/corelib/process.rb +5 -5
  105. data/opal/corelib/random/formatter.rb +11 -11
  106. data/opal/corelib/random/math_random.js.rb +1 -1
  107. data/opal/corelib/random/mersenne_twister.rb +3 -3
  108. data/opal/corelib/random/seedrandom.js.rb +3 -3
  109. data/opal/corelib/random.rb +17 -17
  110. data/opal/corelib/range.rb +51 -35
  111. data/opal/corelib/rational/base.rb +4 -4
  112. data/opal/corelib/rational.rb +61 -62
  113. data/opal/corelib/regexp.rb +47 -38
  114. data/opal/corelib/runtime.js +245 -139
  115. data/opal/corelib/string/encoding.rb +21 -21
  116. data/opal/corelib/string/unpack.rb +19 -14
  117. data/opal/corelib/string.rb +135 -128
  118. data/opal/corelib/struct.rb +59 -46
  119. data/opal/corelib/time.rb +47 -57
  120. data/opal/corelib/trace_point.rb +2 -2
  121. data/opal/corelib/unsupported.rb +31 -120
  122. data/opal/corelib/variables.rb +3 -3
  123. data/opal/opal/base.rb +9 -8
  124. data/opal/opal/full.rb +8 -8
  125. data/opal/opal/mini.rb +17 -17
  126. data/opal/opal.rb +17 -18
  127. data/opal.gemspec +1 -1
  128. data/spec/filters/bugs/array.rb +4 -24
  129. data/spec/filters/bugs/bigdecimal.rb +0 -23
  130. data/spec/filters/bugs/binding.rb +0 -1
  131. data/spec/filters/bugs/boolean.rb +3 -0
  132. data/spec/filters/bugs/class.rb +2 -0
  133. data/spec/filters/bugs/date.rb +0 -5
  134. data/spec/filters/bugs/encoding.rb +8 -50
  135. data/spec/filters/bugs/enumerable.rb +4 -1
  136. data/spec/filters/bugs/enumerator.rb +3 -36
  137. data/spec/filters/bugs/exception.rb +0 -2
  138. data/spec/filters/bugs/file.rb +0 -2
  139. data/spec/filters/bugs/float.rb +0 -3
  140. data/spec/filters/bugs/hash.rb +5 -3
  141. data/spec/filters/bugs/integer.rb +2 -3
  142. data/spec/filters/bugs/kernel.rb +2 -31
  143. data/spec/filters/bugs/language.rb +29 -49
  144. data/spec/filters/bugs/main.rb +0 -2
  145. data/spec/filters/bugs/marshal.rb +2 -3
  146. data/spec/filters/bugs/matrix.rb +0 -36
  147. data/spec/filters/bugs/module.rb +7 -61
  148. data/spec/filters/bugs/numeric.rb +0 -7
  149. data/spec/filters/bugs/objectspace.rb +1 -1
  150. data/spec/filters/bugs/pack_unpack.rb +0 -4
  151. data/spec/filters/bugs/proc.rb +0 -9
  152. data/spec/filters/bugs/random.rb +0 -5
  153. data/spec/filters/bugs/range.rb +1 -6
  154. data/spec/filters/bugs/regexp.rb +0 -3
  155. data/spec/filters/bugs/set.rb +8 -1
  156. data/spec/filters/bugs/string.rb +9 -34
  157. data/spec/filters/bugs/stringscanner.rb +8 -7
  158. data/spec/filters/bugs/struct.rb +2 -3
  159. data/spec/filters/bugs/symbol.rb +0 -1
  160. data/spec/filters/bugs/time.rb +0 -8
  161. data/spec/filters/bugs/unboundmethod.rb +0 -8
  162. data/spec/filters/bugs/warnings.rb +1 -7
  163. data/spec/filters/unsupported/freeze.rb +24 -0
  164. data/spec/filters/unsupported/integer.rb +1 -0
  165. data/spec/filters/unsupported/kernel.rb +12 -0
  166. data/spec/filters/unsupported/privacy.rb +3 -0
  167. data/spec/filters/unsupported/string.rb +2 -0
  168. data/spec/lib/builder_spec.rb +2 -2
  169. data/spec/lib/cli_spec.rb +1 -1
  170. data/spec/lib/compiler_spec.rb +37 -37
  171. data/spec/lib/simple_server_spec.rb +2 -2
  172. data/spec/lib/source_map/file_spec.rb +1 -1
  173. data/spec/opal/compiler/irb_spec.rb +2 -2
  174. data/spec/opal/core/kernel/puts_spec.rb +90 -0
  175. data/spec/opal/core/language/super_spec.rb +24 -0
  176. data/spec/ruby_specs +4 -2
  177. data/spec/support/rewriters_helper.rb +1 -1
  178. data/stdlib/bigdecimal.rb +7 -11
  179. data/stdlib/buffer/view.rb +2 -2
  180. data/stdlib/buffer.rb +2 -2
  181. data/stdlib/date.rb +5 -6
  182. data/stdlib/erb.rb +1 -0
  183. data/stdlib/js.rb +2 -1
  184. data/stdlib/native.rb +7 -8
  185. data/stdlib/nodejs/argf.rb +4 -4
  186. data/stdlib/nodejs/base.rb +29 -0
  187. data/stdlib/nodejs/dir.rb +1 -1
  188. data/stdlib/nodejs/env.rb +6 -9
  189. data/stdlib/nodejs/file.rb +23 -17
  190. data/stdlib/nodejs/fileutils.rb +3 -3
  191. data/stdlib/nodejs/io.rb +2 -20
  192. data/stdlib/nodejs/irb.rb +0 -0
  193. data/stdlib/nodejs/kernel.rb +2 -37
  194. data/stdlib/nodejs.rb +1 -3
  195. data/stdlib/opal/miniracer.rb +2 -0
  196. data/stdlib/opal/platform.rb +6 -13
  197. data/stdlib/opal/replutils.rb +16 -5
  198. data/stdlib/opal-parser.rb +2 -2
  199. data/stdlib/optparse/ac.rb +54 -0
  200. data/stdlib/optparse/date.rb +14 -0
  201. data/stdlib/optparse/kwargs.rb +22 -0
  202. data/stdlib/optparse/shellwords.rb +7 -0
  203. data/stdlib/optparse/time.rb +15 -0
  204. data/stdlib/optparse/uri.rb +7 -0
  205. data/stdlib/optparse/version.rb +69 -0
  206. data/stdlib/optparse.rb +2279 -0
  207. data/stdlib/pathname.rb +5 -6
  208. data/stdlib/pp.rb +18 -2
  209. data/stdlib/promise/v2.rb +18 -22
  210. data/stdlib/promise.rb +15 -21
  211. data/stdlib/set.rb +32 -32
  212. data/stdlib/shellwords.rb +240 -0
  213. data/stdlib/stringio.rb +3 -6
  214. data/stdlib/strscan.rb +5 -8
  215. data/stdlib/template.rb +2 -2
  216. data/stdlib/thread.rb +7 -9
  217. data/tasks/performance.rake +5 -2
  218. data/tasks/testing/mspec_special_calls.rb +0 -12
  219. data/tasks/testing.rake +55 -37
  220. data/test/nodejs/test_file.rb +11 -0
  221. metadata +55 -10
  222. data/lib/opal/nodes/case.rb +0 -114
@@ -1,9 +1,9 @@
1
- # helpers: breaker, slice, falsy, truthy, coerce_to
1
+ # helpers: slice, coerce_to
2
2
 
3
3
  require 'corelib/enumerable'
4
4
 
5
- class Enumerator
6
- include Enumerable
5
+ class ::Enumerator
6
+ include ::Enumerable
7
7
 
8
8
  `self.$$prototype.$$is_enumerator = true`
9
9
 
@@ -15,12 +15,14 @@ class Enumerator
15
15
  obj.size = block;
16
16
  obj.method = method;
17
17
  obj.args = args;
18
+ obj.cursor = 0;
18
19
 
19
20
  return obj;
20
21
  }
21
22
  end
22
23
 
23
24
  def initialize(*, &block)
25
+ @cursor = 0
24
26
  if block
25
27
  @object = Generator.new(&block)
26
28
  @method = :each
@@ -28,7 +30,7 @@ class Enumerator
28
30
  @size = `arguments[0] || nil`
29
31
 
30
32
  if @size && !@size.respond_to?(:call)
31
- @size = `$coerce_to(#{@size}, #{Integer}, 'to_int')`
33
+ @size = `$coerce_to(#{@size}, #{::Integer}, 'to_int')`
32
34
  end
33
35
  else
34
36
  @object = `arguments[0]`
@@ -54,7 +56,7 @@ class Enumerator
54
56
 
55
57
  def with_index(offset = 0, &block)
56
58
  offset = if offset
57
- `$coerce_to(offset, #{Integer}, 'to_int')`
59
+ `$coerce_to(offset, #{::Integer}, 'to_int')`
58
60
  else
59
61
  0
60
62
  end
@@ -65,7 +67,7 @@ class Enumerator
65
67
  var result, index = offset;
66
68
 
67
69
  self.$each.$$p = function() {
68
- var param = #{Opal.destructure(`arguments`)},
70
+ var param = #{::Opal.destructure(`arguments`)},
69
71
  value = block(param, index);
70
72
 
71
73
  index++;
@@ -77,8 +79,6 @@ class Enumerator
77
79
  }
78
80
  end
79
81
 
80
- alias with_object each_with_object
81
-
82
82
  def each_with_index(&block)
83
83
  return enum_for(:each_with_index) { size } unless block_given?
84
84
 
@@ -86,312 +86,57 @@ class Enumerator
86
86
  @object
87
87
  end
88
88
 
89
- def inspect
90
- result = "#<#{self.class}: #{@object.inspect}:#{@method}"
91
-
92
- if @args.any?
93
- result += "(#{@args.inspect[Range.new(1, -2)]})"
94
- end
89
+ def rewind
90
+ @cursor = 0
95
91
 
96
- result + '>'
92
+ self
97
93
  end
98
94
 
99
- class Generator
100
- include Enumerable
101
-
102
- def initialize(&block)
103
- raise LocalJumpError, 'no block given' unless block
104
-
105
- @block = block
106
- end
107
-
108
- def each(*args, &block)
109
- yielder = Yielder.new(&block)
110
-
111
- %x{
112
- try {
113
- args.unshift(#{yielder});
114
-
115
- Opal.yieldX(#{@block}, args);
116
- }
117
- catch (e) {
118
- if (e === $breaker) {
119
- return $breaker.$v;
120
- }
121
- else {
122
- throw e;
123
- }
124
- }
125
- }
126
-
127
- self
128
- end
95
+ def peek_values
96
+ @values ||= map { |*i| i }
97
+ ::Kernel.raise ::StopIteration, 'iteration reached an end' if @cursor >= @values.length
98
+ @values[@cursor]
129
99
  end
130
100
 
131
- class Yielder
132
- def initialize(&block)
133
- @block = block
134
- end
135
-
136
- def yield(*values)
137
- %x{
138
- var value = Opal.yieldX(#{@block}, values);
139
-
140
- if (value === $breaker) {
141
- throw $breaker;
142
- }
143
-
144
- return value;
145
- }
146
- end
147
-
148
- def <<(*values)
149
- self.yield(*values)
150
-
151
- self
152
- end
101
+ def peek
102
+ values = peek_values
103
+ values.length <= 1 ? values[0] : values
153
104
  end
154
105
 
155
- class Lazy < self
156
- class StopLazyError < Exception; end
157
-
158
- def initialize(object, size = nil, &block)
159
- unless block_given?
160
- raise ArgumentError, 'tried to call lazy new without a block'
161
- end
162
-
163
- @enumerator = object
164
-
165
- super size do |yielder, *each_args|
166
- object.each(*each_args) do |*args|
167
- %x{
168
- args.unshift(#{yielder});
169
-
170
- Opal.yieldX(block, args);
171
- }
172
- end
173
- rescue Exception
174
- nil
175
- end
176
- end
177
-
178
- alias force to_a
179
-
180
- def lazy
181
- self
182
- end
183
-
184
- def collect(&block)
185
- unless block
186
- raise ArgumentError, 'tried to call lazy map without a block'
187
- end
188
-
189
- Lazy.new(self, enumerator_size) do |enum, *args|
190
- %x{
191
- var value = Opal.yieldX(block, args);
192
-
193
- #{enum.yield `value`};
194
- }
195
- end
196
- end
197
-
198
- def collect_concat(&block)
199
- unless block
200
- raise ArgumentError, 'tried to call lazy map without a block'
201
- end
202
-
203
- Lazy.new(self, nil) do |enum, *args|
204
- %x{
205
- var value = Opal.yieldX(block, args);
206
-
207
- if (#{`value`.respond_to? :force} && #{`value`.respond_to? :each}) {
208
- #{`value`.each { |v| enum.yield v }}
209
- }
210
- else {
211
- var array = #{Opal.try_convert `value`, Array, :to_ary};
212
-
213
- if (array === nil) {
214
- #{enum.yield `value`};
215
- }
216
- else {
217
- #{`value`.each { |v| enum.yield v }};
218
- }
219
- }
220
- }
221
- end
222
- end
223
-
224
- def drop(n)
225
- n = `$coerce_to(#{n}, #{Integer}, 'to_int')`
226
-
227
- if n < 0
228
- raise ArgumentError, 'attempt to drop negative size'
229
- end
230
-
231
- current_size = enumerator_size
232
- set_size = if Integer === current_size
233
- n < current_size ? n : current_size
234
- else
235
- current_size
236
- end
237
-
238
- dropped = 0
239
- Lazy.new(self, set_size) do |enum, *args|
240
- if dropped < n
241
- dropped += 1
242
- else
243
- enum.yield(*args)
244
- end
245
- end
246
- end
247
-
248
- def drop_while(&block)
249
- unless block
250
- raise ArgumentError, 'tried to call lazy drop_while without a block'
251
- end
252
-
253
- succeeding = true
254
- Lazy.new(self, nil) do |enum, *args|
255
- if succeeding
256
- %x{
257
- var value = Opal.yieldX(block, args);
258
-
259
- if ($falsy(value)) {
260
- succeeding = false;
261
-
262
- #{enum.yield(*args)};
263
- }
264
- }
265
- else
266
- enum.yield(*args)
267
- end
268
- end
269
- end
270
-
271
- def enum_for(method = :each, *args, &block)
272
- self.class.for(self, method, *args, &block)
273
- end
274
-
275
- alias filter find_all
276
-
277
- def find_all(&block)
278
- unless block
279
- raise ArgumentError, 'tried to call lazy select without a block'
280
- end
281
-
282
- Lazy.new(self, nil) do |enum, *args|
283
- %x{
284
- var value = Opal.yieldX(block, args);
285
-
286
- if ($truthy(value)) {
287
- #{enum.yield(*args)};
288
- }
289
- }
290
- end
291
- end
292
-
293
- alias flat_map collect_concat
294
-
295
- def grep(pattern, &block)
296
- if block
297
- Lazy.new(self, nil) do |enum, *args|
298
- %x{
299
- var param = #{Opal.destructure(args)},
300
- value = #{pattern === `param`};
301
-
302
- if ($truthy(value)) {
303
- value = Opal.yield1(block, param);
304
-
305
- #{enum.yield `Opal.yield1(block, param)`};
306
- }
307
- }
308
- end
309
- else
310
- Lazy.new(self, nil) do |enum, *args|
311
- %x{
312
- var param = #{Opal.destructure(args)},
313
- value = #{pattern === `param`};
314
-
315
- if ($truthy(value)) {
316
- #{enum.yield `param`};
317
- }
318
- }
319
- end
320
- end
321
- end
322
-
323
- alias map collect
324
-
325
- alias select find_all
326
-
327
- def reject(&block)
328
- unless block
329
- raise ArgumentError, 'tried to call lazy reject without a block'
330
- end
331
-
332
- Lazy.new(self, nil) do |enum, *args|
333
- %x{
334
- var value = Opal.yieldX(block, args);
335
-
336
- if ($falsy(value)) {
337
- #{enum.yield(*args)};
338
- }
339
- }
340
- end
341
- end
106
+ def next_values
107
+ out = peek_values
108
+ @cursor += 1
109
+ out
110
+ end
342
111
 
343
- def take(n)
344
- n = `$coerce_to(#{n}, #{Integer}, 'to_int')`
112
+ def next
113
+ values = next_values
114
+ values.length <= 1 ? values[0] : values
115
+ end
345
116
 
346
- if n < 0
347
- raise ArgumentError, 'attempt to take negative size'
348
- end
117
+ def feed(arg)
118
+ raise NotImplementedError, "Opal doesn't support Enumerator#feed"
119
+ end
349
120
 
350
- current_size = enumerator_size
351
- set_size = if Integer === current_size
352
- n < current_size ? n : current_size
353
- else
354
- current_size
355
- end
356
-
357
- taken = 0
358
- Lazy.new(self, set_size) do |enum, *args|
359
- if taken < n
360
- enum.yield(*args)
361
- taken += 1
362
- else
363
- raise StopLazyError
364
- end
365
- end
366
- end
121
+ def +(other)
122
+ ::Enumerator::Chain.new(self, other)
123
+ end
367
124
 
368
- def take_while(&block)
369
- unless block
370
- raise ArgumentError, 'tried to call lazy take_while without a block'
371
- end
125
+ def inspect
126
+ result = "#<#{self.class}: #{@object.inspect}:#{@method}"
372
127
 
373
- Lazy.new(self, nil) do |enum, *args|
374
- %x{
375
- var value = Opal.yieldX(block, args);
376
-
377
- if ($truthy(value)) {
378
- #{enum.yield(*args)};
379
- }
380
- else {
381
- #{raise StopLazyError};
382
- }
383
- }
384
- end
128
+ if @args.any?
129
+ result += "(#{@args.inspect[::Range.new(1, -2)]})"
385
130
  end
386
131
 
387
- alias to_enum enum_for
388
-
389
- def inspect
390
- "#<#{self.class}: #{@enumerator.inspect}>"
391
- end
132
+ result + '>'
392
133
  end
393
134
 
394
- class ArithmeticSequence < self
395
- # We need to stub this for the time being
396
- end
135
+ alias with_object each_with_object
136
+
137
+ autoload :ArithmeticSequence, 'corelib/enumerator/arithmetic_sequence'
138
+ autoload :Chain, 'corelib/enumerator/chain'
139
+ autoload :Generator, 'corelib/enumerator/generator'
140
+ autoload :Lazy, 'corelib/enumerator/lazy'
141
+ autoload :Yielder, 'corelib/enumerator/yielder'
397
142
  end
@@ -0,0 +1,47 @@
1
+ module ::Errno
2
+ errors = [
3
+ [:EINVAL, 'Invalid argument', 22],
4
+ [:EEXIST, 'File exists', 17],
5
+ [:EISDIR, 'Is a directory', 21],
6
+ [:EMFILE, 'Too many open files', 24],
7
+ [:EACCES, 'Permission denied', 13],
8
+ [:EPERM, 'Operation not permitted', 1],
9
+ [:ENOENT, 'No such file or directory', 2]
10
+ ]
11
+
12
+ klass = nil
13
+
14
+ %x{
15
+ var i;
16
+ for (i = 0; i < errors.length; i++) {
17
+ (function() { // Create a closure
18
+ var class_name = errors[i][0];
19
+ var default_message = errors[i][1];
20
+ var errno = errors[i][2];
21
+
22
+ klass = Opal.klass(self, Opal.SystemCallError, class_name);
23
+ klass.errno = errno;
24
+
25
+ #{
26
+ class << klass
27
+ def new(name = nil)
28
+ message = `default_message`
29
+ message += " - #{name}" if name
30
+ super(message)
31
+ end
32
+ end
33
+ }
34
+ })();
35
+ }
36
+ }
37
+ end
38
+
39
+ class ::SystemCallError < ::StandardError
40
+ def errno
41
+ self.class.errno
42
+ end
43
+
44
+ class << self
45
+ attr_reader :errno
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
- class Exception < `Error`
2
- `Opal.defineProperty(self.$$prototype, '$$is_exception', true)`
1
+ class ::Exception < `Error`
2
+ `Opal.prop(self.$$prototype, '$$is_exception', true)`
3
3
  `var stack_trace_limit`
4
4
 
5
5
  def self.new(*args)
@@ -119,9 +119,19 @@ class Exception < `Error`
119
119
  to_s
120
120
  end
121
121
 
122
- def full_message(highlight: $stderr.tty?, order: :top)
123
- raise ArgumentError, "expected true or false as highlight: #{highlight}" unless [true, false].include? highlight
124
- raise ArgumentError, "expected :top or :bottom as order: #{order}" unless %i[top bottom].include? order
122
+ def full_message(kwargs = nil)
123
+ unless defined? Hash
124
+ # We are dealing with an unfully loaded Opal library, so we should
125
+ # do with as little as we can.
126
+
127
+ return "#{@message}\n#{`self.stack`}"
128
+ end
129
+
130
+ kwargs = { highlight: $stderr.tty?, order: :top }.merge(kwargs || {})
131
+ highlight, order = kwargs[:highlight], kwargs[:order]
132
+
133
+ ::Kernel.raise ::ArgumentError, "expected true or false as highlight: #{highlight}" unless [true, false].include? highlight
134
+ ::Kernel.raise ::ArgumentError, "expected :top or :bottom as order: #{order}" unless %i[top bottom].include? order
125
135
 
126
136
  if highlight
127
137
  bold_underline = "\e[1;4m"
@@ -178,7 +188,7 @@ class Exception < `Error`
178
188
  }
179
189
 
180
190
  if (valid === false) {
181
- #{raise TypeError, 'backtrace must be Array of String'}
191
+ #{::Kernel.raise ::TypeError, 'backtrace must be Array of String'}
182
192
  }
183
193
 
184
194
  self.backtrace = backtrace;
@@ -196,53 +206,45 @@ class Exception < `Error`
196
206
  end
197
207
 
198
208
  # keep the indentation, it makes the exception hierarchy clear
199
- class ScriptError < Exception; end
200
- class SyntaxError < ScriptError; end
201
- class LoadError < ScriptError; end
202
- class NotImplementedError < ScriptError; end
203
-
204
- class SystemExit < Exception; end
205
- class NoMemoryError < Exception; end
206
- class SignalException < Exception; end
207
- class Interrupt < SignalException; end
208
- class SecurityError < Exception; end
209
- class SystemStackError < Exception; end
210
-
211
- class StandardError < Exception; end
212
- class EncodingError < StandardError; end
213
- class ZeroDivisionError < StandardError; end
214
- class NameError < StandardError; end
215
- class NoMethodError < NameError; end
216
- class RuntimeError < StandardError; end
217
- class FrozenError < RuntimeError; end
218
- class LocalJumpError < StandardError; end
219
- class TypeError < StandardError; end
220
- class ArgumentError < StandardError; end
221
- class UncaughtThrowError < ArgumentError; end
222
- class IndexError < StandardError; end
223
- class StopIteration < IndexError; end
224
- class ClosedQueueError < StopIteration; end
225
- class KeyError < IndexError; end
226
- class RangeError < StandardError; end
227
- class FloatDomainError < RangeError; end
228
- class IOError < StandardError; end
229
- class EOFError < IOError; end
230
- class SystemCallError < StandardError; end
231
- class RegexpError < StandardError; end
232
- class ThreadError < StandardError; end
233
- class FiberError < StandardError; end
234
-
235
- module Errno
236
- class EINVAL < SystemCallError
237
- def self.new(name = nil)
238
- message = 'Invalid argument'
239
- message += " - #{name}" if name
240
- super(message)
241
- end
242
- end
243
- end
244
-
245
- class UncaughtThrowError < ArgumentError
209
+ class ::ScriptError < ::Exception; end
210
+ class ::SyntaxError < ::ScriptError; end
211
+ class ::LoadError < ::ScriptError; end
212
+ class ::NotImplementedError < ::ScriptError; end
213
+
214
+ class ::SystemExit < ::Exception; end
215
+ class ::NoMemoryError < ::Exception; end
216
+ class ::SignalException < ::Exception; end
217
+ class ::Interrupt < ::SignalException; end
218
+ class ::SecurityError < ::Exception; end
219
+ class ::SystemStackError < ::Exception; end
220
+
221
+ class ::StandardError < ::Exception; end
222
+ class ::EncodingError < ::StandardError; end
223
+ class ::ZeroDivisionError < ::StandardError; end
224
+ class ::NameError < ::StandardError; end
225
+ class ::NoMethodError < ::NameError; end
226
+ class ::RuntimeError < ::StandardError; end
227
+ class ::FrozenError < ::RuntimeError; end
228
+ class ::LocalJumpError < ::StandardError; end
229
+ class ::TypeError < ::StandardError; end
230
+ class ::ArgumentError < ::StandardError; end
231
+ class ::UncaughtThrowError < ::ArgumentError; end
232
+ class ::IndexError < ::StandardError; end
233
+ class ::StopIteration < ::IndexError; end
234
+ class ::ClosedQueueError < ::StopIteration; end
235
+ class ::KeyError < ::IndexError; end
236
+ class ::RangeError < ::StandardError; end
237
+ class ::FloatDomainError < ::RangeError; end
238
+ class ::IOError < ::StandardError; end
239
+ class ::EOFError < ::IOError; end
240
+ class ::SystemCallError < ::StandardError; end
241
+ class ::RegexpError < ::StandardError; end
242
+ class ::ThreadError < ::StandardError; end
243
+ class ::FiberError < ::StandardError; end
244
+
245
+ ::Object.autoload :Errno, 'corelib/error/errno'
246
+
247
+ class ::UncaughtThrowError < ::ArgumentError
246
248
  attr_reader :tag, :value
247
249
 
248
250
  def initialize(tag, value = nil)
@@ -253,7 +255,7 @@ class UncaughtThrowError < ArgumentError
253
255
  end
254
256
  end
255
257
 
256
- class NameError
258
+ class ::NameError
257
259
  attr_reader :name
258
260
 
259
261
  def initialize(message, name = nil)
@@ -262,7 +264,7 @@ class NameError
262
264
  end
263
265
  end
264
266
 
265
- class NoMethodError
267
+ class ::NoMethodError
266
268
  attr_reader :args
267
269
 
268
270
  def initialize(message, name = nil, args = [])
@@ -271,11 +273,11 @@ class NoMethodError
271
273
  end
272
274
  end
273
275
 
274
- class StopIteration
276
+ class ::StopIteration
275
277
  attr_reader :result
276
278
  end
277
279
 
278
- class KeyError
280
+ class ::KeyError
279
281
  def initialize(message, receiver: nil, key: nil)
280
282
  super(message)
281
283
  @receiver = receiver
@@ -283,15 +285,15 @@ class KeyError
283
285
  end
284
286
 
285
287
  def receiver
286
- @receiver || raise(ArgumentError, 'no receiver is available')
288
+ @receiver || ::Kernel.raise(::ArgumentError, 'no receiver is available')
287
289
  end
288
290
 
289
291
  def key
290
- @key || raise(ArgumentError, 'no key is available')
292
+ @key || ::Kernel.raise(::ArgumentError, 'no key is available')
291
293
  end
292
294
  end
293
295
 
294
- module JS
296
+ module ::JS
295
297
  class Error
296
298
  end
297
299
  end