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
data/opal/corelib/hash.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # helpers: yield1, hash, hash_init, hash_get, hash_put, hash_delete
2
+
1
3
  require 'corelib/enumerable'
2
4
 
3
5
  # ---
@@ -8,8 +10,8 @@ require 'corelib/enumerable'
8
10
  # - $$keys [Array<hash-bucket>] the list of all keys
9
11
  # - $$proc [Proc,null,nil] the default proc used for missing keys
10
12
  # - hash-bucket [JS::Object] an element of a linked list that holds hash values, keys are `{key:,key_hash:,value:,next:}`
11
- class Hash
12
- include Enumerable
13
+ class ::Hash
14
+ include ::Enumerable
13
15
 
14
16
  # Mark all hash instances as valid hashes (used to check keyword args, etc)
15
17
  `self.$$prototype.$$is_hash = true`
@@ -19,14 +21,14 @@ class Hash
19
21
  var hash, argc = argv.length, i;
20
22
 
21
23
  if (argc === 1) {
22
- hash = #{Opal.coerce_to?(argv[0], Hash, :to_hash)};
24
+ hash = #{::Opal.coerce_to?(argv[0], ::Hash, :to_hash)};
23
25
  if (hash !== nil) {
24
26
  return #{allocate.merge!(`hash`)};
25
27
  }
26
28
 
27
- argv = #{Opal.coerce_to?(argv[0], Array, :to_ary)};
29
+ argv = #{::Opal.coerce_to?(argv[0], ::Array, :to_ary)};
28
30
  if (argv === nil) {
29
- #{raise ArgumentError, 'odd number of arguments for Hash'}
31
+ #{::Kernel.raise ::ArgumentError, 'odd number of arguments for Hash'}
30
32
  }
31
33
 
32
34
  argc = argv.length;
@@ -42,7 +44,7 @@ class Hash
42
44
  hash.$store(argv[i][0], argv[i][1]);
43
45
  break;
44
46
  default:
45
- #{raise ArgumentError, "invalid number of elements (#{`argv[i].length`} for 1..2)"}
47
+ #{::Kernel.raise ::ArgumentError, "invalid number of elements (#{`argv[i].length`} for 1..2)"}
46
48
  }
47
49
  }
48
50
 
@@ -50,7 +52,7 @@ class Hash
50
52
  }
51
53
 
52
54
  if (argc % 2 !== 0) {
53
- #{raise ArgumentError, 'odd number of arguments for Hash'}
55
+ #{::Kernel.raise ::ArgumentError, 'odd number of arguments for Hash'}
54
56
  }
55
57
 
56
58
  hash = #{allocate};
