opal 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -0
- data/lib/opal/nodes/args/parameters.rb +18 -11
- data/lib/opal/nodes/args.rb +0 -28
- data/lib/opal/nodes/super.rb +0 -9
- data/lib/opal/rewriter.rb +2 -0
- data/lib/opal/rewriters/deduplicate_arg_name.rb +48 -0
- data/lib/opal/rewriters/inline_args.rb +1 -13
- data/lib/opal/version.rb +1 -1
- data/opal/corelib/array.rb +26 -22
- data/opal/corelib/constants.rb +2 -2
- data/opal/corelib/kernel.rb +11 -14
- data/opal/corelib/module.rb +4 -4
- data/opal/corelib/proc.rb +4 -6
- data/opal/corelib/runtime.js +30 -21
- data/spec/filters/bugs/array.rb +0 -36
- data/spec/filters/bugs/enumerable.rb +1 -3
- data/spec/filters/bugs/kernel.rb +6 -8
- data/spec/filters/bugs/ruby-32.rb +2 -2
- data/spec/filters/unsupported/kernel.rb +0 -4
- data/spec/opal/core/language/arguments/underscore_arg_spec.rb +89 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8af8b2b4d485065e48d45e66e00075cf3b2f3d58c358355f5cbf5c97c46cd607
|
4
|
+
data.tar.gz: 87b7e4d8443eeb45953d48ca6ebb321b27269d9e7bbe2c4770c5189bcd44bcf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 615891333955fa65566ccad7f18d7a2a65905076db6268775bb5e9f06604b56e4ebfcb8fc05d181353c1bcfbba64c195c2eb4f71b37f805e9f7984f990e56a41
|
7
|
+
data.tar.gz: 1566eb09bf04acbcb49c7386ab9259cd13f8d94810e9dfecadf109b57ad2eaf479d1df419359a4a776b11aba2c7cc97d7df761c9ade46a2b8512d2718503ab69
|
data/CHANGELOG.md
CHANGED
@@ -16,6 +16,38 @@ Changes are grouped as follows:
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
+
## [1.8.1](https://github.com/opal/opal/compare/v1.8.0...v1.8.1) - 2023-11-09
|
20
|
+
|
21
|
+
|
22
|
+
<!--
|
23
|
+
### Internal
|
24
|
+
### Changed
|
25
|
+
### Added
|
26
|
+
### Removed
|
27
|
+
### Deprecated
|
28
|
+
### Performance
|
29
|
+
### Fixed
|
30
|
+
-->
|
31
|
+
|
32
|
+
|
33
|
+
### Fixed
|
34
|
+
|
35
|
+
- `Array` methods should handle elements inserted during the iteration ([#2602](https://github.com/opal/opal/pull/2602))
|
36
|
+
- Assign correct values to duplicated underscore parameters ([#2606](https://github.com/opal/opal/pull/2606))
|
37
|
+
|
38
|
+
|
39
|
+
### Added
|
40
|
+
|
41
|
+
- Support an `IO` argument of `Kernel.printf` ([#2605](https://github.com/opal/opal/pull/2605))
|
42
|
+
|
43
|
+
|
44
|
+
### Performance
|
45
|
+
|
46
|
+
- Fix a performance regression introduced by freezing support ([#2609](https://github.com/opal/opal/pull/2609))
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
19
51
|
## [1.8.0](https://github.com/opal/opal/compare/v1.7.4...v1.8.0) - 2023-10-26
|
20
52
|
|
21
53
|
|
@@ -10,25 +10,28 @@ module Opal
|
|
10
10
|
|
11
11
|
def to_code
|
12
12
|
stringified_parameters = @args.map do |arg|
|
13
|
-
public_send(:"on_#{arg.type}",
|
13
|
+
public_send(:"on_#{arg.type}", arg)
|
14
14
|
end
|
15
15
|
|
16
16
|
"[#{stringified_parameters.compact.join(', ')}]"
|
17
17
|
end
|
18
18
|
|
19
|
-
def on_arg(
|
19
|
+
def on_arg(arg)
|
20
|
+
arg_name = arg.meta[:arg_name]
|
20
21
|
%{['req', '#{arg_name}']}
|
21
22
|
end
|
22
23
|
|
23
|
-
def on_mlhs(
|
24
|
+
def on_mlhs(_arg)
|
24
25
|
%{['req']}
|
25
26
|
end
|
26
27
|
|
27
|
-
def on_optarg(
|
28
|
+
def on_optarg(arg)
|
29
|
+
arg_name = arg.meta[:arg_name]
|
28
30
|
%{['opt', '#{arg_name}']}
|
29
31
|
end
|
30
32
|
|
31
|
-
def on_restarg(
|
33
|
+
def on_restarg(arg)
|
34
|
+
arg_name = arg.meta[:arg_name]
|
32
35
|
if arg_name
|
33
36
|
arg_name = :* if arg_name == :fwd_rest_arg
|
34
37
|
%{['rest', '#{arg_name}']}
|
@@ -37,15 +40,18 @@ module Opal
|
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
40
|
-
def on_kwarg(
|
43
|
+
def on_kwarg(arg)
|
44
|
+
arg_name = arg.meta[:arg_name]
|
41
45
|
%{['keyreq', '#{arg_name}']}
|
42
46
|
end
|
43
47
|
|
44
|
-
def on_kwoptarg(
|
48
|
+
def on_kwoptarg(arg)
|
49
|
+
arg_name = arg.meta[:arg_name]
|
45
50
|
%{['key', '#{arg_name}']}
|
46
51
|
end
|
47
52
|
|
48
|
-
def on_kwrestarg(
|
53
|
+
def on_kwrestarg(arg)
|
54
|
+
arg_name = arg.meta[:arg_name]
|
49
55
|
if arg_name
|
50
56
|
%{['keyrest', '#{arg_name}']}
|
51
57
|
else
|
@@ -53,16 +59,17 @@ module Opal
|
|
53
59
|
end
|
54
60
|
end
|
55
61
|
|
56
|
-
def on_blockarg(
|
62
|
+
def on_blockarg(arg)
|
63
|
+
arg_name = arg.meta[:arg_name]
|
57
64
|
arg_name = :& if arg_name == :fwd_block_arg
|
58
65
|
%{['block', '#{arg_name}']}
|
59
66
|
end
|
60
67
|
|
61
|
-
def on_kwnilarg
|
68
|
+
def on_kwnilarg(_arg)
|
62
69
|
%{['nokey']}
|
63
70
|
end
|
64
71
|
|
65
|
-
def on_shadowarg(
|
72
|
+
def on_shadowarg(_arg); end
|
66
73
|
end
|
67
74
|
end
|
68
75
|
end
|
data/lib/opal/nodes/args.rb
CHANGED
@@ -25,40 +25,12 @@ module Opal
|
|
25
25
|
class ArgsNode < Base
|
26
26
|
handle :args
|
27
27
|
|
28
|
-
# ruby allows for args with the same name, if the arg starts with a '_', like:
|
29
|
-
# def funny_method_name(_, _)
|
30
|
-
# puts _
|
31
|
-
# end
|
32
|
-
# but javascript in strict mode does not allow for args with the same name
|
33
|
-
# ruby assigns the value of the first arg given
|
34
|
-
# funny_method_name(1, 2) => 1
|
35
|
-
# 1. check for args starting with '_' and check if they appear multiple times
|
36
|
-
# 2. leave the first appearance as it is and rename the other ones
|
37
|
-
# compiler result:
|
38
|
-
# function $$funny_method_name(_, __$2)
|
39
|
-
|
40
28
|
def compile
|
41
|
-
same_arg_counter = {}
|
42
29
|
children.each_with_index do |arg, idx|
|
43
|
-
if multiple_underscore?(arg)
|
44
|
-
same_arg_counter[arg] ||= 0
|
45
|
-
same_arg_counter[arg] += 1
|
46
|
-
if same_arg_counter[arg] > 1
|
47
|
-
arg = s(arg.type, :"#{arg.children[0]}_$#{same_arg_counter[arg]}")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
30
|
push ', ' if idx != 0
|
52
31
|
push process(arg)
|
53
32
|
end
|
54
33
|
end
|
55
|
-
|
56
|
-
def multiple_underscore?(arg)
|
57
|
-
arg.type == :arg &&
|
58
|
-
arg.children.count == 1 &&
|
59
|
-
arg.children.first.to_s.start_with?('_') &&
|
60
|
-
children.count(arg) > 1
|
61
|
-
end
|
62
34
|
end
|
63
35
|
end
|
64
36
|
end
|
data/lib/opal/nodes/super.rb
CHANGED
@@ -176,7 +176,6 @@ module Opal
|
|
176
176
|
def implicit_arglist
|
177
177
|
args = []
|
178
178
|
kwargs = []
|
179
|
-
same_arg_counter = Hash.new(0)
|
180
179
|
|
181
180
|
def_scope.original_args.children.each do |sexp|
|
182
181
|
lvar_name = sexp.children[0]
|
@@ -184,14 +183,6 @@ module Opal
|
|
184
183
|
case sexp.type
|
185
184
|
when :arg, :optarg
|
186
185
|
arg_node = s(:lvar, lvar_name)
|
187
|
-
# def m(_, _)
|
188
|
-
# is compiled to
|
189
|
-
# function $$m(_, __$2)
|
190
|
-
# See Opal::Node::ArgsNode
|
191
|
-
if lvar_name[0] == '_'
|
192
|
-
same_arg_counter[lvar_name] += 1
|
193
|
-
arg_node = s(:js_tmp, "#{lvar_name}_$#{same_arg_counter[lvar_name]}") if same_arg_counter[lvar_name] > 1
|
194
|
-
end
|
195
186
|
args << arg_node
|
196
187
|
when :restarg
|
197
188
|
arg_node = lvar_name ? s(:lvar, lvar_name) : s(:js_tmp, '$rest_arg')
|
data/lib/opal/rewriter.rb
CHANGED
@@ -11,6 +11,7 @@ require 'opal/rewriters/logical_operator_assignment'
|
|
11
11
|
require 'opal/rewriters/binary_operator_assignment'
|
12
12
|
require 'opal/rewriters/hashes/key_duplicates_rewriter'
|
13
13
|
require 'opal/rewriters/dump_args'
|
14
|
+
require 'opal/rewriters/deduplicate_arg_name'
|
14
15
|
require 'opal/rewriters/mlhs_args'
|
15
16
|
require 'opal/rewriters/inline_args'
|
16
17
|
require 'opal/rewriters/numblocks'
|
@@ -66,6 +67,7 @@ module Opal
|
|
66
67
|
use Rewriters::BinaryOperatorAssignment
|
67
68
|
use Rewriters::Hashes::KeyDuplicatesRewriter
|
68
69
|
use Rewriters::ReturnableLogic
|
70
|
+
use Rewriters::DeduplicateArgName
|
69
71
|
use Rewriters::DumpArgs
|
70
72
|
use Rewriters::MlhsArgs
|
71
73
|
use Rewriters::InlineArgs
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Opal
|
4
|
+
module Rewriters
|
5
|
+
# Ruby allows for args with the same name, if the arg starts with a '_', like:
|
6
|
+
# def funny_method_name(_, _)
|
7
|
+
# puts _
|
8
|
+
# end
|
9
|
+
# but JavaScript in strict mode does not allow for args with the same name
|
10
|
+
# Ruby assigns the value of the first arg given
|
11
|
+
# funny_method_name(1, 2) => 1
|
12
|
+
# leave the first appearance as it is and rename the other ones
|
13
|
+
# compiler result:
|
14
|
+
# function $$funny_method_name(_, __$2)
|
15
|
+
class DeduplicateArgName < Base
|
16
|
+
def on_args(node)
|
17
|
+
@arg_name_count = Hash.new(0)
|
18
|
+
|
19
|
+
children = node.children.map do |arg|
|
20
|
+
rename_arg(arg)
|
21
|
+
end
|
22
|
+
|
23
|
+
super(node.updated(nil, children))
|
24
|
+
end
|
25
|
+
|
26
|
+
def rename_arg(arg)
|
27
|
+
case arg.type
|
28
|
+
when :arg, :restarg, :kwarg, :kwrestarg, :blockarg
|
29
|
+
name = arg.children[0]
|
30
|
+
name ? arg.updated(nil, [unique_name(name)]) : arg
|
31
|
+
when :optarg, :kwoptarg
|
32
|
+
name, value = arg.children
|
33
|
+
arg.updated(nil, [unique_name(name), value])
|
34
|
+
when :mlhs
|
35
|
+
new_children = arg.children.map { |child| rename_arg(child) }
|
36
|
+
arg.updated(nil, new_children)
|
37
|
+
else
|
38
|
+
arg
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def unique_name(name)
|
43
|
+
count = (@arg_name_count[name] += 1)
|
44
|
+
count > 1 ? :"#{name}_$#{count}" : name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -91,7 +91,6 @@ module Opal
|
|
91
91
|
@initialization = []
|
92
92
|
|
93
93
|
@type = type
|
94
|
-
@underscore_found = false
|
95
94
|
|
96
95
|
STEPS.each do |step|
|
97
96
|
send(step)
|
@@ -120,20 +119,9 @@ module Opal
|
|
120
119
|
@args.args.each do |arg|
|
121
120
|
if @type == :iter
|
122
121
|
# block args are not required,
|
123
|
-
# so we
|
122
|
+
# so we need to tell compiler that required args
|
124
123
|
# must be initialized with nil-s
|
125
124
|
@initialization << arg.updated(:initialize_iter_arg)
|
126
|
-
|
127
|
-
if arg.children[0] == :_
|
128
|
-
if @underscore_found
|
129
|
-
# for proc { |_, _| _ }.call(1, 2) result must be 1
|
130
|
-
# here we convert all underscore args starting from the 2nd
|
131
|
-
# to a "fake" arg
|
132
|
-
arg = s(:fake_arg)
|
133
|
-
end
|
134
|
-
|
135
|
-
@underscore_found = true
|
136
|
-
end
|
137
125
|
else
|
138
126
|
# required inline def argument like 'def m(req)'
|
139
127
|
# no initialization is required
|
data/lib/opal/version.rb
CHANGED
data/opal/corelib/array.rb
CHANGED
@@ -47,7 +47,7 @@ class ::Array < `Array`
|
|
47
47
|
function filterIf(self, filter, block) {
|
48
48
|
var value, raised = null, updated = new Array(self.length);
|
49
49
|
|
50
|
-
for (var i = 0, i2 = 0
|
50
|
+
for (var i = 0, i2 = 0; i < self.length; i++) {
|
51
51
|
if (!raised) {
|
52
52
|
try {
|
53
53
|
value = $yield1(block, self[i])
|
@@ -708,10 +708,9 @@ class ::Array < `Array`
|
|
708
708
|
return enum_for(:collect) { size } unless block_given?
|
709
709
|
|
710
710
|
%x{
|
711
|
-
var
|
712
|
-
var result = new Array(length);
|
711
|
+
var result = [];
|
713
712
|
|
714
|
-
for (var i = 0; i < length; i++) {
|
713
|
+
for (var i = 0; i < self.length; i++) {
|
715
714
|
var value = $yield1(block, self[i]);
|
716
715
|
result[i] = value;
|
717
716
|
}
|
@@ -726,7 +725,7 @@ class ::Array < `Array`
|
|
726
725
|
%x{
|
727
726
|
$deny_frozen_access(self);
|
728
727
|
|
729
|
-
for (var i = 0
|
728
|
+
for (var i = 0; i < self.length; i++) {
|
730
729
|
var value = $yield1(block, self[i]);
|
731
730
|
self[i] = value;
|
732
731
|
}
|
@@ -988,8 +987,8 @@ class ::Array < `Array`
|
|
988
987
|
return enum_for(:each) { size } unless block_given?
|
989
988
|
|
990
989
|
%x{
|
991
|
-
for (var i = 0
|
992
|
-
|
990
|
+
for (var i = 0; i < self.length; i++) {
|
991
|
+
$yield1(block, self[i]);
|
993
992
|
}
|
994
993
|
}
|
995
994
|
|
@@ -1000,8 +999,8 @@ class ::Array < `Array`
|
|
1000
999
|
return enum_for(:each_index) { size } unless block_given?
|
1001
1000
|
|
1002
1001
|
%x{
|
1003
|
-
for (var i = 0
|
1004
|
-
|
1002
|
+
for (var i = 0; i < self.length; i++) {
|
1003
|
+
$yield1(block, i);
|
1005
1004
|
}
|
1006
1005
|
}
|
1007
1006
|
|
@@ -1348,7 +1347,7 @@ class ::Array < `Array`
|
|
1348
1347
|
}
|
1349
1348
|
}
|
1350
1349
|
else if (block !== nil) {
|
1351
|
-
for (i = 0
|
1350
|
+
for (i = 0; i < self.length; i++) {
|
1352
1351
|
value = block(self[i]);
|
1353
1352
|
|
1354
1353
|
if (value !== false && value !== nil) {
|
@@ -1789,7 +1788,7 @@ class ::Array < `Array`
|
|
1789
1788
|
%x{
|
1790
1789
|
var result = [];
|
1791
1790
|
|
1792
|
-
for (var i = 0,
|
1791
|
+
for (var i = 0, value; i < self.length; i++) {
|
1793
1792
|
value = block(self[i]);
|
1794
1793
|
|
1795
1794
|
if (value === false || value === nil) {
|
@@ -1839,7 +1838,11 @@ class ::Array < `Array`
|
|
1839
1838
|
def reverse_each(&block)
|
1840
1839
|
return enum_for(:reverse_each) { size } unless block_given?
|
1841
1840
|
|
1842
|
-
|
1841
|
+
%x{
|
1842
|
+
for (var i = self.length - 1; i >= 0; i--) {
|
1843
|
+
$yield1(block, self[i]);
|
1844
|
+
}
|
1845
|
+
}
|
1843
1846
|
self
|
1844
1847
|
end
|
1845
1848
|
|
@@ -2048,7 +2051,7 @@ class ::Array < `Array`
|
|
2048
2051
|
%x{
|
2049
2052
|
var result = [];
|
2050
2053
|
|
2051
|
-
for (var i = 0,
|
2054
|
+
for (var i = 0, item, value; i < self.length; i++) {
|
2052
2055
|
item = self[i];
|
2053
2056
|
|
2054
2057
|
value = $yield1(block, item);
|
@@ -2293,7 +2296,7 @@ class ::Array < `Array`
|
|
2293
2296
|
%x{
|
2294
2297
|
var result = [];
|
2295
2298
|
|
2296
|
-
for (var i = 0,
|
2299
|
+
for (var i = 0, item, value; i < self.length; i++) {
|
2297
2300
|
item = self[i];
|
2298
2301
|
|
2299
2302
|
value = block(item);
|
@@ -2389,7 +2392,7 @@ class ::Array < `Array`
|
|
2389
2392
|
}
|
2390
2393
|
}
|
2391
2394
|
else {
|
2392
|
-
for (i = 0
|
2395
|
+
for (i = 0; i < self.length; i++) {
|
2393
2396
|
item = self[i];
|
2394
2397
|
key = $yield1(block, item);
|
2395
2398
|
if ($hash_get(hash, key) === undefined) {
|
@@ -2406,23 +2409,24 @@ class ::Array < `Array`
|
|
2406
2409
|
%x{
|
2407
2410
|
$deny_frozen_access(self);
|
2408
2411
|
|
2409
|
-
var
|
2412
|
+
var hash = #{{}}, i, item, key, delete_indexes = [];
|
2410
2413
|
|
2411
|
-
for (i = 0
|
2414
|
+
for (i = 0; i < self.length; i++) {
|
2412
2415
|
item = self[i];
|
2413
2416
|
key = (block === nil ? item : $yield1(block, item));
|
2414
2417
|
|
2415
2418
|
if ($hash_get(hash, key) === undefined) {
|
2416
2419
|
$hash_put(hash, key, item);
|
2417
|
-
|
2420
|
+
} else {
|
2421
|
+
delete_indexes.push(i);
|
2418
2422
|
}
|
2423
|
+
}
|
2419
2424
|
|
2420
|
-
|
2421
|
-
|
2422
|
-
i--;
|
2425
|
+
for (i = delete_indexes.length - 1; i >= 0; i--) {
|
2426
|
+
self.splice(delete_indexes[i], 1);
|
2423
2427
|
}
|
2424
2428
|
|
2425
|
-
return
|
2429
|
+
return delete_indexes.length === 0 ? nil : self;
|
2426
2430
|
}
|
2427
2431
|
end
|
2428
2432
|
|
data/opal/corelib/constants.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
::RUBY_PLATFORM = 'opal'
|
2
2
|
::RUBY_ENGINE = 'opal'
|
3
3
|
::RUBY_VERSION = '3.2.0'
|
4
|
-
::RUBY_ENGINE_VERSION = '1.8.
|
5
|
-
::RUBY_RELEASE_DATE = '2023-
|
4
|
+
::RUBY_ENGINE_VERSION = '1.8.1'
|
5
|
+
::RUBY_RELEASE_DATE = '2023-11-09'
|
6
6
|
::RUBY_PATCHLEVEL = 0
|
7
7
|
::RUBY_REVISION = '0'
|
8
8
|
::RUBY_COPYRIGHT = 'opal - Copyright (C) 2011-2023 Adam Beynon and the Opal contributors'
|
data/opal/corelib/kernel.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# helpers: truthy, coerce_to, respond_to, Opal, deny_frozen_access, freeze, freeze_props, jsid
|
1
|
+
# helpers: truthy, coerce_to, respond_to, Opal, deny_frozen_access, freeze, freeze_props, jsid, each_ivar
|
2
2
|
# use_strict: true
|
3
3
|
# backtick_javascript: true
|
4
4
|
|
@@ -369,18 +369,14 @@ module ::Kernel
|
|
369
369
|
|
370
370
|
def instance_variables
|
371
371
|
%x{
|
372
|
-
var result = [],
|
372
|
+
var result = [], name;
|
373
373
|
|
374
|
-
|
375
|
-
if (
|
376
|
-
|
377
|
-
ivar = name.slice(0, name.length - 1);
|
378
|
-
} else {
|
379
|
-
ivar = name;
|
380
|
-
}
|
381
|
-
result.push('@' + ivar);
|
374
|
+
$each_ivar(self, function(name) {
|
375
|
+
if (name.substr(-1) === '$') {
|
376
|
+
name = name.slice(0, name.length - 1);
|
382
377
|
}
|
383
|
-
|
378
|
+
result.push('@' + name);
|
379
|
+
});
|
384
380
|
|
385
381
|
return result;
|
386
382
|
}
|
@@ -610,9 +606,10 @@ module ::Kernel
|
|
610
606
|
end
|
611
607
|
|
612
608
|
def printf(*args)
|
613
|
-
if args.
|
614
|
-
|
615
|
-
|
609
|
+
return if args.empty?
|
610
|
+
|
611
|
+
io = `args[0].$$is_string` ? $stdout : args.shift
|
612
|
+
io.write format(*args)
|
616
613
|
|
617
614
|
nil
|
618
615
|
end
|
data/opal/corelib/module.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# helpers: truthy, coerce_to, const_set, Object, return_ivar, assign_ivar, ivar, deny_frozen_access, freeze, prop, jsid
|
1
|
+
# helpers: truthy, coerce_to, const_set, Object, return_ivar, assign_ivar, ivar, deny_frozen_access, freeze, prop, jsid, each_ivar
|
2
2
|
# backtick_javascript: true
|
3
3
|
|
4
4
|
class ::Module
|
@@ -744,11 +744,11 @@ class ::Module
|
|
744
744
|
%x{
|
745
745
|
var result = [];
|
746
746
|
|
747
|
-
|
748
|
-
if (
|
747
|
+
$each_ivar(self, function(name) {
|
748
|
+
if (name !== 'constructor' && !#{consts.include?(`name`)}) {
|
749
749
|
result.push('@' + name);
|
750
750
|
}
|
751
|
-
}
|
751
|
+
});
|
752
752
|
|
753
753
|
return result;
|
754
754
|
}
|
data/opal/corelib/proc.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# helpers: slice
|
1
|
+
# helpers: slice, each_ivar
|
2
2
|
# backtick_javascript: true
|
3
3
|
|
4
4
|
class ::Proc < `Function`
|
@@ -181,11 +181,9 @@ class ::Proc < `Function`
|
|
181
181
|
return original_proc.apply(this, arguments);
|
182
182
|
};
|
183
183
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
}
|
188
|
-
}
|
184
|
+
$each_ivar(self, function(prop) {
|
185
|
+
proc[prop] = self[prop];
|
186
|
+
});
|
189
187
|
|
190
188
|
return proc;
|
191
189
|
}
|
data/opal/corelib/runtime.js
CHANGED
@@ -2580,33 +2580,42 @@
|
|
2580
2580
|
return obj;
|
2581
2581
|
};
|
2582
2582
|
|
2583
|
-
//
|
2584
|
-
|
2585
|
-
|
2583
|
+
// Iterate over every instance variable and call func for each one
|
2584
|
+
// giving name of the ivar and optionally the property descriptor.
|
2585
|
+
function $each_ivar(obj, func) {
|
2586
|
+
var own_props = Object.getOwnPropertyNames(obj), own_props_length = own_props.length, i, prop, desc;
|
2586
2587
|
|
2587
|
-
for(
|
2588
|
-
|
2588
|
+
for(i = 0; i < own_props_length; i++) {
|
2589
|
+
prop = own_props[i];
|
2589
2590
|
|
2590
|
-
|
2591
|
-
if ((prop_type === "string" || prop_type === "object") && prop[0] === '$') {
|
2592
|
-
continue;
|
2593
|
-
}
|
2591
|
+
if (prop[0] === '$') continue;
|
2594
2592
|
|
2595
2593
|
desc = Object.getOwnPropertyDescriptor(obj, prop);
|
2596
|
-
|
2597
|
-
|
2598
|
-
|
2599
|
-
(function() {
|
2600
|
-
// set v to undefined, as if the property is not set
|
2601
|
-
var cv = obj[prop];
|
2602
|
-
Object.defineProperty(obj, prop, {
|
2603
|
-
get: function() { return cv; },
|
2604
|
-
set: function(_val) { $deny_frozen_access(obj); },
|
2605
|
-
enumerable: true
|
2606
|
-
});
|
2607
|
-
})();
|
2594
|
+
|
2595
|
+
if (desc && desc.enumerable) {
|
2596
|
+
func(prop, desc);
|
2608
2597
|
}
|
2609
2598
|
}
|
2599
|
+
}
|
2600
|
+
|
2601
|
+
Opal.each_ivar = $each_ivar;
|
2602
|
+
|
2603
|
+
// freze props, make setters of instance variables throw FrozenError
|
2604
|
+
Opal.freeze_props = function(obj) {
|
2605
|
+
var dp_template = {
|
2606
|
+
get: null,
|
2607
|
+
set: function(_val) { $deny_frozen_access(obj); },
|
2608
|
+
enumerable: true
|
2609
|
+
};
|
2610
|
+
|
2611
|
+
$each_ivar(obj, function(prop, desc) {
|
2612
|
+
if (!desc.writable) return;
|
2613
|
+
|
2614
|
+
// Redefine a property with a setter that raises an error.
|
2615
|
+
dp_template.get = $return_val(desc.value);
|
2616
|
+
|
2617
|
+
Object.defineProperty(obj, prop, dp_template);
|
2618
|
+
});
|
2610
2619
|
};
|
2611
2620
|
|
2612
2621
|
// Regexps
|
data/spec/filters/bugs/array.rb
CHANGED
@@ -8,43 +8,19 @@ opal_filter "Array" do
|
|
8
8
|
fails "Array#[] raises a RangeError if passed a range with a bound that is too large" # Expected RangeError but no exception was raised (nil was returned)
|
9
9
|
fails "Array#[] raises a type error if a range is passed with a length" # Expected TypeError but no exception was raised ([2, 3] was returned)
|
10
10
|
fails "Array#all? ignores the block if there is an argument" # Expected warning to match: /given block not used/ but got: ""
|
11
|
-
fails "Array#all? tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
12
11
|
fails "Array#any? when given a pattern argument ignores the block if there is an argument" # Expected warning to match: /given block not used/ but got: ""
|
13
|
-
fails "Array#any? with a block given tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
14
|
-
fails "Array#collect tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
15
|
-
fails "Array#collect! tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
16
|
-
fails "Array#count when a block argument given tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
17
|
-
fails "Array#delete_if tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
18
12
|
fails "Array#drop raises a TypeError when the passed argument isn't an integer and #to_int returns non-Integer" # Expected TypeError but no exception was raised ([1, 2] was returned)
|
19
|
-
fails "Array#drop_while tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
20
|
-
fails "Array#each does not yield elements deleted from the end of the array" # Expected [2, 3, nil] == [2, 3] to be truthy but was false
|
21
|
-
fails "Array#each tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
22
|
-
fails "Array#each yields each element to the block even if the array is changed during iteration" # Expected [1, 2, 3, 4, 5] == [1, 2, 3, 4, 5, 7, 9] to be truthy but was false
|
23
|
-
fails "Array#each yields elements added to the end of the array by the block" # Expected [2] == [2, 0, 0] to be truthy but was false
|
24
|
-
fails "Array#each yields elements based on an internal index" # NoMethodError: undefined method `even?' for nil
|
25
|
-
fails "Array#each yields only elements that are still in the array" # NoMethodError: undefined method `even?' for nil
|
26
|
-
fails "Array#each yields the same element multiple times if inserting while iterating" # Expected [1, 1] == [1, 1, 2] to be truthy but was false
|
27
|
-
fails "Array#each_index tolerates increasing an array size during iteration" # Expected [0, 1, 2] == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102] to be truthy but was false
|
28
13
|
fails "Array#fill with (filler, index, length) raises a TypeError when the length is not numeric" # Expected TypeError (/no implicit conversion of Symbol into Integer/) but got: TypeError (no implicit conversion of String into Integer)
|
29
14
|
fails "Array#fill with (filler, range) works with endless ranges" # Expected [1, 2, 3, 4] == [1, 2, 3, "x"] to be truthy but was false
|
30
15
|
fails "Array#filter returns a new array of elements for which block is true" # Expected [1] == [1, 4, 6] to be truthy but was false
|
31
|
-
fails "Array#filter tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
32
|
-
fails "Array#filter! tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
33
|
-
fails "Array#find_index tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
34
16
|
fails "Array#flatten does not call #to_ary on elements beyond the given level" # Mock '1' expected to receive to_ary("any_args") exactly 0 times but received it 1 times
|
35
17
|
fails "Array#flatten performs respond_to? and method_missing-aware checks when coercing elements to array" # NoMethodError: undefined method `respond_to?' for #<BasicObject:0x2698>
|
36
18
|
fails "Array#flatten with a non-Array object in the Array calls #method_missing if defined" # Expected [#<MockObject:0x2730 @name="Array#flatten", @null=nil>] == [1, 2, 3] to be truthy but was false
|
37
|
-
fails "Array#index tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
38
19
|
fails "Array#initialize with no arguments does not use the given block" # Expected warning to match: /ruby\/core\/array\/initialize_spec.rb:57: warning: given block not used/ but got: ""
|
39
20
|
fails "Array#inspect does not call #to_str on the object returned from #to_s when it is not a String" # Exception: Cannot convert object to primitive value
|
40
21
|
fails "Array#intersect? tries to convert the passed argument to an Array using #to_ary" # Expected false == true to be truthy but was false
|
41
|
-
fails "Array#keep_if tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
42
|
-
fails "Array#map tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
43
|
-
fails "Array#map! tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
44
22
|
fails "Array#none? ignores the block if there is an argument" # Expected warning to match: /given block not used/ but got: ""
|
45
|
-
fails "Array#none? tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
46
23
|
fails "Array#one? ignores the block if there is an argument" # Expected warning to match: /given block not used/ but got: ""
|
47
|
-
fails "Array#one? tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
48
24
|
fails "Array#pack with format 'A' ignores comments in the format string" # RuntimeError: Unsupported pack directive "m" (no chunk reader defined)
|
49
25
|
fails "Array#pack with format 'A' warns that a directive is unknown" # Expected warning to match: /unknown pack directive 'R'/ but got: ""
|
50
26
|
fails "Array#pack with format 'C' ignores comments in the format string" # RuntimeError: Unsupported pack directive "m" (no chunk reader defined)
|
@@ -67,13 +43,8 @@ opal_filter "Array" do
|
|
67
43
|
fails "Array#product returns converted arguments using :method_missing" # TypeError: no implicit conversion of ArraySpecs::ArrayMethodMissing into Array
|
68
44
|
fails "Array#rassoc calls elem == obj on the second element of each contained array" # Expected [1, "foobar"] == [2, #<MockObject:0x4a6b4 @name="foobar", @null=nil>] to be truthy but was false
|
69
45
|
fails "Array#rassoc does not check the last element in each contained but specifically the second" # Expected [1, "foobar", #<MockObject:0x4a37e @name="foobar", @null=nil>] == [2, #<MockObject:0x4a37e @name="foobar", @null=nil>, 1] to be truthy but was false
|
70
|
-
fails "Array#reject tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
71
|
-
fails "Array#reject! tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
72
|
-
fails "Array#reverse_each tolerates increasing an array size during iteration" # Expected ["c", "b", "a"] == ["c", "a", 1] to be truthy but was false
|
73
46
|
fails "Array#sample returns nil for an empty array when called without n and a Random is given" # ArgumentError: invalid argument - 0
|
74
47
|
fails "Array#select returns a new array of elements for which block is true" # Expected [1] == [1, 4, 6] to be truthy but was false
|
75
|
-
fails "Array#select tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
76
|
-
fails "Array#select! tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
77
48
|
fails "Array#shuffle! matches CRuby with random:" # Expected [7, 4, 5, 0, 3, 9, 2, 8, 10, 1, 6] == [2, 6, 8, 5, 7, 10, 3, 1, 0, 4, 9] to be truthy but was false
|
78
49
|
fails "Array#shuffle! matches CRuby with srand" # Expected ["d", "j", "g", "f", "i", "e", "c", "k", "b", "h", "a"] == ["a", "e", "f", "h", "i", "j", "d", "b", "g", "k", "c"] to be truthy but was false
|
79
50
|
fails "Array#slice can be sliced with Enumerator::ArithmeticSequence has endless range with start outside of array's bounds" # Expected [] == nil to be truthy but was false
|
@@ -81,15 +52,8 @@ opal_filter "Array" do
|
|
81
52
|
fails "Array#slice raises TypeError if to_int returns non-integer" # Expected TypeError but no exception was raised ([1, 2, 3, 4] was returned)
|
82
53
|
fails "Array#slice raises a RangeError if passed a range with a bound that is too large" # Expected RangeError but no exception was raised (nil was returned)
|
83
54
|
fails "Array#slice raises a type error if a range is passed with a length" # Expected TypeError but no exception was raised ([2, 3] was returned)
|
84
|
-
fails "Array#sort_by! tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
85
55
|
fails "Array#sum calls + on the init value" # NoMethodError: undefined method `-' for #<MockObject:0x7f7c2 @name="b" @null=nil>
|
86
|
-
fails "Array#sum tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
87
|
-
fails "Array#take_while tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
88
|
-
fails "Array#to_h tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
89
56
|
fails "Array#to_s does not call #to_str on the object returned from #to_s when it is not a String" # Exception: Cannot convert object to primitive value
|
90
|
-
fails "Array#uniq tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
91
|
-
fails "Array#uniq! properly handles recursive arrays" # Expected [1, "two", 3, [...], [...], [...]] == [1, "two", 3, [1, "two", 3, [...], [...], [...]]] to be truthy but was false
|
92
|
-
fails "Array#uniq! tolerates increasing an array size during iteration" # Expected [1, 2, 3] == [1, 2, 3, "a", "b", "c", 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] to be truthy but was false
|
93
57
|
fails "Array#zip raises TypeError when some argument isn't Array and doesn't respond to #to_ary and #to_enum" # Expected TypeError (wrong argument type Object (must respond to :each)) but got: NoMethodError (undefined method `each' for #<Object:0x6273e>)
|
94
58
|
fails "Array.new with no arguments does not use the given block" # Expected warning to match: /warning: given block not used/ but got: ""
|
95
59
|
fails "Array.try_convert sends #to_ary to the argument and raises TypeError if it's not a kind of Array" # Expected TypeError (can't convert MockObject to Array (MockObject#to_ary gives Object)) but got: TypeError (can't convert MockObject into Array (MockObject#to_ary gives Object))
|
@@ -17,14 +17,12 @@ opal_filter "Enumerable" do
|
|
17
17
|
fails "Enumerable#grep_v does not set $~ when given no block" # Expected "e" == "z" to be truthy but was false
|
18
18
|
fails "Enumerable#inject ignores the block if two arguments" # Expected warning to match: /ruby\/core\/enumerable\/shared\/inject.rb:23: warning: given block not used/ but got: ""
|
19
19
|
fails "Enumerable#inject raises an ArgumentError when no parameters or block is given" # Expected ArgumentError but got: Exception (Cannot read properties of undefined (reading '$inspect'))
|
20
|
-
fails "Enumerable#inject tolerates increasing a collection size during iterating Array" # Expected ["a", "b", "c"] == [0, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 4, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 5, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 6, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 7, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 8, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 9, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, "a", "b", "c"] to be truthy but was false
|
21
20
|
fails "Enumerable#map reports the same arity as the given block" # Exception: Cannot read properties of undefined (reading '$$is_array')
|
22
21
|
fails "Enumerable#map yields 2 arguments for a Hash when block arity is 2" # ArgumentError: [#register] wrong number of arguments (given 1, expected 2)
|
23
22
|
fails "Enumerable#none? when given a pattern argument ignores the block if there is an argument" # Expected warning to match: /given block not used/ but got: ""
|
24
23
|
fails "Enumerable#one? when given a pattern argument ignores the block if there is an argument" # Expected warning to match: /given block not used/ but got: ""
|
25
24
|
fails "Enumerable#reduce ignores the block if two arguments" # Expected warning to match: /ruby\/core\/enumerable\/shared\/inject.rb:23: warning: given block not used/ but got: ""
|
26
25
|
fails "Enumerable#reduce raises an ArgumentError when no parameters or block is given" # Expected ArgumentError but got: Exception (Cannot read properties of undefined (reading '$inspect'))
|
27
|
-
fails "Enumerable#reduce tolerates increasing a collection size during iterating Array" # Expected ["a", "b", "c"] == [0, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 4, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 5, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 6, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 7, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 8, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 9, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, "a", "b", "c"] to be truthy but was false
|
28
26
|
fails "Enumerable#reverse_each gathers whole arrays as elements when each yields multiple" # Expected [6, 3, 1] == [[6, 7, 8, 9], [3, 4, 5], [1, 2]] to be truthy but was false
|
29
27
|
fails "Enumerable#slice_when when an iterator method yields more than one value processes all yielded values" # Expected [] == [[[1, 2]]] to be truthy but was false
|
30
28
|
fails "Enumerable#slice_when when given a block doesn't yield an empty array on a small enumerable" # Expected [] == [[42]] to be truthy but was false
|
@@ -34,6 +32,6 @@ opal_filter "Enumerable" do
|
|
34
32
|
fails "Enumerable#tally counts values as gathered array when yielded with multiple arguments" # Expected {[]=>3, 0=>1, [0, 1]=>2, [0, 1, 2]=>3, nil=>1, "default_arg"=>1, [0]=>1} == {nil=>2, 0=>1, [0, 1]=>2, [0, 1, 2]=>3, "default_arg"=>1, []=>2, [0]=>1} to be truthy but was false
|
35
33
|
fails "Enumerable#tally with a hash calls #to_hash to convert argument to Hash implicitly if passed not a Hash" # NoMethodError: undefined method `fetch' for #<Object:0x8def0>
|
36
34
|
fails "Enumerable#uniq uses eql? semantics" # Expected [1] == [1, 1] to be truthy but was false
|
37
|
-
fails "Enumerable#zip passes each element of the result array to a block and return nil if a block is given" # Expected [[1, 4, 7], [2, 5, 8], [3, 6, 9]] == nil to be truthy but was false
|
35
|
+
fails "Enumerable#zip passes each element of the result array to a block and return nil if a block is given" # Expected [[1, 4, 7], [2, 5, 8], [3, 6, 9]] == nil to be truthy but was false
|
38
36
|
fails "Enumerable#zip raises TypeError when some argument isn't Array and doesn't respond to #to_ary and #to_enum" # Expected TypeError (wrong argument type Object (must respond to :each)) but got: NoMethodError (undefined method `each' for #<Object:0x2e1e6>)
|
39
37
|
end
|
data/spec/filters/bugs/kernel.rb
CHANGED
@@ -352,14 +352,12 @@ opal_filter "Kernel" do
|
|
352
352
|
fails "Kernel.printf formatting io is not specified other formats c tries to convert argument to Integer with to_int" # NoMethodError: undefined method `respond_to?' for #<BasicObject:0x4080e>
|
353
353
|
fails "Kernel.printf formatting io is not specified other formats c tries to convert argument to String with to_str" # NoMethodError: undefined method `respond_to?' for #<BasicObject:0x40800>
|
354
354
|
fails "Kernel.printf formatting io is not specified other formats s preserves encoding of the format string" # Expected #<Encoding:UTF-8> == #<Encoding:US-ASCII> to be truthy but was false
|
355
|
-
fails "Kernel.printf formatting io is specified other formats c raises TypeError if argument is nil" # Expected TypeError (/no implicit conversion from nil to integer/) but got:
|
356
|
-
fails "Kernel.printf formatting io is specified other formats c raises TypeError if argument is not String or Integer and cannot be converted to them" # Expected TypeError (/no implicit conversion of Array into Integer/) but got:
|
357
|
-
fails "Kernel.printf formatting io is specified other formats c raises TypeError if converting to Integer with to_int returns non-Integer" # Expected TypeError (/can't convert BasicObject to
|
358
|
-
fails "Kernel.printf formatting io is specified other formats c raises TypeError if converting to String with to_str returns non-String" # Expected TypeError (/can't convert BasicObject to String/) but got:
|
359
|
-
fails "Kernel.printf formatting io is specified other formats c tries to convert argument to Integer with to_int" #
|
360
|
-
fails "Kernel.printf formatting io is specified other formats c tries to convert argument to String with to_str" #
|
361
|
-
fails "Kernel.printf formatting io is specified other formats s formats nil with precision" # Exception: format_string.indexOf is not a function
|
362
|
-
fails "Kernel.printf formatting io is specified other formats s formats nil with width" # Exception: format_string.indexOf is not a function
|
355
|
+
fails "Kernel.printf formatting io is specified other formats c raises TypeError if argument is nil" # Expected TypeError (/no implicit conversion from nil to integer/) but got: TypeError (no implicit conversion of NilClass into Integer)
|
356
|
+
fails "Kernel.printf formatting io is specified other formats c raises TypeError if argument is not String or Integer and cannot be converted to them" # Expected TypeError (/no implicit conversion of Array into Integer/) but got: ArgumentError (too few arguments)
|
357
|
+
fails "Kernel.printf formatting io is specified other formats c raises TypeError if converting to Integer with to_int returns non-Integer" # Expected TypeError (/can't convert BasicObject to Integer/) but got: NoMethodError (undefined method `respond_to?' for #<BasicObject:0x69e>)
|
358
|
+
fails "Kernel.printf formatting io is specified other formats c raises TypeError if converting to String with to_str returns non-String" # Expected TypeError (/can't convert BasicObject to String/) but got: NoMethodError (undefined method `respond_to?' for #<BasicObject:0x6cc>)
|
359
|
+
fails "Kernel.printf formatting io is specified other formats c tries to convert argument to Integer with to_int" # NoMethodError: undefined method `respond_to?' for #<BasicObject:0x6a8>
|
360
|
+
fails "Kernel.printf formatting io is specified other formats c tries to convert argument to String with to_str" # NoMethodError: undefined method `respond_to?' for #<BasicObject:0x6c2>
|
363
361
|
fails "Kernel.printf formatting io is specified other formats s preserves encoding of the format string" # Expected #<Encoding:UTF-8> == #<Encoding:US-ASCII> to be truthy but was false
|
364
362
|
fails "Kernel.printf writes to stdout when a string is the first argument" # NoMethodError: undefined method `tmp' for #<MSpecEnv:0x4046a @name=nil @stdout=#<IO:0xa @fd=1 @flags="w" @eof=false @closed="both" @write_proc=#<Proc:0x40474> @tty=true>>
|
365
363
|
fails "Kernel.proc returned the passed Proc if given an existing Proc" # Expected false to be true
|
@@ -7,8 +7,8 @@ opal_filter "Ruby 3.2" do
|
|
7
7
|
fails "Kernel#sprintf other formats c displays only the first character if argument is a string of several characters" # ArgumentError: %c requires a character
|
8
8
|
fails "Kernel.printf formatting io is not specified other formats c displays no characters if argument is an empty string" # ArgumentError: %c requires a character
|
9
9
|
fails "Kernel.printf formatting io is not specified other formats c displays only the first character if argument is a string of several characters" # ArgumentError: %c requires a character
|
10
|
-
fails "Kernel.printf formatting io is specified other formats c displays no characters if argument is an empty string" #
|
11
|
-
fails "Kernel.printf formatting io is specified other formats c displays only the first character if argument is a string of several characters" #
|
10
|
+
fails "Kernel.printf formatting io is specified other formats c displays no characters if argument is an empty string" # ArgumentError: %c requires a character
|
11
|
+
fails "Kernel.printf formatting io is specified other formats c displays only the first character if argument is a string of several characters" # ArgumentError: %c requires a character
|
12
12
|
fails "Kernel.sprintf other formats c displays no characters if argument is an empty string" # ArgumentError: %c requires a character
|
13
13
|
fails "Kernel.sprintf other formats c displays only the first character if argument is a string of several characters" # ArgumentError: %c requires a character
|
14
14
|
fails "Keyword arguments delegation does not work with call(*ruby2_keyword_args) with missing ruby2_keywords in between" # Expected [[], {}] == [[{}], {}] to be truthy but was false
|
@@ -21,8 +21,4 @@ opal_unsupported_filter "Kernel" do
|
|
21
21
|
fails "Kernel#warn is a private method" # Expected Kernel to have private instance method 'warn' but it does not
|
22
22
|
fails "Kernel.Float raises a TypeError if #to_f returns an Integer" # Expected TypeError but no exception was raised (123 was returned)
|
23
23
|
fails "Kernel.lambda when called without a literal block warns when proc isn't a lambda" # Expected warning: "ruby/core/kernel/lambda_spec.rb:142: warning: lambda without a literal block is deprecated; use the proc without lambda instead\n" but got: ""
|
24
|
-
fails "Kernel.printf formatting io is specified other formats s formats nil with width and precision" # Exception: format_string.indexOf is not a function
|
25
|
-
fails "Kernel.printf formatting io is specified other formats s formats string with width and precision" # Exception: format_string.indexOf is not a function
|
26
|
-
fails "Kernel.printf formatting io is specified other formats s formats string with width" # Exception: format_string.indexOf is not a function
|
27
|
-
fails "Kernel.printf formatting io is specified other formats s substitutes '' for nil" # Exception: format_string.indexOf is not a function
|
28
24
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
describe 'duplicated underscore parameter' do
|
2
|
+
it 'assigns the first arg' do
|
3
|
+
klass = Class.new {
|
4
|
+
def req_req(_, _) = _
|
5
|
+
def req_rest_req(_, *, _) = _
|
6
|
+
def rest_req(*_, _) = _
|
7
|
+
def req_opt(_, _ = 0) = _
|
8
|
+
def opt_req(_ = 0, _) = _
|
9
|
+
def req_kwopt(_, _: 0) = _
|
10
|
+
def req_kwrest(_, **_) = _
|
11
|
+
def req_block(_, &_) = _
|
12
|
+
def req_mlhs(_, (_)) = _
|
13
|
+
def mlhs_req((_), _) = _
|
14
|
+
def rest_kw(*_, _:) = _
|
15
|
+
def nested_mlhs(((_), _)) = _
|
16
|
+
def nested_mlhs_rest(((*_, _))) = _
|
17
|
+
}
|
18
|
+
o = klass.new
|
19
|
+
|
20
|
+
o.req_req(1, 2).should == 1
|
21
|
+
o.req_rest_req(1, 2, 3, 4).should == 1
|
22
|
+
o.rest_req(1, 2, 3).should == [1, 2]
|
23
|
+
o.req_opt(1).should == 1
|
24
|
+
o.req_opt(1, 2).should == 1
|
25
|
+
o.opt_req(1).should == 0
|
26
|
+
o.opt_req(1, 2).should == 1
|
27
|
+
o.req_kwopt(1, _: 2).should == 1
|
28
|
+
o.req_kwrest(1, a: 2).should == 1
|
29
|
+
o.req_block(1).should == 1
|
30
|
+
o.req_block(1) {}.should == 1
|
31
|
+
o.req_mlhs(1, [2]).should == 1
|
32
|
+
o.mlhs_req([1], 2).should == 1
|
33
|
+
o.rest_kw(1, 2, _: 3).should == [1, 2]
|
34
|
+
o.nested_mlhs([[1], 2]).should == 1
|
35
|
+
o.nested_mlhs_rest([[1, 2, 3]]).should == [1, 2]
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'in block parameters' do
|
39
|
+
it 'assignes the first arg' do
|
40
|
+
proc { |_, _| _ }.call(1, 2).should == 1
|
41
|
+
proc { |_, *_| _ }.call(1, 2, 3).should == 1
|
42
|
+
proc { |*_, _| _ }.call(1, 2, 3).should == [1, 2]
|
43
|
+
proc { |_, _:| _ }.call(1, _: 2).should == 1
|
44
|
+
proc { |**_, &_| _ }.call(a: 1) {}.should == {a: 1}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'distinguishes two arguments starting with _' do
|
49
|
+
klass = Class.new {
|
50
|
+
def foo(_a, _a, _b, _b) = [_a, _b]
|
51
|
+
}
|
52
|
+
o = klass.new
|
53
|
+
o.foo(1, 2, 3, 4).should == [1, 3]
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'works with yield' do
|
57
|
+
klass = Class.new {
|
58
|
+
def foo(_, &_) = yield * 2
|
59
|
+
}
|
60
|
+
o = klass.new
|
61
|
+
o.foo(1) { 2 }.should == 4
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'works with block_given?' do
|
65
|
+
klass = Class.new {
|
66
|
+
def foo(_, &_) = block_given?
|
67
|
+
}
|
68
|
+
o = klass.new
|
69
|
+
|
70
|
+
o.foo(1).should == false
|
71
|
+
o.foo(1) {}.should == true
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'works with zsuper' do
|
75
|
+
parent = Class.new {
|
76
|
+
def foo(*args, **kwargs, &blk)
|
77
|
+
[args, kwargs, blk.call]
|
78
|
+
end
|
79
|
+
}
|
80
|
+
child = Class.new(parent) {
|
81
|
+
def foo(_, _ = 0, *_, _, _:, **_, &_)
|
82
|
+
super
|
83
|
+
end
|
84
|
+
}
|
85
|
+
o = child.new
|
86
|
+
|
87
|
+
o.foo(1, 2, 3, 4, _: 5, a: 6) { 7 }.should == [[1, 2, 3, 4], {_: 5, a: 6}, 7]
|
88
|
+
end
|
89
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elia Schito
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-
|
13
|
+
date: 2023-11-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ast
|
@@ -602,6 +602,7 @@ files:
|
|
602
602
|
- lib/opal/rewriters/base.rb
|
603
603
|
- lib/opal/rewriters/binary_operator_assignment.rb
|
604
604
|
- lib/opal/rewriters/block_to_iter.rb
|
605
|
+
- lib/opal/rewriters/deduplicate_arg_name.rb
|
605
606
|
- lib/opal/rewriters/dot_js_syntax.rb
|
606
607
|
- lib/opal/rewriters/dump_args.rb
|
607
608
|
- lib/opal/rewriters/for_rewriter.rb
|
@@ -909,6 +910,7 @@ files:
|
|
909
910
|
- spec/opal/core/language/DATA/multiple___END___crlf_spec.rb
|
910
911
|
- spec/opal/core/language/DATA/multiple___END___spec.rb
|
911
912
|
- spec/opal/core/language/arguments/mlhs_arg_spec.rb
|
913
|
+
- spec/opal/core/language/arguments/underscore_arg_spec.rb
|
912
914
|
- spec/opal/core/language/case_spec.rb
|
913
915
|
- spec/opal/core/language/forward_args_spec.rb
|
914
916
|
- spec/opal/core/language/if_spec.rb
|
@@ -1228,10 +1230,10 @@ licenses:
|
|
1228
1230
|
metadata:
|
1229
1231
|
homepage_uri: https://opalrb.com/
|
1230
1232
|
bug_tracker_uri: https://github.com/opal/opal/issues
|
1231
|
-
changelog_uri: https://github.com/opal/opal/blob/v1.8.
|
1232
|
-
readme_uri: https://github.com/opal/opal/blob/v1.8.
|
1233
|
-
api_documentation_uri: http://opalrb.com/docs/api/v1.8.
|
1234
|
-
guides_uri: http://opalrb.com/docs/guides/v1.8.
|
1233
|
+
changelog_uri: https://github.com/opal/opal/blob/v1.8.1/CHANGELOG.md
|
1234
|
+
readme_uri: https://github.com/opal/opal/blob/v1.8.1/README.md
|
1235
|
+
api_documentation_uri: http://opalrb.com/docs/api/v1.8.1/index.html
|
1236
|
+
guides_uri: http://opalrb.com/docs/guides/v1.8.1/index.html
|
1235
1237
|
chat_uri: https://gitter.im/opal/opal
|
1236
1238
|
source_code_uri: https://github.com/opal/opal
|
1237
1239
|
post_install_message:
|
@@ -1601,6 +1603,7 @@ test_files:
|
|
1601
1603
|
- lib/opal/rewriters/base.rb
|
1602
1604
|
- lib/opal/rewriters/binary_operator_assignment.rb
|
1603
1605
|
- lib/opal/rewriters/block_to_iter.rb
|
1606
|
+
- lib/opal/rewriters/deduplicate_arg_name.rb
|
1604
1607
|
- lib/opal/rewriters/dot_js_syntax.rb
|
1605
1608
|
- lib/opal/rewriters/dump_args.rb
|
1606
1609
|
- lib/opal/rewriters/for_rewriter.rb
|