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/enumerator.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
# helpers:
|
1
|
+
# helpers: slice, coerce_to
|
2
2
|
|
3
3
|
require 'corelib/enumerable'
|
4
4
|
|
5
|
-
class Enumerator
|
6
|
-
include Enumerable
|
5
|
+
class ::Enumerator
|
6
|
+
include ::Enumerable
|
7
7
|
|
8
8
|
`self.$$prototype.$$is_enumerator = true`
|
9
9
|
|
@@ -15,12 +15,14 @@ class Enumerator
|
|
15
15
|
obj.size = block;
|
16
16
|
obj.method = method;
|
17
17
|
obj.args = args;
|
18
|
+
obj.cursor = 0;
|
18
19
|
|
19
20
|
return obj;
|
20
21
|
}
|
21
22
|
end
|
22
23
|
|
23
24
|
def initialize(*, &block)
|
25
|
+
@cursor = 0
|
24
26
|
if block
|
25
27
|
@object = Generator.new(&block)
|
26
28
|
@method = :each
|
@@ -28,7 +30,7 @@ class Enumerator
|
|
28
30
|
@size = `arguments[0] || nil`
|
29
31
|
|
30
32
|
if @size && !@size.respond_to?(:call)
|
31
|
-
@size = `$coerce_to(#{@size}, #{Integer}, 'to_int')`
|
33
|
+
@size = `$coerce_to(#{@size}, #{::Integer}, 'to_int')`
|
32
34
|
end
|
33
35
|
else
|
34
36
|
@object = `arguments[0]`
|
@@ -54,7 +56,7 @@ class Enumerator
|
|
54
56
|
|
55
57
|
def with_index(offset = 0, &block)
|
56
58
|
offset = if offset
|
57
|
-
`$coerce_to(offset, #{Integer}, 'to_int')`
|
59
|
+
`$coerce_to(offset, #{::Integer}, 'to_int')`
|
58
60
|
else
|
59
61
|
0
|
60
62
|
end
|
@@ -65,7 +67,7 @@ class Enumerator
|
|
65
67
|
var result, index = offset;
|
66
68
|
|
67
69
|
self.$each.$$p = function() {
|
68
|
-
var param = #{Opal.destructure(`arguments`)},
|
70
|
+
var param = #{::Opal.destructure(`arguments`)},
|
69
71
|
value = block(param, index);
|
70
72
|
|
71
73
|
index++;
|
@@ -77,8 +79,6 @@ class Enumerator
|
|
77
79
|
}
|
78
80
|
end
|
79
81
|
|
80
|
-
alias with_object each_with_object
|
81
|
-
|
82
82
|
def each_with_index(&block)
|
83
83
|
return enum_for(:each_with_index) { size } unless block_given?
|
84
84
|
|
@@ -86,312 +86,57 @@ class Enumerator
|
|
86
86
|
@object
|
87
87
|
end
|
88
88
|
|
89
|
-
def
|
90
|
-
|
91
|
-
|
92
|
-
if @args.any?
|
93
|
-
result += "(#{@args.inspect[Range.new(1, -2)]})"
|
94
|
-
end
|
89
|
+
def rewind
|
90
|
+
@cursor = 0
|
95
91
|
|
96
|
-
|
92
|
+
self
|
97
93
|
end
|
98
94
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
raise LocalJumpError, 'no block given' unless block
|
104
|
-
|
105
|
-
@block = block
|
106
|
-
end
|
107
|
-
|
108
|
-
def each(*args, &block)
|
109
|
-
yielder = Yielder.new(&block)
|
110
|
-
|
111
|
-
%x{
|
112
|
-
try {
|
113
|
-
args.unshift(#{yielder});
|
114
|
-
|
115
|
-
Opal.yieldX(#{@block}, args);
|
116
|
-
}
|
117
|
-
catch (e) {
|
118
|
-
if (e === $breaker) {
|
119
|
-
return $breaker.$v;
|
120
|
-
}
|
121
|
-
else {
|
122
|
-
throw e;
|
123
|
-
}
|
124
|
-
}
|
125
|
-
}
|
126
|
-
|
127
|
-
self
|
128
|
-
end
|
95
|
+
def peek_values
|
96
|
+
@values ||= map { |*i| i }
|
97
|
+
::Kernel.raise ::StopIteration, 'iteration reached an end' if @cursor >= @values.length
|
98
|
+
@values[@cursor]
|
129
99
|
end
|
130
100
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
end
|
135
|
-
|
136
|
-
def yield(*values)
|
137
|
-
%x{
|
138
|
-
var value = Opal.yieldX(#{@block}, values);
|
139
|
-
|
140
|
-
if (value === $breaker) {
|
141
|
-
throw $breaker;
|
142
|
-
}
|
143
|
-
|
144
|
-
return value;
|
145
|
-
}
|
146
|
-
end
|
147
|
-
|
148
|
-
def <<(*values)
|
149
|
-
self.yield(*values)
|
150
|
-
|
151
|
-
self
|
152
|
-
end
|
101
|
+
def peek
|
102
|
+
values = peek_values
|
103
|
+
values.length <= 1 ? values[0] : values
|
153
104
|
end
|
154
105
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
raise ArgumentError, 'tried to call lazy new without a block'
|
161
|
-
end
|
162
|
-
|
163
|
-
@enumerator = object
|
164
|
-
|
165
|
-
super size do |yielder, *each_args|
|
166
|
-
object.each(*each_args) do |*args|
|
167
|
-
%x{
|
168
|
-
args.unshift(#{yielder});
|
169
|
-
|
170
|
-
Opal.yieldX(block, args);
|
171
|
-
}
|
172
|
-
end
|
173
|
-
rescue Exception
|
174
|
-
nil
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
alias force to_a
|
179
|
-
|
180
|
-
def lazy
|
181
|
-
self
|
182
|
-
end
|
183
|
-
|
184
|
-
def collect(&block)
|
185
|
-
unless block
|
186
|
-
raise ArgumentError, 'tried to call lazy map without a block'
|
187
|
-
end
|
188
|
-
|
189
|
-
Lazy.new(self, enumerator_size) do |enum, *args|
|
190
|
-
%x{
|
191
|
-
var value = Opal.yieldX(block, args);
|
192
|
-
|
193
|
-
#{enum.yield `value`};
|
194
|
-
}
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
def collect_concat(&block)
|
199
|
-
unless block
|
200
|
-
raise ArgumentError, 'tried to call lazy map without a block'
|
201
|
-
end
|
202
|
-
|
203
|
-
Lazy.new(self, nil) do |enum, *args|
|
204
|
-
%x{
|
205
|
-
var value = Opal.yieldX(block, args);
|
206
|
-
|
207
|
-
if (#{`value`.respond_to? :force} && #{`value`.respond_to? :each}) {
|
208
|
-
#{`value`.each { |v| enum.yield v }}
|
209
|
-
}
|
210
|
-
else {
|
211
|
-
var array = #{Opal.try_convert `value`, Array, :to_ary};
|
212
|
-
|
213
|
-
if (array === nil) {
|
214
|
-
#{enum.yield `value`};
|
215
|
-
}
|
216
|
-
else {
|
217
|
-
#{`value`.each { |v| enum.yield v }};
|
218
|
-
}
|
219
|
-
}
|
220
|
-
}
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
def drop(n)
|
225
|
-
n = `$coerce_to(#{n}, #{Integer}, 'to_int')`
|
226
|
-
|
227
|
-
if n < 0
|
228
|
-
raise ArgumentError, 'attempt to drop negative size'
|
229
|
-
end
|
230
|
-
|
231
|
-
current_size = enumerator_size
|
232
|
-
set_size = if Integer === current_size
|
233
|
-
n < current_size ? n : current_size
|
234
|
-
else
|
235
|
-
current_size
|
236
|
-
end
|
237
|
-
|
238
|
-
dropped = 0
|
239
|
-
Lazy.new(self, set_size) do |enum, *args|
|
240
|
-
if dropped < n
|
241
|
-
dropped += 1
|
242
|
-
else
|
243
|
-
enum.yield(*args)
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
def drop_while(&block)
|
249
|
-
unless block
|
250
|
-
raise ArgumentError, 'tried to call lazy drop_while without a block'
|
251
|
-
end
|
252
|
-
|
253
|
-
succeeding = true
|
254
|
-
Lazy.new(self, nil) do |enum, *args|
|
255
|
-
if succeeding
|
256
|
-
%x{
|
257
|
-
var value = Opal.yieldX(block, args);
|
258
|
-
|
259
|
-
if ($falsy(value)) {
|
260
|
-
succeeding = false;
|
261
|
-
|
262
|
-
#{enum.yield(*args)};
|
263
|
-
}
|
264
|
-
}
|
265
|
-
else
|
266
|
-
enum.yield(*args)
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
def enum_for(method = :each, *args, &block)
|
272
|
-
self.class.for(self, method, *args, &block)
|
273
|
-
end
|
274
|
-
|
275
|
-
alias filter find_all
|
276
|
-
|
277
|
-
def find_all(&block)
|
278
|
-
unless block
|
279
|
-
raise ArgumentError, 'tried to call lazy select without a block'
|
280
|
-
end
|
281
|
-
|
282
|
-
Lazy.new(self, nil) do |enum, *args|
|
283
|
-
%x{
|
284
|
-
var value = Opal.yieldX(block, args);
|
285
|
-
|
286
|
-
if ($truthy(value)) {
|
287
|
-
#{enum.yield(*args)};
|
288
|
-
}
|
289
|
-
}
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
alias flat_map collect_concat
|
294
|
-
|
295
|
-
def grep(pattern, &block)
|
296
|
-
if block
|
297
|
-
Lazy.new(self, nil) do |enum, *args|
|
298
|
-
%x{
|
299
|
-
var param = #{Opal.destructure(args)},
|
300
|
-
value = #{pattern === `param`};
|
301
|
-
|
302
|
-
if ($truthy(value)) {
|
303
|
-
value = Opal.yield1(block, param);
|
304
|
-
|
305
|
-
#{enum.yield `Opal.yield1(block, param)`};
|
306
|
-
}
|
307
|
-
}
|
308
|
-
end
|
309
|
-
else
|
310
|
-
Lazy.new(self, nil) do |enum, *args|
|
311
|
-
%x{
|
312
|
-
var param = #{Opal.destructure(args)},
|
313
|
-
value = #{pattern === `param`};
|
314
|
-
|
315
|
-
if ($truthy(value)) {
|
316
|
-
#{enum.yield `param`};
|
317
|
-
}
|
318
|
-
}
|
319
|
-
end
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
alias map collect
|
324
|
-
|
325
|
-
alias select find_all
|
326
|
-
|
327
|
-
def reject(&block)
|
328
|
-
unless block
|
329
|
-
raise ArgumentError, 'tried to call lazy reject without a block'
|
330
|
-
end
|
331
|
-
|
332
|
-
Lazy.new(self, nil) do |enum, *args|
|
333
|
-
%x{
|
334
|
-
var value = Opal.yieldX(block, args);
|
335
|
-
|
336
|
-
if ($falsy(value)) {
|
337
|
-
#{enum.yield(*args)};
|
338
|
-
}
|
339
|
-
}
|
340
|
-
end
|
341
|
-
end
|
106
|
+
def next_values
|
107
|
+
out = peek_values
|
108
|
+
@cursor += 1
|
109
|
+
out
|
110
|
+
end
|
342
111
|
|
343
|
-
|
344
|
-
|
112
|
+
def next
|
113
|
+
values = next_values
|
114
|
+
values.length <= 1 ? values[0] : values
|
115
|
+
end
|
345
116
|
|
346
|
-
|
347
|
-
|
348
|
-
|
117
|
+
def feed(arg)
|
118
|
+
raise NotImplementedError, "Opal doesn't support Enumerator#feed"
|
119
|
+
end
|
349
120
|
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
else
|
354
|
-
current_size
|
355
|
-
end
|
356
|
-
|
357
|
-
taken = 0
|
358
|
-
Lazy.new(self, set_size) do |enum, *args|
|
359
|
-
if taken < n
|
360
|
-
enum.yield(*args)
|
361
|
-
taken += 1
|
362
|
-
else
|
363
|
-
raise StopLazyError
|
364
|
-
end
|
365
|
-
end
|
366
|
-
end
|
121
|
+
def +(other)
|
122
|
+
::Enumerator::Chain.new(self, other)
|
123
|
+
end
|
367
124
|
|
368
|
-
|
369
|
-
|
370
|
-
raise ArgumentError, 'tried to call lazy take_while without a block'
|
371
|
-
end
|
125
|
+
def inspect
|
126
|
+
result = "#<#{self.class}: #{@object.inspect}:#{@method}"
|
372
127
|
|
373
|
-
|
374
|
-
|
375
|
-
var value = Opal.yieldX(block, args);
|
376
|
-
|
377
|
-
if ($truthy(value)) {
|
378
|
-
#{enum.yield(*args)};
|
379
|
-
}
|
380
|
-
else {
|
381
|
-
#{raise StopLazyError};
|
382
|
-
}
|
383
|
-
}
|
384
|
-
end
|
128
|
+
if @args.any?
|
129
|
+
result += "(#{@args.inspect[::Range.new(1, -2)]})"
|
385
130
|
end
|
386
131
|
|
387
|
-
|
388
|
-
|
389
|
-
def inspect
|
390
|
-
"#<#{self.class}: #{@enumerator.inspect}>"
|
391
|
-
end
|
132
|
+
result + '>'
|
392
133
|
end
|
393
134
|
|
394
|
-
|
395
|
-
|
396
|
-
|
135
|
+
alias with_object each_with_object
|
136
|
+
|
137
|
+
autoload :ArithmeticSequence, 'corelib/enumerator/arithmetic_sequence'
|
138
|
+
autoload :Chain, 'corelib/enumerator/chain'
|
139
|
+
autoload :Generator, 'corelib/enumerator/generator'
|
140
|
+
autoload :Lazy, 'corelib/enumerator/lazy'
|
141
|
+
autoload :Yielder, 'corelib/enumerator/yielder'
|
397
142
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module ::Errno
|
2
|
+
errors = [
|
3
|
+
[:EINVAL, 'Invalid argument', 22],
|
4
|
+
[:EEXIST, 'File exists', 17],
|
5
|
+
[:EISDIR, 'Is a directory', 21],
|
6
|
+
[:EMFILE, 'Too many open files', 24],
|
7
|
+
[:EACCES, 'Permission denied', 13],
|
8
|
+
[:EPERM, 'Operation not permitted', 1],
|
9
|
+
[:ENOENT, 'No such file or directory', 2]
|
10
|
+
]
|
11
|
+
|
12
|
+
klass = nil
|
13
|
+
|
14
|
+
%x{
|
15
|
+
var i;
|
16
|
+
for (i = 0; i < errors.length; i++) {
|
17
|
+
(function() { // Create a closure
|
18
|
+
var class_name = errors[i][0];
|
19
|
+
var default_message = errors[i][1];
|
20
|
+
var errno = errors[i][2];
|
21
|
+
|
22
|
+
klass = Opal.klass(self, Opal.SystemCallError, class_name);
|
23
|
+
klass.errno = errno;
|
24
|
+
|
25
|
+
#{
|
26
|
+
class << klass
|
27
|
+
def new(name = nil)
|
28
|
+
message = `default_message`
|
29
|
+
message += " - #{name}" if name
|
30
|
+
super(message)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
}
|
34
|
+
})();
|
35
|
+
}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
class ::SystemCallError < ::StandardError
|
40
|
+
def errno
|
41
|
+
self.class.errno
|
42
|
+
end
|
43
|
+
|
44
|
+
class << self
|
45
|
+
attr_reader :errno
|
46
|
+
end
|
47
|
+
end
|
data/opal/corelib/error.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
class Exception < `Error`
|
2
|
-
`Opal.
|
1
|
+
class ::Exception < `Error`
|
2
|
+
`Opal.prop(self.$$prototype, '$$is_exception', true)`
|
3
3
|
`var stack_trace_limit`
|
4
4
|
|
5
5
|
def self.new(*args)
|
@@ -119,9 +119,19 @@ class Exception < `Error`
|
|
119
119
|
to_s
|
120
120
|
end
|
121
121
|
|
122
|
-
def full_message(
|
123
|
-
|
124
|
-
|
122
|
+
def full_message(kwargs = nil)
|
123
|
+
unless defined? Hash
|
124
|
+
# We are dealing with an unfully loaded Opal library, so we should
|
125
|
+
# do with as little as we can.
|
126
|
+
|
127
|
+
return "#{@message}\n#{`self.stack`}"
|
128
|
+
end
|
129
|
+
|
130
|
+
kwargs = { highlight: $stderr.tty?, order: :top }.merge(kwargs || {})
|
131
|
+
highlight, order = kwargs[:highlight], kwargs[:order]
|
132
|
+
|
133
|
+
::Kernel.raise ::ArgumentError, "expected true or false as highlight: #{highlight}" unless [true, false].include? highlight
|
134
|
+
::Kernel.raise ::ArgumentError, "expected :top or :bottom as order: #{order}" unless %i[top bottom].include? order
|
125
135
|
|
126
136
|
if highlight
|
127
137
|
bold_underline = "\e[1;4m"
|
@@ -178,7 +188,7 @@ class Exception < `Error`
|
|
178
188
|
}
|
179
189
|
|
180
190
|
if (valid === false) {
|
181
|
-
#{raise TypeError, 'backtrace must be Array of String'}
|
191
|
+
#{::Kernel.raise ::TypeError, 'backtrace must be Array of String'}
|
182
192
|
}
|
183
193
|
|
184
194
|
self.backtrace = backtrace;
|
@@ -196,53 +206,45 @@ class Exception < `Error`
|
|
196
206
|
end
|
197
207
|
|
198
208
|
# keep the indentation, it makes the exception hierarchy clear
|
199
|
-
class ScriptError < Exception; end
|
200
|
-
class SyntaxError < ScriptError; end
|
201
|
-
class LoadError < ScriptError; end
|
202
|
-
class NotImplementedError < ScriptError; end
|
203
|
-
|
204
|
-
class SystemExit < Exception; end
|
205
|
-
class NoMemoryError < Exception; end
|
206
|
-
class SignalException < Exception; end
|
207
|
-
class Interrupt < SignalException; end
|
208
|
-
class SecurityError < Exception; end
|
209
|
-
class SystemStackError < Exception; end
|
210
|
-
|
211
|
-
class StandardError < Exception; end
|
212
|
-
class EncodingError < StandardError; end
|
213
|
-
class ZeroDivisionError < StandardError; end
|
214
|
-
class NameError < StandardError; end
|
215
|
-
class NoMethodError < NameError; end
|
216
|
-
class RuntimeError < StandardError; end
|
217
|
-
class FrozenError < RuntimeError; end
|
218
|
-
class LocalJumpError < StandardError; end
|
219
|
-
class TypeError < StandardError; end
|
220
|
-
class ArgumentError < StandardError; end
|
221
|
-
class UncaughtThrowError < ArgumentError; end
|
222
|
-
class IndexError < StandardError; end
|
223
|
-
class StopIteration < IndexError; end
|
224
|
-
class ClosedQueueError < StopIteration; end
|
225
|
-
class KeyError < IndexError; end
|
226
|
-
class RangeError < StandardError; end
|
227
|
-
class FloatDomainError < RangeError; end
|
228
|
-
class IOError < StandardError; end
|
229
|
-
class EOFError < IOError; end
|
230
|
-
class SystemCallError < StandardError; end
|
231
|
-
class RegexpError < StandardError; end
|
232
|
-
class ThreadError < StandardError; end
|
233
|
-
class FiberError < StandardError; end
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
message = 'Invalid argument'
|
239
|
-
message += " - #{name}" if name
|
240
|
-
super(message)
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
class UncaughtThrowError < ArgumentError
|
209
|
+
class ::ScriptError < ::Exception; end
|
210
|
+
class ::SyntaxError < ::ScriptError; end
|
211
|
+
class ::LoadError < ::ScriptError; end
|
212
|
+
class ::NotImplementedError < ::ScriptError; end
|
213
|
+
|
214
|
+
class ::SystemExit < ::Exception; end
|
215
|
+
class ::NoMemoryError < ::Exception; end
|
216
|
+
class ::SignalException < ::Exception; end
|
217
|
+
class ::Interrupt < ::SignalException; end
|
218
|
+
class ::SecurityError < ::Exception; end
|
219
|
+
class ::SystemStackError < ::Exception; end
|
220
|
+
|
221
|
+
class ::StandardError < ::Exception; end
|
222
|
+
class ::EncodingError < ::StandardError; end
|
223
|
+
class ::ZeroDivisionError < ::StandardError; end
|
224
|
+
class ::NameError < ::StandardError; end
|
225
|
+
class ::NoMethodError < ::NameError; end
|
226
|
+
class ::RuntimeError < ::StandardError; end
|
227
|
+
class ::FrozenError < ::RuntimeError; end
|
228
|
+
class ::LocalJumpError < ::StandardError; end
|
229
|
+
class ::TypeError < ::StandardError; end
|
230
|
+
class ::ArgumentError < ::StandardError; end
|
231
|
+
class ::UncaughtThrowError < ::ArgumentError; end
|
232
|
+
class ::IndexError < ::StandardError; end
|
233
|
+
class ::StopIteration < ::IndexError; end
|
234
|
+
class ::ClosedQueueError < ::StopIteration; end
|
235
|
+
class ::KeyError < ::IndexError; end
|
236
|
+
class ::RangeError < ::StandardError; end
|
237
|
+
class ::FloatDomainError < ::RangeError; end
|
238
|
+
class ::IOError < ::StandardError; end
|
239
|
+
class ::EOFError < ::IOError; end
|
240
|
+
class ::SystemCallError < ::StandardError; end
|
241
|
+
class ::RegexpError < ::StandardError; end
|
242
|
+
class ::ThreadError < ::StandardError; end
|
243
|
+
class ::FiberError < ::StandardError; end
|
244
|
+
|
245
|
+
::Object.autoload :Errno, 'corelib/error/errno'
|
246
|
+
|
247
|
+
class ::UncaughtThrowError < ::ArgumentError
|
246
248
|
attr_reader :tag, :value
|
247
249
|
|
248
250
|
def initialize(tag, value = nil)
|
@@ -253,7 +255,7 @@ class UncaughtThrowError < ArgumentError
|
|
253
255
|
end
|
254
256
|
end
|
255
257
|
|
256
|
-
class NameError
|
258
|
+
class ::NameError
|
257
259
|
attr_reader :name
|
258
260
|
|
259
261
|
def initialize(message, name = nil)
|
@@ -262,7 +264,7 @@ class NameError
|
|
262
264
|
end
|
263
265
|
end
|
264
266
|
|
265
|
-
class NoMethodError
|
267
|
+
class ::NoMethodError
|
266
268
|
attr_reader :args
|
267
269
|
|
268
270
|
def initialize(message, name = nil, args = [])
|
@@ -271,11 +273,11 @@ class NoMethodError
|
|
271
273
|
end
|
272
274
|
end
|
273
275
|
|
274
|
-
class StopIteration
|
276
|
+
class ::StopIteration
|
275
277
|
attr_reader :result
|
276
278
|
end
|
277
279
|
|
278
|
-
class KeyError
|
280
|
+
class ::KeyError
|
279
281
|
def initialize(message, receiver: nil, key: nil)
|
280
282
|
super(message)
|
281
283
|
@receiver = receiver
|
@@ -283,15 +285,15 @@ class KeyError
|
|
283
285
|
end
|
284
286
|
|
285
287
|
def receiver
|
286
|
-
@receiver || raise(ArgumentError, 'no receiver is available')
|
288
|
+
@receiver || ::Kernel.raise(::ArgumentError, 'no receiver is available')
|
287
289
|
end
|
288
290
|
|
289
291
|
def key
|
290
|
-
@key || raise(ArgumentError, 'no key is available')
|
292
|
+
@key || ::Kernel.raise(::ArgumentError, 'no key is available')
|
291
293
|
end
|
292
294
|
end
|
293
295
|
|
294
|
-
module JS
|
296
|
+
module ::JS
|
295
297
|
class Error
|
296
298
|
end
|
297
299
|
end
|