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.
- checksums.yaml +4 -4
- data/.eslintrc.js +1 -0
- data/.github/workflows/build.yml +0 -3
- data/.rubocop.yml +5 -1
- data/UNRELEASED.md +66 -2
- data/benchmark-ips/bm_truthy.rb +30 -0
- data/bin/opal-mspec +1 -3
- data/bin/opal-repl +1 -2
- data/bin/remove-filters +1 -4
- data/docs/compiled_ruby.md +10 -6
- data/exe/opal-repl +1 -3
- data/lib/opal/ast/builder.rb +1 -1
- data/lib/opal/cli.rb +2 -2
- data/lib/opal/cli_runners/nodejs.rb +9 -2
- data/lib/opal/cli_runners/source-map-support-browser.js +80 -216
- data/lib/opal/cli_runners/source-map-support-node.js +80 -216
- data/lib/opal/cli_runners/source-map-support.js +5 -1
- data/lib/opal/cli_runners/system_runner.rb +10 -4
- data/lib/opal/compiler.rb +3 -5
- data/lib/opal/fragment.rb +5 -1
- data/lib/opal/nodes/args/extract_block_arg.rb +1 -8
- data/lib/opal/nodes/args/extract_kwoptarg.rb +1 -3
- data/lib/opal/nodes/args/extract_optarg.rb +1 -3
- data/lib/opal/nodes/args/extract_post_arg.rb +2 -5
- data/lib/opal/nodes/args/extract_post_optarg.rb +2 -7
- data/lib/opal/nodes/args/initialize_iterarg.rb +1 -3
- data/lib/opal/nodes/args/prepare_post_args.rb +5 -1
- data/lib/opal/nodes/base.rb +3 -2
- data/lib/opal/nodes/call.rb +20 -9
- data/lib/opal/nodes/call_special.rb +50 -0
- data/lib/opal/nodes/class.rb +24 -15
- data/lib/opal/nodes/constants.rb +23 -5
- data/lib/opal/nodes/def.rb +20 -23
- data/lib/opal/nodes/defined.rb +5 -5
- data/lib/opal/nodes/definitions.rb +2 -2
- data/lib/opal/nodes/defs.rb +2 -5
- data/lib/opal/nodes/helpers.rb +48 -18
- data/lib/opal/nodes/if.rb +109 -8
- data/lib/opal/nodes/iter.rb +23 -16
- data/lib/opal/nodes/literal.rb +18 -4
- data/lib/opal/nodes/logic.rb +2 -1
- data/lib/opal/nodes/masgn.rb +4 -9
- data/lib/opal/nodes/module.rb +29 -19
- data/lib/opal/nodes/node_with_args.rb +1 -7
- data/lib/opal/nodes/scope.rb +54 -15
- data/lib/opal/nodes/singleton_class.rb +5 -3
- data/lib/opal/nodes/super.rb +3 -3
- data/lib/opal/nodes/top.rb +34 -31
- data/lib/opal/nodes/variables.rb +2 -2
- data/lib/opal/nodes/x_string.rb +3 -0
- data/lib/opal/nodes.rb +0 -1
- data/lib/opal/parser/patch.rb +75 -0
- data/lib/opal/parser/with_ruby_lexer.rb +1 -1
- data/lib/opal/regexp_anchors.rb +7 -7
- data/lib/opal/requires.rb +19 -0
- data/lib/opal/rewriters/pattern_matching.rb +1 -1
- data/lib/opal/rewriters/returnable_logic.rb +102 -4
- data/lib/opal/util.rb +2 -2
- data/lib/opal/version.rb +1 -1
- data/lib/opal.rb +1 -17
- data/opal/corelib/array/pack.rb +11 -11
- data/opal/corelib/array.rb +193 -152
- data/opal/corelib/basic_object.rb +14 -14
- data/opal/corelib/binding.rb +7 -7
- data/opal/corelib/boolean.rb +12 -15
- data/opal/corelib/class.rb +23 -1
- data/opal/corelib/comparable.rb +8 -8
- data/opal/corelib/complex/base.rb +2 -2
- data/opal/corelib/complex.rb +79 -88
- data/opal/corelib/constants.rb +9 -9
- data/opal/corelib/dir.rb +4 -3
- data/opal/corelib/enumerable.rb +140 -127
- data/opal/corelib/enumerator/arithmetic_sequence.rb +177 -0
- data/opal/corelib/enumerator/chain.rb +42 -0
- data/opal/corelib/enumerator/generator.rb +35 -0
- data/opal/corelib/enumerator/lazy.rb +243 -0
- data/opal/corelib/enumerator/yielder.rb +36 -0
- data/opal/corelib/enumerator.rb +45 -300
- data/opal/corelib/error/errno.rb +47 -0
- data/opal/corelib/error.rb +62 -60
- data/opal/corelib/file.rb +26 -12
- data/opal/corelib/hash.rb +98 -107
- data/opal/corelib/helpers.rb +62 -13
- data/opal/corelib/io.rb +47 -34
- data/opal/corelib/kernel/format.rb +29 -29
- data/opal/corelib/kernel.rb +86 -83
- data/opal/corelib/main.rb +14 -12
- data/opal/corelib/marshal/read_buffer.rb +15 -15
- data/opal/corelib/marshal/write_buffer.rb +45 -44
- data/opal/corelib/marshal.rb +3 -3
- data/opal/corelib/math.rb +50 -50
- data/opal/corelib/method.rb +12 -8
- data/opal/corelib/module.rb +96 -79
- data/opal/corelib/nil.rb +9 -11
- data/opal/corelib/number.rb +113 -118
- data/opal/corelib/numeric.rb +37 -33
- data/opal/corelib/object_space.rb +11 -10
- data/opal/corelib/pack_unpack/format_string_parser.rb +3 -3
- data/opal/corelib/pattern_matching/base.rb +7 -7
- data/opal/corelib/pattern_matching.rb +1 -1
- data/opal/corelib/proc.rb +15 -16
- data/opal/corelib/process/base.rb +2 -2
- data/opal/corelib/process/status.rb +21 -0
- data/opal/corelib/process.rb +5 -5
- data/opal/corelib/random/formatter.rb +11 -11
- data/opal/corelib/random/math_random.js.rb +1 -1
- data/opal/corelib/random/mersenne_twister.rb +3 -3
- data/opal/corelib/random/seedrandom.js.rb +3 -3
- data/opal/corelib/random.rb +17 -17
- data/opal/corelib/range.rb +51 -35
- data/opal/corelib/rational/base.rb +4 -4
- data/opal/corelib/rational.rb +61 -62
- data/opal/corelib/regexp.rb +47 -38
- data/opal/corelib/runtime.js +245 -139
- data/opal/corelib/string/encoding.rb +21 -21
- data/opal/corelib/string/unpack.rb +19 -14
- data/opal/corelib/string.rb +135 -128
- data/opal/corelib/struct.rb +59 -46
- data/opal/corelib/time.rb +47 -57
- data/opal/corelib/trace_point.rb +2 -2
- data/opal/corelib/unsupported.rb +31 -120
- data/opal/corelib/variables.rb +3 -3
- data/opal/opal/base.rb +9 -8
- data/opal/opal/full.rb +8 -8
- data/opal/opal/mini.rb +17 -17
- data/opal/opal.rb +17 -18
- data/opal.gemspec +1 -1
- data/spec/filters/bugs/array.rb +4 -24
- data/spec/filters/bugs/bigdecimal.rb +0 -23
- data/spec/filters/bugs/binding.rb +0 -1
- data/spec/filters/bugs/boolean.rb +3 -0
- data/spec/filters/bugs/class.rb +2 -0
- data/spec/filters/bugs/date.rb +0 -5
- data/spec/filters/bugs/encoding.rb +8 -50
- data/spec/filters/bugs/enumerable.rb +4 -1
- data/spec/filters/bugs/enumerator.rb +3 -36
- data/spec/filters/bugs/exception.rb +0 -2
- data/spec/filters/bugs/file.rb +0 -2
- data/spec/filters/bugs/float.rb +0 -3
- data/spec/filters/bugs/hash.rb +5 -3
- data/spec/filters/bugs/integer.rb +2 -3
- data/spec/filters/bugs/kernel.rb +2 -31
- data/spec/filters/bugs/language.rb +29 -49
- data/spec/filters/bugs/main.rb +0 -2
- data/spec/filters/bugs/marshal.rb +2 -3
- data/spec/filters/bugs/matrix.rb +0 -36
- data/spec/filters/bugs/module.rb +7 -61
- data/spec/filters/bugs/numeric.rb +0 -7
- data/spec/filters/bugs/objectspace.rb +1 -1
- data/spec/filters/bugs/pack_unpack.rb +0 -4
- data/spec/filters/bugs/proc.rb +0 -9
- data/spec/filters/bugs/random.rb +0 -5
- data/spec/filters/bugs/range.rb +1 -6
- data/spec/filters/bugs/regexp.rb +0 -3
- data/spec/filters/bugs/set.rb +8 -1
- data/spec/filters/bugs/string.rb +9 -34
- data/spec/filters/bugs/stringscanner.rb +8 -7
- data/spec/filters/bugs/struct.rb +2 -3
- data/spec/filters/bugs/symbol.rb +0 -1
- data/spec/filters/bugs/time.rb +0 -8
- data/spec/filters/bugs/unboundmethod.rb +0 -8
- data/spec/filters/bugs/warnings.rb +1 -7
- data/spec/filters/unsupported/freeze.rb +24 -0
- data/spec/filters/unsupported/integer.rb +1 -0
- data/spec/filters/unsupported/kernel.rb +12 -0
- data/spec/filters/unsupported/privacy.rb +3 -0
- data/spec/filters/unsupported/string.rb +2 -0
- data/spec/lib/builder_spec.rb +2 -2
- data/spec/lib/cli_spec.rb +1 -1
- data/spec/lib/compiler_spec.rb +37 -37
- data/spec/lib/simple_server_spec.rb +2 -2
- data/spec/lib/source_map/file_spec.rb +1 -1
- data/spec/opal/compiler/irb_spec.rb +2 -2
- data/spec/opal/core/kernel/puts_spec.rb +90 -0
- data/spec/opal/core/language/super_spec.rb +24 -0
- data/spec/ruby_specs +4 -2
- data/spec/support/rewriters_helper.rb +1 -1
- data/stdlib/bigdecimal.rb +7 -11
- data/stdlib/buffer/view.rb +2 -2
- data/stdlib/buffer.rb +2 -2
- data/stdlib/date.rb +5 -6
- data/stdlib/erb.rb +1 -0
- data/stdlib/js.rb +2 -1
- data/stdlib/native.rb +7 -8
- data/stdlib/nodejs/argf.rb +4 -4
- data/stdlib/nodejs/base.rb +29 -0
- data/stdlib/nodejs/dir.rb +1 -1
- data/stdlib/nodejs/env.rb +6 -9
- data/stdlib/nodejs/file.rb +23 -17
- data/stdlib/nodejs/fileutils.rb +3 -3
- data/stdlib/nodejs/io.rb +2 -20
- data/stdlib/nodejs/irb.rb +0 -0
- data/stdlib/nodejs/kernel.rb +2 -37
- data/stdlib/nodejs.rb +1 -3
- data/stdlib/opal/miniracer.rb +2 -0
- data/stdlib/opal/platform.rb +6 -13
- data/stdlib/opal/replutils.rb +16 -5
- data/stdlib/opal-parser.rb +2 -2
- data/stdlib/optparse/ac.rb +54 -0
- data/stdlib/optparse/date.rb +14 -0
- data/stdlib/optparse/kwargs.rb +22 -0
- data/stdlib/optparse/shellwords.rb +7 -0
- data/stdlib/optparse/time.rb +15 -0
- data/stdlib/optparse/uri.rb +7 -0
- data/stdlib/optparse/version.rb +69 -0
- data/stdlib/optparse.rb +2279 -0
- data/stdlib/pathname.rb +5 -6
- data/stdlib/pp.rb +18 -2
- data/stdlib/promise/v2.rb +18 -22
- data/stdlib/promise.rb +15 -21
- data/stdlib/set.rb +32 -32
- data/stdlib/shellwords.rb +240 -0
- data/stdlib/stringio.rb +3 -6
- data/stdlib/strscan.rb +5 -8
- data/stdlib/template.rb +2 -2
- data/stdlib/thread.rb +7 -9
- data/tasks/performance.rake +5 -2
- data/tasks/testing/mspec_special_calls.rb +0 -12
- data/tasks/testing.rake +55 -37
- data/test/nodejs/test_file.rb +11 -0
- metadata +55 -10
- 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
|
-
|
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 =
|
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 =
|
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
|
-
|
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
|
-
|
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
|
-
|
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 =
|
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
|
-
|
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 (
|
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
|
-
|
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 =
|
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 (
|
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
|
-
|
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 =
|
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
|
-
|
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 =
|
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
|
-
|
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
|
-
|
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 =
|
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
|
-
|
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 (
|
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
|
-
|
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 =
|
798
|
+
value = $hash_get(self, key);
|
810
799
|
|
811
800
|
if (value === undefined) {
|
812
|
-
|
801
|
+
$hash_put(self, key, other_value);
|
813
802
|
continue;
|
814
803
|
}
|
815
804
|
|
816
|
-
|
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 =
|
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
|
-
|
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 (
|
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
|
-
|
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
|
-
|
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 =
|
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
|
-
|
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 (
|
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,
|
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 =
|
1006
|
+
var result = $hash();
|
1023
1007
|
|
1024
1008
|
for (var i = 0, length = keys.length; i < length; i++) {
|
1025
|
-
var key = keys[i], value =
|
1009
|
+
var key = keys[i], value = $hash_get(self, key);
|
1026
1010
|
|
1027
1011
|
if (value !== undefined) {
|
1028
|
-
|
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
|
-
|
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 =
|
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 =
|
1090
|
+
key = $yield1(block, key);
|
1111
1091
|
|
1112
|
-
|
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 =
|
1116
|
+
new_key = $yield1(block, key);
|
1137
1117
|
|
1138
|
-
|
1139
|
-
|
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 =
|
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 =
|
1142
|
+
value = $yield1(block, value);
|
1163
1143
|
|
1164
|
-
|
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 =
|
1165
|
+
value = $yield1(block, value);
|
1186
1166
|
|
1187
|
-
|
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
|