@@ -67,7 +69,7 @@ class Hash
67
69
  %x{
68
70
  var hash = new self.$$constructor();
69
71
 
70
- Opal.hash_init(hash);
72
+ $hash_init(hash);
71
73
 
72
74
  hash.$$none = nil;
73
75
  hash.$$proc = nil;
@@ -77,13 +79,13 @@ class Hash
77
79
  end
78
80
 
79
81
  def self.try_convert(obj)
80
- Opal.coerce_to?(obj, Hash, :to_hash)
82
+ ::Opal.coerce_to?(obj, ::Hash, :to_hash)
81
83
  end
82
84
 
83
85
  def initialize(defaults = undefined, &block)
84
86
  %x{
85
87
  if (defaults !== undefined && block !== nil) {
86
- #{raise ArgumentError, 'wrong number of arguments (1 for 0)'}
88
+ #{::Kernel.raise ::ArgumentError, 'wrong number of arguments (1 for 0)'}
87
89
  }
88
90
  self.$$none = (defaults === undefined ? nil : defaults);
89
91
  self.$$proc = block;
@@ -114,7 +116,7 @@ class Hash
114
116
  other_value = other.$$smap[key];
115
117
  } else {
116
118
  value = key.value;
117
- other_value = Opal.hash_get(other, key.key);
119
+ other_value = $hash_get(other, key.key);
118
120
  }
119
121
 
120
122
  if (other_value === undefined || !value['$eql?'](other_value)) {
@@ -127,7 +129,7 @@ class Hash
127
129
  end
128
130
 
129
131
  def >=(other)
130
- other = Opal.coerce_to!(other, Hash, :to_hash)
132
+ other = ::Opal.coerce_to!(other, ::Hash, :to_hash)
131
133
 
132
134
  %x{
133
135
  if (self.$$keys.length < other.$$keys.length) {
@@ -152,7 +154,7 @@ class Hash
152
154
  end
153
155
 
154
156
  def >(other)
155
- other = Opal.coerce_to!(other, Hash, :to_hash)
157
+ other = ::Opal.coerce_to!(other, ::Hash, :to_hash)
156
158
 
157
159
  %x{
158
160
  if (self.$$keys.length <= other.$$keys.length) {
@@ -164,18 +166,18 @@ class Hash
164
166
  end
165
167
 
166
168
  def <(other)
167
- other = Opal.coerce_to!(other, Hash, :to_hash)
169
+ other = ::Opal.coerce_to!(other, ::Hash, :to_hash)
168
170
  other > self
169
171
  end
170
172
 
171
173
  def <=(other)
172
- other = Opal.coerce_to!(other, Hash, :to_hash)
174
+ other = ::Opal.coerce_to!(other, ::Hash, :to_hash)
173
175
  other >= self
174
176
  end
175
177
 
176
178
  def [](key)
177
179
  %x{
178
- var value = Opal.hash_get(self, key);
180
+ var value = $hash_get(self, key);
179
181
 
180
182
  if (value !== undefined) {
181
183
  return value;
@@ -187,7 +189,7 @@ class Hash
187
189
 
188
190
  def []=(key, value)
189
191
  %x{
190
- Opal.hash_put(self, key, value);
192
+ $hash_put(self, key, value);
191
193
  return value;
192
194
  }
193
195
  end
@@ -214,7 +216,7 @@ class Hash
214
216
 
215
217
  def clear
216
218
  %x{
217
- Opal.hash_init(self);
219
+ $hash_init(self);
218
220
  return self;
219
221
  }
220
222
  end
@@ -223,7 +225,7 @@ class Hash
223
225
  %x{
224
226
  var hash = new self.$$class();
225
227
 
226
- Opal.hash_init(hash);
228
+ $hash_init(hash);
227
229
  Opal.hash_clone(self, hash);
228
230
 
229
231
  return hash;
@@ -232,7 +234,7 @@ class Hash
232
234
 
233
235
  def compact
234
236
  %x{
235
- var hash = Opal.hash();
237
+ var hash = $hash();
236
238
 
237
239
  for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) {
238
240
  key = keys[i];
@@ -245,7 +247,7 @@ class Hash
245
247
  }
246
248
 
247
249
  if (value !== nil) {
248
- Opal.hash_put(hash, key, value);
250
+ $hash_put(hash, key, value);
249
251
  }
250
252
  }
251
253
 
@@ -268,7 +270,7 @@ class Hash
268
270
  }
269
271
 
270
272
  if (value === nil) {
271
- if (Opal.hash_delete(self, key) !== undefined) {
273
+ if ($hash_delete(self, key) !== undefined) {
272
274
  changes_were_made = true;
273
275
  length--;
274
276
  i--;
@@ -294,7 +296,7 @@ class Hash
294
296
  for(i = 0, ii = keys.length; i < ii; i++) {
295
297
  key = keys[i];
296
298
  if (!key.$$is_string) key = key.key;
297
- Opal.hash_put(identity_hash, key, Opal.hash_get(self, key));
299
+ $hash_put(identity_hash, key, $hash_get(self, key));
298
300
  }
299
301
 
300
302
  self.$$by_identity = true;
@@ -343,10 +345,10 @@ class Hash
343
345
  var proc = default_proc;
344
346
 
345
347
  if (proc !== nil) {
346
- proc = #{Opal.coerce_to!(`proc`, Proc, :to_proc)};
348
+ proc = #{::Opal.coerce_to!(`proc`, ::Proc, :to_proc)};
347
349
 
348
350
  if (#{`proc`.lambda?} && #{`proc`.arity.abs} !== 2) {
349
- #{raise TypeError, 'default_proc takes two arguments'};
351
+ #{::Kernel.raise ::TypeError, 'default_proc takes two arguments'};
350
352
  }
351
353
  }
352
354
 
@@ -359,7 +361,7 @@ class Hash
359
361
 
360
362
  def delete(key, &block)
361
363
  %x{
362
- var value = Opal.hash_delete(self, key);
364
+ var value = $hash_delete(self, key);
363
365
 
364
366
  if (value !== undefined) {
365
367
  return value;
@@ -390,7 +392,7 @@ class Hash
390
392
  obj = block(key, value);
391
393
 
392
394
  if (obj !== false && obj !== nil) {
393
- if (Opal.hash_delete(self, key) !== undefined) {
395
+ if ($hash_delete(self, key) !== undefined) {
394
396
  length--;
395
397
  i--;
396
398
  }
@@ -401,8 +403,6 @@ class Hash
401
403
  }
402
404
  end
403
405
 
404
- alias dup clone
405
-
406
406
  def dig(key, *keys)
407
407
  item = self[key]
408
408
 
@@ -413,7 +413,7 @@ class Hash
413
413
  }
414
414
 
415
415
  unless item.respond_to?(:dig)
416
- raise TypeError, "#{item.class} does not have #dig method"
416
+ ::Kernel.raise ::TypeError, "#{item.class} does not have #dig method"
417
417
  end
418
418
 
419
419
  item.dig(*keys)
@@ -433,7 +433,7 @@ class Hash
433
433
  key = key.key;
434
434
  }
435
435
 
436
- Opal.yield1(block, [key, value]);
436
+ $yield1(block, [key, value]);
437
437
  }
438
438
 
439
439
  return self;
@@ -454,8 +454,6 @@ class Hash
454
454
  }
455
455
  end
456
456
 
457
- alias each_pair each
458
-
459
457
  def each_value(&block)
460
458
  return enum_for(:each_value) { size } unless block
461
459
 
@@ -474,8 +472,6 @@ class Hash
474
472
  `self.$$keys.length === 0`
475
473
  end
476
474
 
477
- alias eql? ==
478
-
479
475
  def except(*keys)
480
476
  dup.except!(*keys)
481
477
  end
@@ -487,7 +483,7 @@ class Hash
487
483
 
488
484
  def fetch(key, defaults = undefined, &block)
489
485
  %x{
490
- var value = Opal.hash_get(self, key);
486
+ var value = $hash_get(self, key);
491
487
 
492
488
  if (value !== undefined) {
493
489
  return value;
@@ -502,7 +498,7 @@ class Hash
502
498
  }
503
499
  }
504
500
 
505
- raise KeyError.new("key not found: #{key.inspect}", key: key, receiver: self)
501
+ ::Kernel.raise ::KeyError.new("key not found: #{key.inspect}", key: key, receiver: self)
506
502
  end
507
503
 
508
504
  def fetch_values(*keys, &block)
@@ -510,7 +506,7 @@ class Hash
510
506
  end
511
507
 
512
508
  def flatten(level = 1)
513
- level = Opal.coerce_to!(level, Integer, :to_int)
509
+ level = ::Opal.coerce_to!(level, ::Integer, :to_int)
514
510
 
515
511
  %x{
516
512
  var result = [];
@@ -545,7 +541,7 @@ class Hash
545
541
  end
546
542
 
547
543
  def has_key?(key)
548
- `Opal.hash_get(self, key) !== undefined`
544
+ `$hash_get(self, key) !== undefined`
549
545
  end
550
546
 
551
547
  def has_value?(value)
@@ -607,8 +603,6 @@ class Hash
607
603
  }
608
604
  end
609
605
 
610
- alias include? has_key?
611
-
612
606
  def index(object)
613
607
  %x{
614
608
  for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) {
@@ -636,7 +630,7 @@ class Hash
636
630
 
637
631
  for (var i = 0, length = args.length, key, value; i < length; i++) {
638
632
  key = args[i];
639
- value = Opal.hash_get(self, key);
633
+ value = $hash_get(self, key);
640
634
 
641
635
  if (value === undefined) {
642
636
  result.push(#{default});
@@ -650,8 +644,6 @@ class Hash
650
644
  }
651
645
  end
652
646
 
653
- alias indices indexes
654
-
655
647
  `var inspect_ids`
656
648
 
657
649
  def inspect
@@ -659,8 +651,10 @@ class Hash
659
651
  var top = (inspect_ids === undefined),
660
652
  hash_id = self.$object_id(),
661
653
  result = [];
654
+ }
662
655
 
663
- try {
656
+ begin
657
+ %x{
664
658
  if (top) {
665
659
  inspect_ids = {};
666
660
  }
@@ -681,22 +675,23 @@ class Hash
681
675
  key = key.key;
682
676
  }
683
677
 
684
- result.push(key.$inspect() + '=>' + value.$inspect());
678
+ key = #{Opal.inspect(`key`)}
679
+ value = #{Opal.inspect(`value`)}
680
+
681
+ result.push(key + '=>' + value);
685
682
  }
686
683
 
687
684
  return '{' + result.join(', ') + '}';
688
-
689
- } finally {
690
- if (top) {
691
- inspect_ids = undefined;
692
- }
693
685
  }
694
- }
686
+ nil
687
+ ensure
688
+ `if (top) inspect_ids = undefined`
689
+ end
695
690
  end
696
691
 
697
692
  def invert
698
693
  %x{
699
- var hash = Opal.hash();
694
+ var hash = $hash();
700
695
 
701
696
  for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) {
702
697
  key = keys[i];
@@ -708,7 +703,7 @@ class Hash
708
703
  key = key.key;
709
704
  }
710
705
 
711
- Opal.hash_put(hash, value, key);
706
+ $hash_put(hash, value, key);
712
707
  }
713
708
 
714
709
  return hash;
@@ -732,7 +727,7 @@ class Hash
732
727
  obj = block(key, value);
733
728
 
734
729
  if (obj === false || obj === nil) {
735
- if (Opal.hash_delete(self, key) !== undefined) {
730
+ if ($hash_delete(self, key) !== undefined) {
736
731
  length--;
737
732
  i--;
738
733
  }
@@ -743,10 +738,6 @@ class Hash
743
738
  }
744
739
  end
745
740
 
746
- alias key index
747
-
748
- alias key? has_key?
749
-
750
741
  def keys
751
742
  %x{
752
743
  var result = [];
@@ -769,8 +760,6 @@ class Hash
769
760
  `self.$$keys.length`
770
761
  end
771
762
 
772
- alias member? has_key?
773
-
774
763
  def merge(*others, &block)
775
764
  dup.merge!(*others, &block)
776
765
  end
@@ -779,7 +768,7 @@ class Hash
779
768
  %x{
780
769
  var i, j, other, other_keys, length, key, value, other_value;
781
770
  for (i = 0; i < others.length; ++i) {
782
- other = #{Opal.coerce_to!(`others[i]`, Hash, :to_hash)};
771
+ other = #{::Opal.coerce_to!(`others[i]`, ::Hash, :to_hash)};
783
772
  other_keys = other.$$keys, length = other_keys.length;
784
773
 
785
774
  if (block === nil) {
@@ -793,7 +782,7 @@ class Hash
793
782
  key = key.key;
794
783
  }
795
784
 
796
- Opal.hash_put(self, key, other_value);
785
+ $hash_put(self, key, other_value);
797
786
  }
798
787
  } else {
799
788
  for (j = 0; j < length; j++) {
@@ -806,14 +795,14 @@ class Hash
806
795
  key = key.key;
807
796
  }
808
797
 
809
- value = Opal.hash_get(self, key);
798
+ value = $hash_get(self, key);
810
799
 
811
800
  if (value === undefined) {
812
- Opal.hash_put(self, key, other_value);
801
+ $hash_put(self, key, other_value);
813
802
  continue;
814
803
  }
815
804
 
816
- Opal.hash_put(self, key, block(key, value, other_value));
805
+ $hash_put(self, key, block(key, value, other_value));
817
806
  }
818
807
  }
819
808
  }
@@ -854,7 +843,7 @@ class Hash
854
843
  return enum_for(:reject) { size } unless block
855
844
 
856
845
  %x{
857
- var hash = Opal.hash();
846
+ var hash = $hash();
858
847
 
859
848
  for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) {
860
849
  key = keys[i];
@@ -869,7 +858,7 @@ class Hash
869
858
  obj = block(key, value);
870
859
 
871
860
  if (obj === false || obj === nil) {
872
- Opal.hash_put(hash, key, value);
861
+ $hash_put(hash, key, value);
873
862
  }
874
863
  }
875
864
 
@@ -896,7 +885,7 @@ class Hash
896
885
  obj = block(key, value);
897
886
 
898
887
  if (obj !== false && obj !== nil) {
899
- if (Opal.hash_delete(self, key) !== undefined) {
888
+ if ($hash_delete(self, key) !== undefined) {
900
889
  changes_were_made = true;
901
890
  length--;
902
891
  i--;
@@ -909,10 +898,10 @@ class Hash
909
898
  end
910
899
 
911
900
  def replace(other)
912
- other = Opal.coerce_to!(other, Hash, :to_hash)
901
+ other = ::Opal.coerce_to!(other, ::Hash, :to_hash)
913
902
 
914
903
  %x{
915
- Opal.hash_init(self);
904
+ $hash_init(self);
916
905
 
917
906
  for (var i = 0, other_keys = other.$$keys, length = other_keys.length, key, value, other_value; i < length; i++) {
918
907
  key = other_keys[i];
@@ -924,7 +913,7 @@ class Hash
924
913
  key = key.key;
925
914
  }
926
915
 
927
- Opal.hash_put(self, key, other_value);
916
+ $hash_put(self, key, other_value);
928
917
  }
929
918
  }
930
919
 
@@ -941,7 +930,7 @@ class Hash
941
930
  return enum_for(:select) { size } unless block
942
931
 
943
932
  %x{
944
- var hash = Opal.hash();
933
+ var hash = $hash();
945
934
 
946
935
  for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) {
947
936
  key = keys[i];
@@ -956,7 +945,7 @@ class Hash
956
945
  obj = block(key, value);
957
946
 
958
947
  if (obj !== false && obj !== nil) {
959
- Opal.hash_put(hash, key, value);
948
+ $hash_put(hash, key, value);
960
949
  }
961
950
  }
962
951
 
@@ -983,7 +972,7 @@ class Hash
983
972
  obj = block(key, value);
984
973
 
985
974
  if (obj === false || obj === nil) {
986
- if (Opal.hash_delete(self, key) !== undefined) {
975
+ if ($hash_delete(self, key) !== undefined) {
987
976
  length--;
988
977
  i--;
989
978
  }
@@ -995,9 +984,6 @@ class Hash
995
984
  }
996
985
  end
997
986
 
998
- alias filter select
999
- alias filter! select!
1000
-
1001
987
  def shift
1002
988
  %x{
1003
989
  var keys = self.$$keys,
@@ -1008,24 +994,22 @@ class Hash
1008
994
 
1009
995
  key = key.$$is_string ? key : key.key;
1010
996
 
1011
- return [key, Opal.hash_delete(self, key)];
997
+ return [key, $hash_delete(self, key)];
1012
998
  }
1013
999
 
1014
1000
  return self.$default(nil);
1015
1001
  }
1016
1002
  end
1017
1003
 
1018
- alias size length
1019
-
1020
1004
  def slice(*keys)
1021
1005
  %x{
1022
- var result = Opal.hash();
1006
+ var result = $hash();
1023
1007
 
1024
1008
  for (var i = 0, length = keys.length; i < length; i++) {
1025
- var key = keys[i], value = Opal.hash_get(self, key);
1009
+ var key = keys[i], value = $hash_get(self, key);
1026
1010
 
1027
1011
  if (value !== undefined) {
1028
- Opal.hash_put(result, key, value);
1012
+ $hash_put(result, key, value);
1029
1013
  }
1030
1014
  }
1031
1015
 
@@ -1033,8 +1017,6 @@ class Hash
1033
1017
  }
1034
1018
  end
1035
1019
 
1036
- alias store []=
1037
-
1038
1020
  def to_a
1039
1021
  %x{
1040
1022
  var result = [];
@@ -1066,7 +1048,7 @@ class Hash
1066
1048
 
1067
1049
  var hash = new Opal.Hash();
1068
1050
 
1069
- Opal.hash_init(hash);
1051
+ $hash_init(hash);
1070
1052
  Opal.hash_clone(self, hash);
1071
1053
 
1072
1054
  return hash;
@@ -1081,7 +1063,7 @@ class Hash
1081
1063
  proc do |key = undefined|
1082
1064
  %x{
1083
1065
  if (key == null) {
1084
- #{raise ArgumentError, 'no key given'}
1066
+ #{::Kernel.raise ::ArgumentError, 'no key given'}
1085
1067
  }
1086
1068
  }
1087
1069
 
@@ -1089,13 +1071,11 @@ class Hash
1089
1071
  end
1090
1072
  end
1091
1073
 
1092
- alias to_s inspect
1093
-
1094
1074
  def transform_keys(&block)
1095
1075
  return enum_for(:transform_keys) { size } unless block
1096
1076
 
1097
1077
  %x{
1098
- var result = Opal.hash();
1078
+ var result = $hash();
1099
1079
 
1100
1080
  for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) {
1101
1081
  key = keys[i];
@@ -1107,9 +1087,9 @@ class Hash
1107
1087
  key = key.key;
1108
1088
  }
1109
1089
 
1110
- key = Opal.yield1(block, key);
1090
+ key = $yield1(block, key);
1111
1091
 
1112
- Opal.hash_put(result, key, value);
1092
+ $hash_put(result, key, value);
1113
1093
  }
1114
1094
 
1115
1095
  return result;
@@ -1133,10 +1113,10 @@ class Hash
1133
1113
  key = key.key;
1134
1114
  }
1135
1115
 
1136
- new_key = Opal.yield1(block, key);
1116
+ new_key = $yield1(block, key);
1137
1117
 
1138
- Opal.hash_delete(self, key);
1139
- Opal.hash_put(self, new_key, value);
1118
+ $hash_delete(self, key);
1119
+ $hash_put(self, new_key, value);
1140
1120
  }
1141
1121
 
1142
1122
  return self;
@@ -1147,7 +1127,7 @@ class Hash
1147
1127
  return enum_for(:transform_values) { size } unless block
1148
1128
 
1149
1129
  %x{
1150
- var result = Opal.hash();
1130
+ var result = $hash();
1151
1131
 
1152
1132
  for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) {
1153
1133
  key = keys[i];
@@ -1159,9 +1139,9 @@ class Hash
1159
1139
  key = key.key;
1160
1140
  }
1161
1141
 
1162
- value = Opal.yield1(block, value);
1142
+ value = $yield1(block, value);
1163
1143
 
1164
- Opal.hash_put(result, key, value);
1144
+ $hash_put(result, key, value);
1165
1145
  }
1166
1146
 
1167
1147
  return result;
@@ -1182,21 +1162,15 @@ class Hash
1182
1162
  key = key.key;
1183
1163
  }
1184
1164
 
1185
- value = Opal.yield1(block, value);
1165
+ value = $yield1(block, value);
1186
1166
 
1187
- Opal.hash_put(self, key, value);
1167
+ $hash_put(self, key, value);
1188
1168
  }
1189
1169
 
1190
1170
  return self;
1191
1171
  }
1192
1172
  end
1193
1173
 
1194
- alias update merge!
1195
-
1196
- alias value? has_value?
1197
-
1198
- alias values_at indexes
1199
-
1200
1174
  def values
1201
1175
  %x{
1202
1176
  var result = [];
@@ -1214,4 +1188,21 @@ class Hash
1214
1188
  return result;
1215
1189
  }
1216
1190
  end
1191
+
1192
+ alias dup clone
1193
+ alias each_pair each
1194
+ alias eql? ==
1195
+ alias filter select
1196
+ alias filter! select!
1197
+ alias include? has_key?
1198
+ alias indices indexes
1199
+ alias key index
1200
+ alias key? has_key?
1201
+ alias member? has_key?
1202
+ alias size length
1203
+ alias store []=
1204
+ alias to_s inspect
1205
+ alias update merge!
1206
+ alias value? has_value?
1207
+ alias values_at indexes
1217
1208
  end