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
@@ -3,11 +3,11 @@
3
3
  require 'corelib/enumerable'
4
4
  require 'corelib/numeric'
5
5
 
6
- class Array < `Array`
7
- include Enumerable
6
+ class ::Array < `Array`
7
+ include ::Enumerable
8
8
 
9
9
  # Mark all javascript arrays as being valid ruby arrays
10
- `Opal.defineProperty(self.$$prototype, '$$is_array', true)`
10
+ `Opal.prop(self.$$prototype, '$$is_array', true)`
11
11
 
12
12
  %x{
13
13
  // Recent versions of V8 (> 7.1) only use an optimized implementation when Array.prototype is unmodified.
@@ -77,15 +77,15 @@ class Array < `Array`
77
77
  def initialize(size = nil, obj = nil, &block)
78
78
  %x{
79
79
  if (obj !== nil && block !== nil) {
80
- #{warn('warning: block supersedes default value argument')}
80
+ #{::Kernel.warn('warning: block supersedes default value argument')}
81
81
  }
82
82
 
83
- if (size > #{Integer::MAX}) {
84
- #{raise ArgumentError, 'array size too big'}
83
+ if (size > #{::Integer::MAX}) {
84
+ #{::Kernel.raise ::ArgumentError, 'array size too big'}
85
85
  }
86
86
 
87
87
  if (arguments.length > 2) {
88
- #{raise ArgumentError, "wrong number of arguments (#{`arguments.length`} for 0..2)"}
88
+ #{::Kernel.raise ::ArgumentError, "wrong number of arguments (#{`arguments.length`} for 0..2)"}
89
89
  }
90
90
 
91
91
  if (arguments.length === 0) {
@@ -103,10 +103,10 @@ class Array < `Array`
103
103
  }
104
104
  }
105
105
 
106
- size = $coerce_to(size, #{Integer}, 'to_int');
106
+ size = $coerce_to(size, #{::Integer}, 'to_int');
107
107
 
108
108
  if (size < 0) {
109
- #{raise ArgumentError, 'negative array size'}
109
+ #{::Kernel.raise ::ArgumentError, 'negative array size'}
110
110
  }
111
111
 
112
112
  self.splice(0, self.length);
@@ -129,14 +129,14 @@ class Array < `Array`
129
129
  end
130
130
 
131
131
  def self.try_convert(obj)
132
- Opal.coerce_to? obj, Array, :to_ary
132
+ ::Opal.coerce_to? obj, ::Array, :to_ary
133
133
  end
134
134
 
135
135
  def &(other)
136
- other = if Array === other
136
+ other = if ::Array === other
137
137
  other.to_a
138
138
  else
139
- `$coerce_to(other, #{Array}, 'to_ary')`.to_a
139
+ `$coerce_to(other, #{::Array}, 'to_ary')`.to_a
140
140
  end
141
141
 
142
142
  %x{
@@ -158,10 +158,10 @@ class Array < `Array`
158
158
  end
159
159
 
160
160
  def |(other)
161
- other = if Array === other
161
+ other = if ::Array === other
162
162
  other.to_a
163
163
  else
164
- `$coerce_to(other, #{Array}, 'to_ary')`.to_a
164
+ `$coerce_to(other, #{::Array}, 'to_ary')`.to_a
165
165
  end
166
166
 
167
167
  %x{
@@ -182,10 +182,10 @@ class Array < `Array`
182
182
  def *(other)
183
183
  return join(other.to_str) if other.respond_to? :to_str
184
184
 
185
- other = `$coerce_to(other, #{Integer}, 'to_int')`
185
+ other = `$coerce_to(other, #{::Integer}, 'to_int')`
186
186
 
187
187
  if `other < 0`
188
- raise ArgumentError, 'negative argument'
188
+ ::Kernel.raise ::ArgumentError, 'negative argument'
189
189
  end
190
190
 
191
191
  %x{
@@ -201,20 +201,20 @@ class Array < `Array`
201
201
  end
202
202
 
203
203
  def +(other)
204
- other = if Array === other
204
+ other = if ::Array === other
205
205
  other.to_a
206
206
  else
207
- `$coerce_to(other, #{Array}, 'to_ary')`.to_a
207
+ `$coerce_to(other, #{::Array}, 'to_ary')`.to_a
208
208
  end
209
209
 
210
210
  `self.concat(other)`
211
211
  end
212
212
 
213
213
  def -(other)
214
- other = if Array === other
214
+ other = if ::Array === other
215
215
  other.to_a
216
216
  else
217
- `$coerce_to(other, #{Array}, 'to_ary')`.to_a
217
+ `$coerce_to(other, #{::Array}, 'to_ary')`.to_a
218
218
  end
219
219
 
220
220
  return [] if `self.length === 0`
@@ -245,7 +245,7 @@ class Array < `Array`
245
245
  end
246
246
 
247
247
  def <=>(other)
248
- if Array === other
248
+ if ::Array === other
249
249
  other = other.to_a
250
250
  elsif other.respond_to? :to_ary
251
251
  other = other.to_ary.to_a
@@ -333,8 +333,8 @@ class Array < `Array`
333
333
  exclude, from, to, result;
334
334
 
335
335
  exclude = index.excl;
336
- from = $coerce_to(index.begin, Opal.Integer, 'to_int');
337
- to = $coerce_to(index.end, Opal.Integer, 'to_int');
336
+ from = index.begin === nil ? 0 : $coerce_to(index.begin, Opal.Integer, 'to_int');
337
+ to = index.end === nil ? -1 : $coerce_to(index.end, Opal.Integer, 'to_int');
338
338
 
339
339
  if (from < 0) {
340
340
  from += size;
@@ -344,6 +344,10 @@ class Array < `Array`
344
344
  }
345
345
  }
346
346
 
347
+ if (index.excl_rev && index.begin !== nil) {
348
+ from += 1;
349
+ }
350
+
347
351
  if (from > size) {
348
352
  return nil;
349
353
  }
@@ -356,7 +360,7 @@ class Array < `Array`
356
360
  }
357
361
  }
358
362
 
359
- if (!exclude) {
363
+ if (!exclude || index.end === nil) {
360
364
  to += 1;
361
365
  }
362
366
 
@@ -364,6 +368,30 @@ class Array < `Array`
364
368
  return result;
365
369
  }
366
370
 
371
+ function $array_slice_arithmetic_seq(self, index) {
372
+ var array, out = [], i = 0, pseudorange;
373
+
374
+ if (index.step < 0) {
375
+ pseudorange = {
376
+ begin: index.range.end,
377
+ end: index.range.begin,
378
+ excl: false,
379
+ excl_rev: index.range.excl
380
+ };
381
+ array = $array_slice_range(self, pseudorange).$reverse();
382
+ }
383
+ else {
384
+ array = $array_slice_range(self, index.range);
385
+ }
386
+
387
+ while (i < array.length) {
388
+ out.push(array[i]);
389
+ i += Math.abs(index.step);
390
+ }
391
+
392
+ return out;
393
+ }
394
+
367
395
  function $array_slice_index_length(self, index, length) {
368
396
  var size = self.length,
369
397
  exclude, from, to, result;
@@ -403,6 +431,9 @@ class Array < `Array`
403
431
  if (index.$$is_range) {
404
432
  return $array_slice_range(self, index);
405
433
  }
434
+ else if (index.$$is_arithmetic_seq) {
435
+ return $array_slice_arithmetic_seq(self, index);
436
+ }
406
437
  else {
407
438
  return $array_slice_index_length(self, index, length);
408
439
  }
@@ -414,8 +445,8 @@ class Array < `Array`
414
445
  var i, size = self.length;
415
446
  }
416
447
 
417
- if Range === index
418
- data = if Array === value
448
+ if ::Range === index
449
+ data = if ::Array === value
419
450
  value.to_a
420
451
  elsif value.respond_to? :to_ary
421
452
  value.to_ary.to_a
@@ -425,14 +456,14 @@ class Array < `Array`
425
456
 
426
457
  %x{
427
458
  var exclude = index.excl,
428
- from = $coerce_to(index.begin, #{Integer}, 'to_int'),
429
- to = $coerce_to(index.end, #{Integer}, 'to_int');
459
+ from = index.begin === nil ? 0 : $coerce_to(index.begin, Opal.Integer, 'to_int'),
460
+ to = index.end === nil ? -1 : $coerce_to(index.end, Opal.Integer, 'to_int');
430
461
 
431
462
  if (from < 0) {
432
463
  from += size;
433
464
 
434
465
  if (from < 0) {
435
- #{raise RangeError, "#{index.inspect} out of range"};
466
+ #{::Kernel.raise ::RangeError, "#{index.inspect} out of range"};
436
467
  }
437
468
  }
438
469
 
@@ -440,7 +471,7 @@ class Array < `Array`
440
471
  to += size;
441
472
  }
442
473
 
443
- if (!exclude) {
474
+ if (!exclude || index.end === nil) {
444
475
  to += 1;
445
476
  }
446
477
 
@@ -466,7 +497,7 @@ class Array < `Array`
466
497
  length = value
467
498
  value = extra
468
499
 
469
- data = if Array === value
500
+ data = if ::Array === value
470
501
  value.to_a
471
502
  elsif value.respond_to? :to_ary
472
503
  value.to_ary.to_a
@@ -478,20 +509,20 @@ class Array < `Array`
478
509
  %x{
479
510
  var old;
480
511
 
481
- index = $coerce_to(index, #{Integer}, 'to_int');
482
- length = $coerce_to(length, #{Integer}, 'to_int');
512
+ index = $coerce_to(index, #{::Integer}, 'to_int');
513
+ length = $coerce_to(length, #{::Integer}, 'to_int');
483
514
 
484
515
  if (index < 0) {
485
516
  old = index;
486
517
  index += size;
487
518
 
488
519
  if (index < 0) {
489
- #{raise IndexError, "index #{`old`} too small for array; minimum #{`-self.length`}"};
520
+ #{::Kernel.raise ::IndexError, "index #{`old`} too small for array; minimum #{`-self.length`}"};
490
521
  }
491
522
  }
492
523
 
493
524
  if (length < 0) {
494
- #{raise IndexError, "negative length (#{length})"}
525
+ #{::Kernel.raise ::IndexError, "negative length (#{length})"}
495
526
  }
496
527
 
497
528
  if (index > size) {
@@ -531,7 +562,7 @@ class Array < `Array`
531
562
 
532
563
  def at(index)
533
564
  %x{
534
- index = $coerce_to(index, #{Integer}, 'to_int')
565
+ index = $coerce_to(index, #{::Integer}, 'to_int')
535
566
 
536
567
  if (index < 0) {
537
568
  index += self.length;
@@ -574,7 +605,7 @@ class Array < `Array`
574
605
  smaller = (ret < 0);
575
606
  }
576
607
  else {
577
- #{raise TypeError, "wrong argument type #{`ret`.class} (must be numeric, true, false or nil)"}
608
+ #{::Kernel.raise ::TypeError, "wrong argument type #{`ret`.class} (must be numeric, true, false or nil)"}
578
609
  }
579
610
 
580
611
  if (smaller) { max = mid; } else { min = mid + 1; }
@@ -602,9 +633,9 @@ class Array < `Array`
602
633
  unless block_given?
603
634
  return enum_for(:cycle, n) do
604
635
  if n.nil?
605
- Float::INFINITY
636
+ ::Float::INFINITY
606
637
  else
607
- n = Opal.coerce_to!(n, Integer, :to_int)
638
+ n = ::Opal.coerce_to!(n, ::Integer, :to_int)
608
639
  n > 0 ? enumerator_size * n : 0
609
640
  end
610
641
  end
@@ -623,7 +654,7 @@ class Array < `Array`
623
654
  }
624
655
  }
625
656
  else {
626
- n = #{Opal.coerce_to!(n, Integer, :to_int)};
657
+ n = #{::Opal.coerce_to!(n, ::Integer, :to_int)};
627
658
  if (n <= 0) {
628
659
  return self;
629
660
  }
@@ -702,7 +733,7 @@ class Array < `Array`
702
733
  }
703
734
 
704
735
  def combination(n)
705
- num = Opal.coerce_to! n, Integer, :to_int
736
+ num = ::Opal.coerce_to! n, ::Integer, :to_int
706
737
  return enum_for(:combination, num) { `binomial_coefficient(#{self}.length, num)` } unless block_given?
707
738
 
708
739
  %x{
@@ -750,7 +781,7 @@ class Array < `Array`
750
781
  end
751
782
 
752
783
  def repeated_combination(n)
753
- num = Opal.coerce_to! n, Integer, :to_int
784
+ num = ::Opal.coerce_to! n, ::Integer, :to_int
754
785
 
755
786
  unless block_given?
756
787
  return enum_for(:repeated_combination, num) { `binomial_coefficient(self.length + num - 1, num)` }
@@ -810,10 +841,10 @@ class Array < `Array`
810
841
 
811
842
  def concat(*others)
812
843
  others = others.map do |other|
813
- other = if Array === other
844
+ other = if ::Array === other
814
845
  other.to_a
815
846
  else
816
- `$coerce_to(other, #{Array}, 'to_ary')`.to_a
847
+ `$coerce_to(other, #{::Array}, 'to_ary')`.to_a
817
848
  end
818
849
 
819
850
  if other.equal?(self)
@@ -859,7 +890,7 @@ class Array < `Array`
859
890
 
860
891
  def delete_at(index)
861
892
  %x{
862
- index = $coerce_to(index, #{Integer}, 'to_int');
893
+ index = $coerce_to(index, #{::Integer}, 'to_int');
863
894
 
864
895
  if (index < 0) {
865
896
  index += self.length;
@@ -897,7 +928,7 @@ class Array < `Array`
897
928
  }
898
929
 
899
930
  unless item.respond_to?(:dig)
900
- raise TypeError, "#{item.class} does not have #dig method"
931
+ ::Kernel.raise ::TypeError, "#{item.class} does not have #dig method"
901
932
  end
902
933
 
903
934
  item.dig(*idxs)
@@ -905,8 +936,10 @@ class Array < `Array`
905
936
 
906
937
  def drop(number)
907
938
  %x{
939
+ number = $coerce_to(number, #{::Integer}, 'to_int');
940
+
908
941
  if (number < 0) {
909
- #{raise ArgumentError}
942
+ #{::Kernel.raise ::ArgumentError}
910
943
  }
911
944
 
912
945
  return self.slice(number);
@@ -1003,7 +1036,7 @@ class Array < `Array`
1003
1036
  %x{
1004
1037
  var original = index;
1005
1038
 
1006
- index = $coerce_to(index, #{Integer}, 'to_int');
1039
+ index = $coerce_to(index, #{::Integer}, 'to_int');
1007
1040
 
1008
1041
  if (index < 0) {
1009
1042
  index += self.length;
@@ -1026,10 +1059,10 @@ class Array < `Array`
1026
1059
  }
1027
1060
 
1028
1061
  if (self.length === 0) {
1029
- #{raise IndexError, "index #{`original`} outside of array bounds: 0...0"}
1062
+ #{::Kernel.raise ::IndexError, "index #{`original`} outside of array bounds: 0...0"}
1030
1063
  }
1031
1064
  else {
1032
- #{raise IndexError, "index #{`original`} outside of array bounds: -#{`self.length`}...#{`self.length`}"};
1065
+ #{::Kernel.raise ::IndexError, "index #{`original`} outside of array bounds: -#{`self.length`}...#{`self.length`}"};
1033
1066
  }
1034
1067
  }
1035
1068
  end
@@ -1041,39 +1074,39 @@ class Array < `Array`
1041
1074
 
1042
1075
  if block
1043
1076
  if `args.length > 2`
1044
- raise ArgumentError, "wrong number of arguments (#{args.length} for 0..2)"
1077
+ ::Kernel.raise ::ArgumentError, "wrong number of arguments (#{args.length} for 0..2)"
1045
1078
  end
1046
1079
 
1047
1080
  one, two = args
1048
1081
  else
1049
1082
  if `args.length == 0`
1050
- raise ArgumentError, 'wrong number of arguments (0 for 1..3)'
1083
+ ::Kernel.raise ::ArgumentError, 'wrong number of arguments (0 for 1..3)'
1051
1084
  elsif `args.length > 3`
1052
- raise ArgumentError, "wrong number of arguments (#{args.length} for 1..3)"
1085
+ ::Kernel.raise ::ArgumentError, "wrong number of arguments (#{args.length} for 1..3)"
1053
1086
  end
1054
1087
 
1055
1088
  obj, one, two = args
1056
1089
  end
1057
1090
 
1058
- if Range === one
1059
- raise TypeError, 'length invalid with range' if two
1091
+ if ::Range === one
1092
+ ::Kernel.raise ::TypeError, 'length invalid with range' if two
1060
1093
 
1061
- left = `$coerce_to(one.begin, #{Integer}, 'to_int')`
1094
+ left = `one.begin === nil ? 0 : $coerce_to(one.begin, #{::Integer}, 'to_int')`
1062
1095
  `left += this.length` if `left < 0`
1063
- raise RangeError, "#{one.inspect} out of range" if `left < 0`
1096
+ ::Kernel.raise ::RangeError, "#{one.inspect} out of range" if `left < 0`
1064
1097
 
1065
- right = `$coerce_to(one.end, #{Integer}, 'to_int')`
1098
+ right = `one.end === nil ? -1 : $coerce_to(one.end, #{::Integer}, 'to_int')`
1066
1099
  `right += this.length` if `right < 0`
1067
1100
  `right += 1` unless one.exclude_end?
1068
1101
 
1069
1102
  return self if `right <= left`
1070
1103
  elsif one
1071
- left = `$coerce_to(one, #{Integer}, 'to_int')`
1104
+ left = `$coerce_to(one, #{::Integer}, 'to_int')`
1072
1105
  `left += this.length` if `left < 0`
1073
1106
  left = 0 if `left < 0`
1074
1107
 
1075
1108
  if two
1076
- right = `$coerce_to(two, #{Integer}, 'to_int')`
1109
+ right = `$coerce_to(two, #{::Integer}, 'to_int')`
1077
1110
 
1078
1111
  return self if `right == 0`
1079
1112
 
@@ -1122,10 +1155,10 @@ class Array < `Array`
1122
1155
  return self.length === 0 ? nil : self[0];
1123
1156
  }
1124
1157
 
1125
- count = $coerce_to(count, #{Integer}, 'to_int');
1158
+ count = $coerce_to(count, #{::Integer}, 'to_int');
1126
1159
 
1127
1160
  if (count < 0) {
1128
- #{raise ArgumentError, 'negative array size'};
1161
+ #{::Kernel.raise ::ArgumentError, 'negative array size'};
1129
1162
  }
1130
1163
 
1131
1164
  return self.slice(0, count);
@@ -1157,11 +1190,11 @@ class Array < `Array`
1157
1190
  }
1158
1191
 
1159
1192
  if (!ary.$$is_array) {
1160
- #{raise TypeError};
1193
+ #{::Kernel.raise ::TypeError};
1161
1194
  }
1162
1195
 
1163
1196
  if (ary === self) {
1164
- #{raise ArgumentError};
1197
+ #{::Kernel.raise ::ArgumentError};
1165
1198
  }
1166
1199
 
1167
1200
  switch (level) {
@@ -1179,7 +1212,7 @@ class Array < `Array`
1179
1212
  }
1180
1213
 
1181
1214
  if (level !== undefined) {
1182
- level = $coerce_to(level, #{Integer}, 'to_int');
1215
+ level = $coerce_to(level, #{::Integer}, 'to_int');
1183
1216
  }
1184
1217
 
1185
1218
  return _flatten(self, level);
@@ -1294,14 +1327,14 @@ class Array < `Array`
1294
1327
 
1295
1328
  def insert(index, *objects)
1296
1329
  %x{
1297
- index = $coerce_to(index, #{Integer}, 'to_int');
1330
+ index = $coerce_to(index, #{::Integer}, 'to_int');
1298
1331
 
1299
1332
  if (objects.length > 0) {
1300
1333
  if (index < 0) {
1301
1334
  index += self.length + 1;
1302
1335
 
1303
1336
  if (index < 0) {
1304
- #{ raise IndexError, "#{index} is out of bounds" };
1337
+ #{ ::Kernel.raise ::IndexError, "#{index} is out of bounds" };
1305
1338
  }
1306
1339
  }
1307
1340
  if (index > self.length) {
@@ -1317,30 +1350,45 @@ class Array < `Array`
1317
1350
  self
1318
1351
  end
1319
1352
 
1353
+ `var inspect_stack = []`
1354
+
1320
1355
  def inspect
1321
1356
  %x{
1322
1357
  var result = [],
1323
- id = #{__id__};
1324
-
1325
- for (var i = 0, length = self.length; i < length; i++) {
1326
- var item = #{self[`i`]};
1358
+ id = #{__id__},
1359
+ pushed = true;
1360
+ }
1327
1361
 
1328
- if (#{`item`.__id__} === id) {
1329
- result.push('[...]');
1362
+ begin
1363
+ %x{
1364
+ if (inspect_stack.indexOf(id) !== -1) {
1365
+ pushed = false;
1366
+ return '[...]';
1330
1367
  }
1331
- else {
1332
- result.push(#{`item`.inspect});
1368
+ inspect_stack.push(id)
1369
+
1370
+ for (var i = 0, length = self.length; i < length; i++) {
1371
+ var item = #{self[`i`]};
1372
+
1373
+ result.push(#{Opal.inspect(`item`)});
1333
1374
  }
1334
- }
1335
1375
 
1336
- return '[' + result.join(', ') + ']';
1337
- }
1376
+ return '[' + result.join(', ') + ']';
1377
+ }
1378
+ nil
1379
+ ensure
1380
+ `if (pushed) inspect_stack.pop()`
1381
+ end
1338
1382
  end
1339
1383
 
1340
1384
  def intersection(*arrays)
1341
1385
  arrays.reduce(to_a.dup) { |a, b| a & b }
1342
1386
  end
1343
1387
 
1388
+ def intersect?(other)
1389
+ !intersection(other).empty?
1390
+ end
1391
+
1344
1392
  def join(sep = nil)
1345
1393
  return '' if `self.length === 0`
1346
1394
 
@@ -1369,7 +1417,7 @@ class Array < `Array`
1369
1417
  tmp = #{`item`.to_ary};
1370
1418
 
1371
1419
  if (tmp === self) {
1372
- #{raise ArgumentError};
1420
+ #{::Kernel.raise ::ArgumentError};
1373
1421
  }
1374
1422
 
1375
1423
  if (tmp !== nil) {
@@ -1389,14 +1437,14 @@ class Array < `Array`
1389
1437
  }
1390
1438
  }
1391
1439
 
1392
- #{raise NoMethodError.new("#{`Opal.inspect(item)`} doesn't respond to #to_str, #to_ary or #to_s", 'to_str')};
1440
+ #{::Kernel.raise ::NoMethodError.new("#{Opal.inspect(item)} doesn't respond to #to_str, #to_ary or #to_s", 'to_str')};
1393
1441
  }
1394
1442
 
1395
1443
  if (sep === nil) {
1396
1444
  return result.join('');
1397
1445
  }
1398
1446
  else {
1399
- return result.join(#{Opal.coerce_to!(sep, String, :to_str).to_s});
1447
+ return result.join(#{::Opal.coerce_to!(sep, ::String, :to_str).to_s});
1400
1448
  }
1401
1449
  }
1402
1450
  end
@@ -1413,10 +1461,10 @@ class Array < `Array`
1413
1461
  return self.length === 0 ? nil : self[self.length - 1];
1414
1462
  }
1415
1463
 
1416
- count = $coerce_to(count, #{Integer}, 'to_int');
1464
+ count = $coerce_to(count, #{::Integer}, 'to_int');
1417
1465
 
1418
1466
  if (count < 0) {
1419
- #{raise ArgumentError, 'negative array size'};
1467
+ #{::Kernel.raise ::ArgumentError, 'negative array size'};
1420
1468
  }
1421
1469
 
1422
1470
  if (count > self.length) {
@@ -1431,10 +1479,6 @@ class Array < `Array`
1431
1479
  `self.length`
1432
1480
  end
1433
1481
 
1434
- alias map collect
1435
-
1436
- alias map! collect!
1437
-
1438
1482
  def max(n = undefined, &block)
1439
1483
  each.max(n, &block)
1440
1484
  end
@@ -1470,7 +1514,7 @@ class Array < `Array`
1470
1514
  num = self.length;
1471
1515
  }
1472
1516
  else {
1473
- num = $coerce_to(num, #{Integer}, 'to_int');
1517
+ num = $coerce_to(num, #{::Integer}, 'to_int');
1474
1518
  }
1475
1519
 
1476
1520
  if (num < 0 || self.length < num) {
@@ -1527,7 +1571,7 @@ class Array < `Array`
1527
1571
  end
1528
1572
 
1529
1573
  def repeated_permutation(n)
1530
- num = Opal.coerce_to! n, Integer, :to_int
1574
+ num = ::Opal.coerce_to! n, ::Integer, :to_int
1531
1575
  return enum_for(:repeated_permutation, num) { num >= 0 ? size**num : 0 } unless block_given?
1532
1576
 
1533
1577
  %x{
@@ -1556,10 +1600,10 @@ class Array < `Array`
1556
1600
  return `self.pop()`
1557
1601
  end
1558
1602
 
1559
- count = `$coerce_to(count, #{Integer}, 'to_int')`
1603
+ count = `$coerce_to(count, #{::Integer}, 'to_int')`
1560
1604
 
1561
1605
  if `count < 0`
1562
- raise ArgumentError, 'negative array size'
1606
+ ::Kernel.raise ::ArgumentError, 'negative array size'
1563
1607
  end
1564
1608
 
1565
1609
  return [] if `self.length === 0`
@@ -1584,7 +1628,7 @@ class Array < `Array`
1584
1628
 
1585
1629
  arrays[0] = self;
1586
1630
  for (i = 1; i < n; i++) {
1587
- arrays[i] = $coerce_to(args[i - 1], #{Array}, 'to_ary');
1631
+ arrays[i] = $coerce_to(args[i - 1], #{::Array}, 'to_ary');
1588
1632
  }
1589
1633
 
1590
1634
  for (i = 0; i < n; i++) {
@@ -1594,7 +1638,7 @@ class Array < `Array`
1594
1638
  }
1595
1639
  resultlen *= len;
1596
1640
  if (resultlen > 2147483647) {
1597
- #{raise RangeError, 'too big to product'}
1641
+ #{::Kernel.raise ::RangeError, 'too big to product'}
1598
1642
  }
1599
1643
  lengths[i] = len;
1600
1644
  counters[i] = 0;
@@ -1633,8 +1677,6 @@ class Array < `Array`
1633
1677
  self
1634
1678
  end
1635
1679
 
1636
- alias append push
1637
-
1638
1680
  def rassoc(object)
1639
1681
  %x{
1640
1682
  for (var i = 0, length = self.length, item; i < length; i++) {
@@ -1680,10 +1722,10 @@ class Array < `Array`
1680
1722
  end
1681
1723
 
1682
1724
  def replace(other)
1683
- other = if Array === other
1725
+ other = if ::Array === other
1684
1726
  other.to_a
1685
1727
  else
1686
- `$coerce_to(other, #{Array}, 'to_ary')`.to_a
1728
+ `$coerce_to(other, #{::Array}, 'to_ary')`.to_a
1687
1729
  end
1688
1730
 
1689
1731
  %x{
@@ -1752,7 +1794,7 @@ class Array < `Array`
1752
1794
  %x{
1753
1795
  var ary, idx, firstPart, lastPart;
1754
1796
 
1755
- n = $coerce_to(n, #{Integer}, 'to_int')
1797
+ n = $coerce_to(n, #{::Integer}, 'to_int')
1756
1798
 
1757
1799
  if (self.length === 1) {
1758
1800
  return self.slice();
@@ -1775,51 +1817,51 @@ class Array < `Array`
1775
1817
  if (self.length === 0 || self.length === 1) {
1776
1818
  return self;
1777
1819
  }
1778
- cnt = $coerce_to(cnt, #{Integer}, 'to_int');
1820
+ cnt = $coerce_to(cnt, #{::Integer}, 'to_int');
1779
1821
  }
1780
1822
  ary = rotate(cnt)
1781
1823
  replace ary
1782
1824
  end
1783
1825
 
1784
- class SampleRandom
1826
+ class self::SampleRandom
1785
1827
  def initialize(rng)
1786
1828
  @rng = rng
1787
1829
  end
1788
1830
 
1789
1831
  def rand(size)
1790
- random = `$coerce_to(#{@rng.rand(size)}, #{Integer}, 'to_int')`
1791
- raise RangeError, 'random value must be >= 0' if `random < 0`
1792
- raise RangeError, 'random value must be less than Array size' unless `random < size`
1832
+ random = `$coerce_to(#{@rng.rand(size)}, #{::Integer}, 'to_int')`
1833
+ ::Kernel.raise ::RangeError, 'random value must be >= 0' if `random < 0`
1834
+ ::Kernel.raise ::RangeError, 'random value must be less than Array size' unless `random < size`
1793
1835
 
1794
1836
  random
1795
1837
  end
1796
1838
  end
1797
1839
 
1798
1840
  def sample(count = undefined, options = undefined)
1799
- return at Kernel.rand(`self.length`) if `count === undefined`
1841
+ return at ::Kernel.rand(`self.length`) if `count === undefined`
1800
1842
 
1801
1843
  if `options === undefined`
1802
- if (o = Opal.coerce_to? count, Hash, :to_hash)
1844
+ if (o = ::Opal.coerce_to? count, ::Hash, :to_hash)
1803
1845
  options = o
1804
1846
  count = nil
1805
1847
  else
1806
1848
  options = nil
1807
- count = `$coerce_to(count, #{Integer}, 'to_int')`
1849
+ count = `$coerce_to(count, #{::Integer}, 'to_int')`
1808
1850
  end
1809
1851
  else
1810
- count = `$coerce_to(count, #{Integer}, 'to_int')`
1811
- options = `$coerce_to(options, #{Hash}, 'to_hash')`
1852
+ count = `$coerce_to(count, #{::Integer}, 'to_int')`
1853
+ options = `$coerce_to(options, #{::Hash}, 'to_hash')`
1812
1854
  end
1813
1855
 
1814
1856
  if count && `count < 0`
1815
- raise ArgumentError, 'count must be greater than 0'
1857
+ ::Kernel.raise ::ArgumentError, 'count must be greater than 0'
1816
1858
  end
1817
1859
 
1818
1860
  rng = options[:random] if options
1819
1861
  rng = if rng && rng.respond_to?(:rand)
1820
1862
  SampleRandom.new rng
1821
1863
  else
1822
- Kernel
1864
+ ::Kernel
1823
1865
  end
1824
1866
 
1825
1867
  return `self[#{rng.rand(`self.length`)}]` unless count
@@ -1936,19 +1978,16 @@ class Array < `Array`
1936
1978
  }
1937
1979
  end
1938
1980
 
1939
- alias filter select
1940
- alias filter! select!
1941
-
1942
1981
  def shift(count = undefined)
1943
1982
  if `count === undefined`
1944
1983
  return if `self.length === 0`
1945
1984
  return `shiftNoArg(self)`
1946
1985
  end
1947
1986
 
1948
- count = `$coerce_to(count, #{Integer}, 'to_int')`
1987
+ count = `$coerce_to(count, #{::Integer}, 'to_int')`
1949
1988
 
1950
1989
  if `count < 0`
1951
- raise ArgumentError, 'negative array size'
1990
+ ::Kernel.raise ::ArgumentError, 'negative array size'
1952
1991
  end
1953
1992
 
1954
1993
  return [] if `self.length === 0`
@@ -1956,8 +1995,6 @@ class Array < `Array`
1956
1995
  `self.splice(0, count)`
1957
1996
  end
1958
1997
 
1959
- alias size length
1960
-
1961
1998
  def shuffle(rng = undefined)
1962
1999
  dup.to_a.shuffle!(rng)
1963
2000
  end
@@ -1967,7 +2004,7 @@ class Array < `Array`
1967
2004
  var randgen, i = self.length, j, tmp;
1968
2005
 
1969
2006
  if (rng !== undefined) {
1970
- rng = #{Opal.coerce_to?(rng, Hash, :to_hash)};
2007
+ rng = #{::Opal.coerce_to?(rng, ::Hash, :to_hash)};
1971
2008
 
1972
2009
  if (rng !== nil) {
1973
2010
  rng = #{rng[:random]};
@@ -1983,11 +2020,11 @@ class Array < `Array`
1983
2020
  j = randgen.$rand(i).$to_int();
1984
2021
 
1985
2022
  if (j < 0) {
1986
- #{raise RangeError, "random number too small #{`j`}"}
2023
+ #{::Kernel.raise ::RangeError, "random number too small #{`j`}"}
1987
2024
  }
1988
2025
 
1989
2026
  if (j >= i) {
1990
- #{raise RangeError, "random number too big #{`j`}"}
2027
+ #{::Kernel.raise ::RangeError, "random number too big #{`j`}"}
1991
2028
  }
1992
2029
  }
1993
2030
  else {
@@ -2003,18 +2040,16 @@ class Array < `Array`
2003
2040
  }
2004
2041
  end
2005
2042
 
2006
- alias slice []
2007
-
2008
2043
  def slice!(index, length = undefined)
2009
2044
  result = nil
2010
2045
 
2011
2046
  if `length === undefined`
2012
- if Range === index
2047
+ if ::Range === index
2013
2048
  range = index
2014
2049
  result = self[range]
2015
2050
 
2016
- range_start = `$coerce_to(range.begin, #{Integer}, 'to_int')`
2017
- range_end = `$coerce_to(range.end, #{Integer}, 'to_int')`
2051
+ range_start = `range.begin === nil ? 0 : $coerce_to(range.begin, #{::Integer}, 'to_int')`
2052
+ range_end = `range.end === nil ? -1 : $coerce_to(range.end, #{::Integer}, 'to_int')`
2018
2053
 
2019
2054
  %x{
2020
2055
  if (range_start < 0) {
@@ -2031,7 +2066,7 @@ class Array < `Array`
2031
2066
  }
2032
2067
 
2033
2068
  var range_length = range_end - range_start;
2034
- if (range.excl) {
2069
+ if (range.excl && range.end !== nil) {
2035
2070
  range_end -= 1;
2036
2071
  } else {
2037
2072
  range_length += 1;
@@ -2042,7 +2077,7 @@ class Array < `Array`
2042
2077
  }
2043
2078
  }
2044
2079
  else
2045
- start = `$coerce_to(index, #{Integer}, 'to_int')`
2080
+ start = `$coerce_to(index, #{::Integer}, 'to_int')`
2046
2081
  %x{
2047
2082
  if (start < 0) {
2048
2083
  start += self.length;
@@ -2062,8 +2097,8 @@ class Array < `Array`
2062
2097
  }
2063
2098
  end
2064
2099
  else
2065
- start = `$coerce_to(index, #{Integer}, 'to_int')`
2066
- length = `$coerce_to(length, #{Integer}, 'to_int')`
2100
+ start = `$coerce_to(index, #{::Integer}, 'to_int')`
2101
+ length = `$coerce_to(length, #{::Integer}, 'to_int')`
2067
2102
 
2068
2103
  %x{
2069
2104
  if (length < 0) {
@@ -2104,7 +2139,7 @@ class Array < `Array`
2104
2139
  var ret = block(x, y);
2105
2140
 
2106
2141
  if (ret === nil) {
2107
- #{raise ArgumentError, "comparison of #{`x`.inspect} with #{`y`.inspect} failed"};
2142
+ #{::Kernel.raise ::ArgumentError, "comparison of #{`x`.inspect} with #{`y`.inspect} failed"};
2108
2143
  }
2109
2144
 
2110
2145
  return #{`ret` > 0} ? 1 : (#{`ret` < 0} ? -1 : 0);
@@ -2141,7 +2176,7 @@ class Array < `Array`
2141
2176
  def take(count)
2142
2177
  %x{
2143
2178
  if (count < 0) {
2144
- #{raise ArgumentError};
2179
+ #{::Kernel.raise ::ArgumentError};
2145
2180
  }
2146
2181
 
2147
2182
  return self.slice(0, count);
@@ -2191,12 +2226,12 @@ class Array < `Array`
2191
2226
  var i, len = array.length, ary, key, val, hash = #{{}};
2192
2227
 
2193
2228
  for (i = 0; i < len; i++) {
2194
- ary = #{Opal.coerce_to?(`array[i]`, Array, :to_ary)};
2229
+ ary = #{::Opal.coerce_to?(`array[i]`, ::Array, :to_ary)};
2195
2230
  if (!ary.$$is_array) {
2196
- #{raise TypeError, "wrong element type #{`ary`.class} at #{`i`} (expected array)"}
2231
+ #{::Kernel.raise ::TypeError, "wrong element type #{`ary`.class} at #{`i`} (expected array)"}
2197
2232
  }
2198
2233
  if (ary.length !== 2) {
2199
- #{raise ArgumentError, "wrong array length at #{`i`} (expected 2, was #{`ary`.length})"}
2234
+ #{::Kernel.raise ::ArgumentError, "wrong array length at #{`i`} (expected 2, was #{`ary`.length})"}
2200
2235
  }
2201
2236
  key = ary[0];
2202
2237
  val = ary[1];
@@ -2207,8 +2242,6 @@ class Array < `Array`
2207
2242
  }
2208
2243
  end
2209
2244
 
2210
- alias to_s inspect
2211
-
2212
2245
  def transpose
2213
2246
  return [] if empty?
2214
2247
 
@@ -2216,16 +2249,16 @@ class Array < `Array`
2216
2249
  max = nil
2217
2250
 
2218
2251
  each do |row|
2219
- row = if Array === row
2252
+ row = if ::Array === row
2220
2253
  row.to_a
2221
2254
  else
2222
- `$coerce_to(row, #{Array}, 'to_ary')`.to_a
2255
+ `$coerce_to(row, #{::Array}, 'to_ary')`.to_a
2223
2256
  end
2224
2257
 
2225
2258
  max ||= `row.length`
2226
2259
 
2227
2260
  if `row.length` != max
2228
- raise IndexError, "element size differs (#{`row.length`} should be #{max})"
2261
+ ::Kernel.raise ::IndexError, "element size differs (#{`row.length`} should be #{max})"
2229
2262
  end
2230
2263
 
2231
2264
  `row.length`.times do |i|
@@ -2310,15 +2343,13 @@ class Array < `Array`
2310
2343
  }
2311
2344
  end
2312
2345
 
2313
- alias prepend unshift
2314
-
2315
2346
  def values_at(*args)
2316
2347
  out = []
2317
2348
 
2318
2349
  args.each do |elem|
2319
- if elem.is_a? Range
2320
- finish = `$coerce_to(#{elem.last}, #{Integer}, 'to_int')`
2321
- start = `$coerce_to(#{elem.first}, #{Integer}, 'to_int')`
2350
+ if elem.is_a? ::Range
2351
+ finish = `#{elem.end} === nil ? -1 : $coerce_to(#{elem.end}, #{::Integer}, 'to_int')`
2352
+ start = `#{elem.begin} === nil ? 0 : $coerce_to(#{elem.begin}, #{::Integer}, 'to_int')`
2322
2353
 
2323
2354
  %x{
2324
2355
  if (start < 0) {
@@ -2331,7 +2362,7 @@ class Array < `Array`
2331
2362
  if (finish < 0) {
2332
2363
  finish = finish + self.length;
2333
2364
  }
2334
- if (#{elem.exclude_end?}) {
2365
+ if (#{elem.exclude_end?} && #{elem.end} !== nil) {
2335
2366
  finish--;
2336
2367
  }
2337
2368
  if (finish < start) {
@@ -2341,7 +2372,7 @@ class Array < `Array`
2341
2372
 
2342
2373
  start.upto(finish) { |i| out << at(i) }
2343
2374
  else
2344
- i = `$coerce_to(elem, #{Integer}, 'to_int')`
2375
+ i = `$coerce_to(elem, #{::Integer}, 'to_int')`
2345
2376
  out << at(i)
2346
2377
  end
2347
2378
  end
@@ -2363,8 +2394,8 @@ class Array < `Array`
2363
2394
  continue;
2364
2395
  }
2365
2396
  others[j] = #{(
2366
- Opal.coerce_to?(`o`, Array, :to_ary) ||
2367
- Opal.coerce_to!(`o`, Enumerator, :to_enum, :each)
2397
+ ::Opal.coerce_to?(`o`, ::Array, :to_ary) ||
2398
+ ::Opal.coerce_to!(`o`, ::Enumerator, :to_enum, :each)
2368
2399
  ).to_a};
2369
2400
  }
2370
2401
 
@@ -2408,10 +2439,20 @@ class Array < `Array`
2408
2439
  super.reject { |ivar| `/^@\d+$/.test(#{ivar})` || ivar == '@length' }
2409
2440
  end
2410
2441
 
2411
- Opal.pristine singleton_class, :allocate
2412
- Opal.pristine self, :copy_instance_variables, :initialize_dup
2413
-
2414
2442
  def pack(*args)
2415
- raise "To use Array#pack, you must first require 'corelib/array/pack'."
2443
+ ::Kernel.raise "To use Array#pack, you must first require 'corelib/array/pack'."
2416
2444
  end
2445
+
2446
+ alias append push
2447
+ alias filter select
2448
+ alias filter! select!
2449
+ alias map collect
2450
+ alias map! collect!
2451
+ alias prepend unshift
2452
+ alias size length
2453
+ alias slice []
2454
+ alias to_s inspect
2455
+
2456
+ ::Opal.pristine singleton_class, :allocate
2457
+ ::Opal.pristine self, :copy_instance_variables, :initialize_dup
2417
2458
  end