opal 0.9.4 → 0.10.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +1 -0
- data/.gitignore +2 -3
- data/.gitmodules +5 -2
- data/.jshintrc +1 -8
- data/.rspec +1 -1
- data/.travis.yml +15 -23
- data/CHANGELOG.md +511 -326
- data/CODE_OF_CONDUCT.md +13 -15
- data/CONTRIBUTING.md +26 -216
- data/Gemfile +20 -12
- data/Guardfile +2 -2
- data/HACKING.md +230 -0
- data/README.md +6 -7
- data/bin/opal-mspec +1 -1
- data/config.ru +2 -2
- data/docs/faq.md +1 -1
- data/docs/source_maps.md +1 -1
- data/lib/opal.rb +1 -0
- data/lib/opal/builder.rb +1 -1
- data/lib/opal/cli.rb +30 -28
- data/lib/opal/cli_options.rb +3 -0
- data/lib/opal/cli_runners.rb +14 -1
- data/lib/opal/cli_runners/{apple_script.rb → applescript.rb} +3 -3
- data/lib/opal/cli_runners/nashorn.rb +2 -2
- data/lib/opal/cli_runners/nodejs.rb +2 -2
- data/lib/opal/cli_runners/phantom.js +24 -0
- data/lib/opal/cli_runners/phantomjs.rb +10 -10
- data/lib/opal/cli_runners/server.rb +3 -3
- data/lib/opal/compiler.rb +43 -4
- data/lib/opal/config.rb +3 -1
- data/lib/opal/errors.rb +13 -0
- data/lib/opal/fragment.rb +0 -13
- data/lib/opal/nodes.rb +10 -0
- data/lib/opal/nodes/args/initialize_kwargs.rb +28 -0
- data/lib/opal/nodes/args/kwarg.rb +29 -0
- data/lib/opal/nodes/args/kwoptarg.rb +29 -0
- data/lib/opal/nodes/args/kwrestarg.rb +39 -0
- data/lib/opal/nodes/args/mlhsarg.rb +79 -0
- data/lib/opal/nodes/args/normarg.rb +26 -0
- data/lib/opal/nodes/args/optarg.rb +27 -0
- data/lib/opal/nodes/args/post_args.rb +200 -0
- data/lib/opal/nodes/args/post_kwargs.rb +31 -0
- data/lib/opal/nodes/args/restarg.rb +33 -0
- data/lib/opal/nodes/base.rb +12 -0
- data/lib/opal/nodes/call.rb +92 -33
- data/lib/opal/nodes/def.rb +26 -169
- data/lib/opal/nodes/hash.rb +10 -4
- data/lib/opal/nodes/helpers.rb +6 -3
- data/lib/opal/nodes/inline_args.rb +61 -0
- data/lib/opal/nodes/iter.rb +73 -82
- data/lib/opal/nodes/logic.rb +12 -2
- data/lib/opal/nodes/masgn.rb +1 -2
- data/lib/opal/nodes/node_with_args.rb +141 -0
- data/lib/opal/nodes/rescue.rb +121 -43
- data/lib/opal/nodes/scope.rb +24 -5
- data/lib/opal/nodes/super.rb +122 -54
- data/lib/opal/nodes/top.rb +0 -12
- data/lib/opal/nodes/yield.rb +2 -13
- data/lib/opal/parser.rb +67 -39
- data/lib/opal/parser/grammar.rb +3319 -2961
- data/lib/opal/parser/grammar.y +234 -46
- data/lib/opal/parser/lexer.rb +105 -17
- data/lib/opal/parser/sexp.rb +4 -0
- data/lib/opal/paths.rb +4 -0
- data/lib/opal/regexp_anchors.rb +19 -1
- data/lib/opal/sprockets.rb +21 -18
- data/lib/opal/sprockets/environment.rb +0 -8
- data/lib/opal/sprockets/processor.rb +13 -16
- data/lib/opal/sprockets/server.rb +6 -12
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +1 -0
- data/opal/corelib/array.rb +209 -131
- data/opal/corelib/basic_object.rb +7 -3
- data/opal/corelib/class.rb +11 -17
- data/opal/corelib/constants.rb +2 -2
- data/opal/corelib/enumerable.rb +178 -355
- data/opal/corelib/enumerator.rb +3 -46
- data/opal/corelib/error.rb +2 -2
- data/opal/corelib/file.rb +13 -1
- data/opal/corelib/hash.rb +26 -56
- data/opal/corelib/helpers.rb +10 -0
- data/opal/corelib/kernel.rb +6 -3
- data/opal/corelib/module.rb +62 -31
- data/opal/corelib/number.rb +7 -16
- data/opal/corelib/proc.rb +24 -9
- data/opal/corelib/range.rb +4 -13
- data/opal/corelib/runtime.js +515 -378
- data/opal/corelib/string.rb +21 -49
- data/opal/corelib/struct.rb +50 -35
- data/opal/corelib/unsupported.rb +18 -30
- data/opal/opal.rb +0 -1
- data/opal/opal/mini.rb +1 -0
- data/spec/README.md +6 -4
- data/spec/filters/bugs/array.rb +0 -42
- data/spec/filters/bugs/basicobject.rb +0 -2
- data/spec/filters/bugs/bigdecimal.rb +160 -0
- data/spec/filters/bugs/class.rb +0 -5
- data/spec/filters/bugs/date.rb +1 -48
- data/spec/filters/bugs/enumerable.rb +4 -12
- data/spec/filters/bugs/enumerator.rb +0 -1
- data/spec/filters/bugs/exception.rb +4 -3
- data/spec/filters/bugs/float.rb +4 -2
- data/spec/filters/bugs/kernel.rb +25 -10
- data/spec/filters/bugs/language.rb +119 -68
- data/spec/filters/bugs/method.rb +135 -0
- data/spec/filters/bugs/module.rb +13 -28
- data/spec/filters/bugs/proc.rb +18 -8
- data/spec/filters/bugs/range.rb +0 -3
- data/spec/filters/bugs/rational.rb +4 -0
- data/spec/filters/bugs/regexp.rb +68 -36
- data/spec/filters/bugs/string.rb +1 -1
- data/spec/filters/bugs/struct.rb +0 -12
- data/spec/filters/bugs/time.rb +1 -0
- data/spec/filters/bugs/unboundmethod.rb +2 -1
- data/spec/filters/unsupported/freeze.rb +3 -1
- data/spec/filters/unsupported/language.rb +0 -7
- data/spec/filters/unsupported/privacy.rb +7 -6
- data/spec/filters/unsupported/string.rb +10 -0
- data/spec/filters/unsupported/struct.rb +3 -0
- data/spec/filters/unsupported/symbol.rb +9 -0
- data/spec/filters/unsupported/taint.rb +0 -3
- data/spec/filters/unsupported/thread.rb +1 -0
- data/spec/lib/cli_runners/phantomjs_spec.rb +39 -0
- data/spec/lib/cli_spec.rb +42 -1
- data/spec/lib/compiler/call_spec.rb +700 -0
- data/spec/lib/compiler_spec.rb +46 -28
- data/spec/lib/config_spec.rb +13 -0
- data/spec/lib/parser/call_spec.rb +18 -0
- data/spec/lib/parser/def_spec.rb +29 -0
- data/spec/lib/parser/iter_spec.rb +15 -15
- data/spec/lib/parser/lambda_spec.rb +153 -12
- data/spec/lib/parser/string_spec.rb +5 -0
- data/spec/lib/parser/undef_spec.rb +1 -1
- data/spec/lib/parser/variables_spec.rb +24 -0
- data/spec/lib/paths_spec.rb +12 -5
- data/spec/lib/spec_helper.rb +5 -0
- data/spec/lib/sprockets/processor_spec.rb +6 -5
- data/spec/lib/sprockets_spec.rb +8 -0
- data/spec/mspec-opal/formatters.rb +188 -0
- data/spec/mspec-opal/runner.rb +193 -0
- data/spec/opal/core/enumerator/with_index_spec.rb +6 -0
- data/spec/opal/core/kernel/define_singleton_method_spec.rb +1 -1
- data/spec/opal/core/kernel/instance_variables_spec.rb +14 -0
- data/spec/opal/core/kernel/loop_spec.rb +1 -1
- data/spec/opal/core/kernel/raise_spec.rb +1 -1
- data/spec/opal/core/language/heredoc_spec.rb +42 -0
- data/spec/opal/core/language/rescue_spec.rb +18 -0
- data/spec/opal/core/language_spec.rb +22 -0
- data/spec/opal/core/module/const_defined_spec.rb +1 -2
- data/spec/opal/core/module/name_spec.rb +6 -0
- data/spec/opal/core/runtime/bridged_classes_spec.rb +14 -2
- data/spec/opal/core/runtime/rescue_spec.rb +12 -2
- data/spec/opal/core/runtime/super_spec.rb +1 -0
- data/spec/opal/core/string_spec.rb +21 -0
- data/spec/opal/stdlib/js_spec.rb +1 -1
- data/spec/opal/stdlib/native/hash_spec.rb +7 -0
- data/spec/opal/stdlib/promise/always_spec.rb +24 -5
- data/spec/opal/stdlib/promise/rescue_spec.rb +15 -6
- data/spec/opal/stdlib/promise/then_spec.rb +13 -5
- data/spec/opal/stdlib/promise/trace_spec.rb +5 -6
- data/spec/opal/stdlib/strscan/scan_spec.rb +1 -1
- data/spec/ruby_specs +122 -0
- data/spec/spec_helper.rb +3 -15
- data/stdlib/base64.rb +51 -121
- data/stdlib/bigdecimal.rb +231 -0
- data/stdlib/bigdecimal/bignumber.js.rb +11 -0
- data/stdlib/bigdecimal/kernel.rb +5 -0
- data/stdlib/date.rb +252 -10
- data/stdlib/native.rb +38 -38
- data/stdlib/nodejs/dir.rb +8 -6
- data/stdlib/nodejs/file.rb +28 -3
- data/stdlib/nodejs/node_modules/.bin/js-yaml +1 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/.bin/esparse +1 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/.bin/esvalidate +1 -0
- data/stdlib/nodejs/require.rb +1 -1
- data/stdlib/nodejs/yaml.rb +3 -2
- data/stdlib/opal-parser.rb +7 -2
- data/stdlib/pathname.rb +23 -1
- data/stdlib/phantomjs.rb +10 -0
- data/stdlib/promise.rb +38 -23
- data/tasks/building.rake +3 -3
- data/tasks/testing.rake +27 -14
- data/tasks/testing/mspec_special_calls.rb +1 -1
- data/tasks/testing/sprockets-phantomjs.js +4 -0
- data/test/opal/test_keyword.rb +110 -110
- data/test/opal/unsupported_and_bugs.rb +30 -0
- data/vendored-minitest/minitest/assertions.rb +1 -1
- metadata +65 -15
- data/.spectator +0 -2
- data/.spectator-mspec +0 -3
- data/opal/corelib/array/inheritance.rb +0 -127
- data/spec/rubyspecs +0 -139
data/opal/corelib/string.rb
CHANGED
@@ -359,11 +359,7 @@ class String < `String`
|
|
359
359
|
|
360
360
|
%x{
|
361
361
|
for (var i = 0, length = self.length; i < length; i++) {
|
362
|
-
|
363
|
-
|
364
|
-
if (value === $breaker) {
|
365
|
-
return $breaker.$v;
|
366
|
-
}
|
362
|
+
Opal.yield1(block, self.charAt(i));
|
367
363
|
}
|
368
364
|
}
|
369
365
|
|
@@ -374,17 +370,10 @@ class String < `String`
|
|
374
370
|
return enum_for :each_line, separator unless block_given?
|
375
371
|
|
376
372
|
%x{
|
377
|
-
var value;
|
378
|
-
|
379
373
|
if (separator === nil) {
|
380
|
-
|
374
|
+
Opal.yield1(block, self);
|
381
375
|
|
382
|
-
|
383
|
-
return value.$v;
|
384
|
-
}
|
385
|
-
else {
|
386
|
-
return self;
|
387
|
-
}
|
376
|
+
return self;
|
388
377
|
}
|
389
378
|
|
390
379
|
separator = #{Opal.coerce_to(`separator`, String, :to_str)}
|
@@ -394,11 +383,7 @@ class String < `String`
|
|
394
383
|
if (separator.length === 0) {
|
395
384
|
for (a = self.split(/(\n{2,})/), i = 0, n = a.length; i < n; i += 2) {
|
396
385
|
if (a[i] || a[i + 1]) {
|
397
|
-
|
398
|
-
|
399
|
-
if (value === $breaker) {
|
400
|
-
return value.$v;
|
401
|
-
}
|
386
|
+
Opal.yield1(block, (a[i] || "") + (a[i + 1] || ""));
|
402
387
|
}
|
403
388
|
}
|
404
389
|
|
@@ -411,18 +396,10 @@ class String < `String`
|
|
411
396
|
|
412
397
|
for (i = 0, length = splitted.length; i < length; i++) {
|
413
398
|
if (i < length - 1 || trailing) {
|
414
|
-
|
415
|
-
|
416
|
-
if (value === $breaker) {
|
417
|
-
return value.$v;
|
418
|
-
}
|
399
|
+
Opal.yield1(block, splitted[i] + separator);
|
419
400
|
}
|
420
401
|
else {
|
421
|
-
|
422
|
-
|
423
|
-
if (value === $breaker) {
|
424
|
-
return value.$v;
|
425
|
-
}
|
402
|
+
Opal.yield1(block, splitted[i]);
|
426
403
|
}
|
427
404
|
}
|
428
405
|
}
|
@@ -533,16 +510,11 @@ class String < `String`
|
|
533
510
|
|
534
511
|
def include?(other)
|
535
512
|
%x{
|
536
|
-
if (other.$$is_string) {
|
537
|
-
|
513
|
+
if (!other.$$is_string) {
|
514
|
+
#{other = Opal.coerce_to(other, String, :to_str)}
|
538
515
|
}
|
516
|
+
return self.indexOf(other) !== -1;
|
539
517
|
}
|
540
|
-
|
541
|
-
unless other.respond_to? :to_str
|
542
|
-
raise TypeError, "no implicit conversion of #{other.class} into String"
|
543
|
-
end
|
544
|
-
|
545
|
-
`self.indexOf(#{other.to_str}) !== -1`
|
546
518
|
end
|
547
519
|
|
548
520
|
def index(search, offset = undefined)
|
@@ -1032,6 +1004,10 @@ class String < `String`
|
|
1032
1004
|
return result;
|
1033
1005
|
}
|
1034
1006
|
|
1007
|
+
if (limit >= result.length) {
|
1008
|
+
return result;
|
1009
|
+
}
|
1010
|
+
|
1035
1011
|
i = 0;
|
1036
1012
|
while (match !== null) {
|
1037
1013
|
i++;
|
@@ -1041,7 +1017,6 @@ class String < `String`
|
|
1041
1017
|
}
|
1042
1018
|
match = pattern.exec(string);
|
1043
1019
|
}
|
1044
|
-
|
1045
1020
|
result.splice(limit - 1, result.length - 1, string.slice(index));
|
1046
1021
|
return result;
|
1047
1022
|
}
|
@@ -1339,8 +1314,8 @@ class String < `String`
|
|
1339
1314
|
in_range = false;
|
1340
1315
|
for (i = 0; i < to_length; i++) {
|
1341
1316
|
ch = to_chars[i];
|
1342
|
-
if (
|
1343
|
-
|
1317
|
+
if (last_to == null) {
|
1318
|
+
last_to = ch;
|
1344
1319
|
to_chars_expanded.push(ch);
|
1345
1320
|
}
|
1346
1321
|
else if (ch === '-') {
|
@@ -1356,7 +1331,7 @@ class String < `String`
|
|
1356
1331
|
}
|
1357
1332
|
}
|
1358
1333
|
else if (in_range) {
|
1359
|
-
start =
|
1334
|
+
start = last_to.charCodeAt(0);
|
1360
1335
|
end = ch.charCodeAt(0);
|
1361
1336
|
if (start > end) {
|
1362
1337
|
#{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
|
@@ -1366,7 +1341,7 @@ class String < `String`
|
|
1366
1341
|
}
|
1367
1342
|
to_chars_expanded.push(ch);
|
1368
1343
|
in_range = null;
|
1369
|
-
|
1344
|
+
last_to = null;
|
1370
1345
|
}
|
1371
1346
|
else {
|
1372
1347
|
to_chars_expanded.push(ch);
|
@@ -1575,7 +1550,7 @@ class String < `String`
|
|
1575
1550
|
return enum_for :upto, stop, excl unless block_given?
|
1576
1551
|
stop = Opal.coerce_to(stop, String, :to_str)
|
1577
1552
|
%x{
|
1578
|
-
var a, b, s = self.toString()
|
1553
|
+
var a, b, s = self.toString();
|
1579
1554
|
|
1580
1555
|
if (s.length === 1 && stop.length === 1) {
|
1581
1556
|
|
@@ -1587,8 +1562,7 @@ class String < `String`
|
|
1587
1562
|
break;
|
1588
1563
|
}
|
1589
1564
|
|
1590
|
-
|
1591
|
-
if (value === $breaker) { return $breaker.$v; }
|
1565
|
+
block(String.fromCharCode(a));
|
1592
1566
|
|
1593
1567
|
a += 1;
|
1594
1568
|
}
|
@@ -1603,8 +1577,7 @@ class String < `String`
|
|
1603
1577
|
break;
|
1604
1578
|
}
|
1605
1579
|
|
1606
|
-
|
1607
|
-
if (value === $breaker) { return $breaker.$v; }
|
1580
|
+
block(a.toString());
|
1608
1581
|
|
1609
1582
|
a += 1;
|
1610
1583
|
}
|
@@ -1616,8 +1589,7 @@ class String < `String`
|
|
1616
1589
|
break;
|
1617
1590
|
}
|
1618
1591
|
|
1619
|
-
|
1620
|
-
if (value === $breaker) { return $breaker.$v; }
|
1592
|
+
block(s);
|
1621
1593
|
|
1622
1594
|
s = #{`s`.succ};
|
1623
1595
|
}
|
data/opal/corelib/struct.rb
CHANGED
@@ -3,31 +3,42 @@ require 'corelib/enumerable'
|
|
3
3
|
class Struct
|
4
4
|
include Enumerable
|
5
5
|
|
6
|
-
def self.new(
|
7
|
-
|
6
|
+
def self.new(const_name, *args, &block)
|
7
|
+
if const_name
|
8
|
+
begin
|
9
|
+
const_name = Opal.const_name!(const_name)
|
10
|
+
rescue TypeError, NameError
|
11
|
+
args.unshift(const_name)
|
12
|
+
const_name = nil
|
13
|
+
end
|
14
|
+
end
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
args.unshift name
|
16
|
+
args.map do |arg|
|
17
|
+
Opal.coerce_to!(arg, String, :to_str)
|
18
|
+
end
|
13
19
|
|
14
|
-
|
15
|
-
|
20
|
+
klass = Class.new(self) do
|
21
|
+
args.each { |arg| define_struct_attribute(arg) }
|
16
22
|
|
17
|
-
|
23
|
+
class << self
|
24
|
+
def new(*args)
|
25
|
+
instance = allocate
|
26
|
+
`#{instance}.$$data = {};`
|
27
|
+
instance.initialize(*args)
|
28
|
+
instance
|
29
|
+
end
|
18
30
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
`#{instance}.$$data = {};`
|
23
|
-
instance.initialize(*args)
|
24
|
-
instance
|
25
|
-
end
|
31
|
+
alias [] new
|
32
|
+
end
|
33
|
+
end
|
26
34
|
|
27
|
-
|
28
|
-
|
29
|
-
|
35
|
+
klass.module_eval(&block) if block
|
36
|
+
|
37
|
+
if const_name
|
38
|
+
Struct.const_set(const_name, klass)
|
30
39
|
end
|
40
|
+
|
41
|
+
klass
|
31
42
|
end
|
32
43
|
|
33
44
|
def self.define_struct_attribute(name)
|
@@ -43,7 +54,7 @@ class Struct
|
|
43
54
|
|
44
55
|
define_method "#{name}=" do |value|
|
45
56
|
`self.$$data[name] = value`
|
46
|
-
end
|
57
|
+
end
|
47
58
|
end
|
48
59
|
|
49
60
|
def self.members
|
@@ -63,7 +74,11 @@ class Struct
|
|
63
74
|
end
|
64
75
|
|
65
76
|
def initialize(*args)
|
66
|
-
|
77
|
+
if args.length > self.class.members.length
|
78
|
+
raise ArgumentError, "struct size differs"
|
79
|
+
end
|
80
|
+
|
81
|
+
self.class.members.each_with_index {|name, index|
|
67
82
|
self[name] = args[index]
|
68
83
|
}
|
69
84
|
end
|
@@ -71,17 +86,17 @@ class Struct
|
|
71
86
|
def members
|
72
87
|
self.class.members
|
73
88
|
end
|
74
|
-
|
89
|
+
|
75
90
|
def hash
|
76
91
|
Hash.new(`self.$$data`).hash
|
77
92
|
end
|
78
93
|
|
79
94
|
def [](name)
|
80
95
|
if Integer === name
|
81
|
-
raise IndexError, "offset #{name} too small for struct(size:#{members.size})" if name < -members.size
|
82
|
-
raise IndexError, "offset #{name} too large for struct(size:#{members.size})" if name >= members.size
|
96
|
+
raise IndexError, "offset #{name} too small for struct(size:#{self.class.members.size})" if name < -self.class.members.size
|
97
|
+
raise IndexError, "offset #{name} too large for struct(size:#{self.class.members.size})" if name >= self.class.members.size
|
83
98
|
|
84
|
-
name = members[name]
|
99
|
+
name = self.class.members[name]
|
85
100
|
elsif String === name
|
86
101
|
%x{
|
87
102
|
if(!self.$$data.hasOwnProperty(name)) {
|
@@ -98,12 +113,12 @@ class Struct
|
|
98
113
|
|
99
114
|
def []=(name, value)
|
100
115
|
if Integer === name
|
101
|
-
raise IndexError, "offset #{name} too small for struct(size:#{members.size})" if name < -members.size
|
102
|
-
raise IndexError, "offset #{name} too large for struct(size:#{members.size})" if name >= members.size
|
116
|
+
raise IndexError, "offset #{name} too small for struct(size:#{self.class.members.size})" if name < -self.class.members.size
|
117
|
+
raise IndexError, "offset #{name} too large for struct(size:#{self.class.members.size})" if name >= self.class.members.size
|
103
118
|
|
104
|
-
name = members[name]
|
119
|
+
name = self.class.members[name]
|
105
120
|
elsif String === name
|
106
|
-
raise NameError.new("no member '#{name}' in struct", name) unless members.include?(name.to_sym)
|
121
|
+
raise NameError.new("no member '#{name}' in struct", name) unless self.class.members.include?(name.to_sym)
|
107
122
|
else
|
108
123
|
raise TypeError, "no implicit conversion of #{name.class} into Integer"
|
109
124
|
end
|
@@ -187,25 +202,25 @@ class Struct
|
|
187
202
|
def each
|
188
203
|
return enum_for(:each){self.size} unless block_given?
|
189
204
|
|
190
|
-
members.each { |name| yield self[name] }
|
205
|
+
self.class.members.each { |name| yield self[name] }
|
191
206
|
self
|
192
207
|
end
|
193
208
|
|
194
209
|
def each_pair
|
195
210
|
return enum_for(:each_pair){self.size} unless block_given?
|
196
211
|
|
197
|
-
members.each { |name| yield [name, self[name]] }
|
212
|
+
self.class.members.each { |name| yield [name, self[name]] }
|
198
213
|
self
|
199
214
|
end
|
200
215
|
|
201
216
|
def length
|
202
|
-
members.length
|
217
|
+
self.class.members.length
|
203
218
|
end
|
204
219
|
|
205
220
|
alias size length
|
206
221
|
|
207
222
|
def to_a
|
208
|
-
members.map { |name| self[name] }
|
223
|
+
self.class.members.map { |name| self[name] }
|
209
224
|
end
|
210
225
|
|
211
226
|
alias values to_a
|
@@ -213,7 +228,7 @@ class Struct
|
|
213
228
|
def inspect
|
214
229
|
result = "#<struct "
|
215
230
|
|
216
|
-
if self.class
|
231
|
+
if Struct === self && self.class.name
|
217
232
|
result += "#{self.class} "
|
218
233
|
end
|
219
234
|
|
@@ -229,7 +244,7 @@ class Struct
|
|
229
244
|
alias to_s inspect
|
230
245
|
|
231
246
|
def to_h
|
232
|
-
members.inject({}) {|h, name| h[name] = self[name]; h}
|
247
|
+
self.class.members.inject({}) {|h, name| h[name] = self[name]; h}
|
233
248
|
end
|
234
249
|
|
235
250
|
def values_at(*args)
|
data/opal/corelib/unsupported.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
%x{
|
2
2
|
var warnings = {};
|
3
3
|
|
4
|
+
function handle_unsupported_feature(message) {
|
5
|
+
switch (Opal.config.unsupported_features_severity) {
|
6
|
+
case 'error':
|
7
|
+
#{Kernel.raise NotImplementedError, `message`}
|
8
|
+
break;
|
9
|
+
case 'warning':
|
10
|
+
warn(message)
|
11
|
+
break;
|
12
|
+
default: // ignore
|
13
|
+
// noop
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
4
17
|
function warn(string) {
|
5
18
|
if (warnings[string]) {
|
6
19
|
return;
|
@@ -91,22 +104,12 @@ module Kernel
|
|
91
104
|
`var ERROR = "Object freezing is not supported by Opal";`
|
92
105
|
|
93
106
|
def freeze
|
94
|
-
|
95
|
-
`warn(ERROR)`
|
96
|
-
else
|
97
|
-
raise NotImplementedError, `ERROR`
|
98
|
-
end
|
99
|
-
|
107
|
+
`handle_unsupported_feature(ERROR)`
|
100
108
|
self
|
101
109
|
end
|
102
110
|
|
103
111
|
def frozen?
|
104
|
-
|
105
|
-
`warn(ERROR)`
|
106
|
-
else
|
107
|
-
raise NotImplementedError, `ERROR`
|
108
|
-
end
|
109
|
-
|
112
|
+
`handle_unsupported_feature(ERROR)`
|
110
113
|
false
|
111
114
|
end
|
112
115
|
end
|
@@ -115,32 +118,17 @@ module Kernel
|
|
115
118
|
`var ERROR = "Object tainting is not supported by Opal";`
|
116
119
|
|
117
120
|
def taint
|
118
|
-
|
119
|
-
`warn(ERROR)`
|
120
|
-
else
|
121
|
-
raise NotImplementedError, `ERROR`
|
122
|
-
end
|
123
|
-
|
121
|
+
`handle_unsupported_feature(ERROR)`
|
124
122
|
self
|
125
123
|
end
|
126
124
|
|
127
125
|
def untaint
|
128
|
-
|
129
|
-
`warn(ERROR)`
|
130
|
-
else
|
131
|
-
raise NotImplementedError, `ERROR`
|
132
|
-
end
|
133
|
-
|
126
|
+
`handle_unsupported_feature(ERROR)`
|
134
127
|
self
|
135
128
|
end
|
136
129
|
|
137
130
|
def tainted?
|
138
|
-
|
139
|
-
`warn(ERROR)`
|
140
|
-
else
|
141
|
-
raise NotImplementedError, `ERROR`
|
142
|
-
end
|
143
|
-
|
131
|
+
`handle_unsupported_feature(ERROR)`
|
144
132
|
false
|
145
133
|
end
|
146
134
|
end
|
data/opal/opal.rb
CHANGED
data/opal/opal/mini.rb
CHANGED
data/spec/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Opal specs overview
|
2
2
|
|
3
|
-
* **
|
4
|
-
* **
|
5
|
-
* **
|
6
|
-
* **filters** The list of MSpec/RubySpec examples that are either bugs or unsupported
|
3
|
+
* **ruby** the Ruby Spec Suite examples (submodule)
|
4
|
+
* **ruby_specs** (file) a whitelist of the Ruby Spec Suite files to be ran
|
5
|
+
* **filters** The list of the Ruby Spec Suite examples that are either bugs or unsupported
|
7
6
|
* **opal** opal additions/special behaviour in the runtime/corelib
|
8
7
|
* **lib** specs for opal lib (parser, lexer, grammar, compiler etc)
|
8
|
+
* **mspec** the MSpec library that runs the ruby spec
|
9
|
+
* **mspec-opal** Opal specific patches to the MSpec library
|
10
|
+
* **support** misc. utilities
|
data/spec/filters/bugs/array.rb
CHANGED
@@ -3,51 +3,9 @@ opal_filter "Array" do
|
|
3
3
|
fails "Array#flatten with a non-Array object in the Array calls #method_missing if defined"
|
4
4
|
fails "Array#join raises a NoMethodError if an element does not respond to #to_str, #to_ary, or #to_s"
|
5
5
|
fails "Array#partition returns in the left array values for which the block evaluates to true"
|
6
|
-
fails "Array#permutation when no block is given returned Enumerator size with an array size greater than 0 returns the descending factorial of array size and given length"
|
7
|
-
fails "Array#permutation when no block is given returned Enumerator size with an array size greater than 0 returns the descending factorial of array size with array size when there's no param"
|
8
|
-
fails "Array#permutation when no block is given returned Enumerator size with an empty array returns 1 when the given length is 0"
|
9
|
-
fails "Array#permutation when no block is given returned Enumerator size with an empty array returns 1 when there's param"
|
10
6
|
fails "Array#rassoc calls elem == obj on the second element of each contained array"
|
11
7
|
fails "Array#rassoc does not check the last element in each contained but speficically the second"
|
12
|
-
fails "Array#repeated_combination accepts sizes larger than the original array"
|
13
|
-
fails "Array#repeated_combination generates from a defensive copy, ignoring mutations"
|
14
|
-
fails "Array#repeated_combination returns an enumerator when no block is provided"
|
15
|
-
fails "Array#repeated_combination returns self when a block is given"
|
16
|
-
fails "Array#repeated_combination when no block is given returned Enumerator size returns 0 when the combination_size is < 0"
|
17
|
-
fails "Array#repeated_combination when no block is given returned Enumerator size returns 1 when the combination_size is 0"
|
18
|
-
fails "Array#repeated_combination when no block is given returned Enumerator size returns the binomial coeficient between combination_size and array size + combination_size -1"
|
19
|
-
fails "Array#repeated_combination yields [] when length is 0"
|
20
|
-
fails "Array#repeated_combination yields a partition consisting of only singletons"
|
21
|
-
fails "Array#repeated_combination yields nothing for negative length and return self"
|
22
|
-
fails "Array#repeated_combination yields nothing when the array is empty and num is non zero"
|
23
|
-
fails "Array#repeated_combination yields the expected repeated_combinations"
|
24
|
-
fails "Array#repeated_permutation allows permutations larger than the number of elements"
|
25
|
-
fails "Array#repeated_permutation does not yield when called on an empty Array with a nonzero argument"
|
26
|
-
fails "Array#repeated_permutation generates from a defensive copy, ignoring mutations"
|
27
|
-
fails "Array#repeated_permutation handles duplicate elements correctly"
|
28
|
-
fails "Array#repeated_permutation returns an Enumerator of all repeated permutations of given length when called without a block"
|
29
|
-
fails "Array#repeated_permutation returns an Enumerator which works as expected even when the array was modified"
|
30
|
-
fails "Array#repeated_permutation truncates Float arguments"
|
31
|
-
fails "Array#repeated_permutation when no block is given returned Enumerator size returns 0 when combination_size is < 0"
|
32
|
-
fails "Array#repeated_permutation when no block is given returned Enumerator size returns array size ** combination_size"
|
33
|
-
fails "Array#repeated_permutation yields all repeated_permutations to the block then returns self when called with block but no arguments"
|
34
|
-
fails "Array#repeated_permutation yields the empty repeated_permutation ([[]]) when the given length is 0"
|
35
8
|
fails "Array#select returns a new array of elements for which block is true"
|
36
|
-
fails "Array#slice! calls to_int on range arguments"
|
37
|
-
fails "Array#slice! calls to_int on start and length arguments"
|
38
|
-
fails "Array#slice! does not expand array with indices out of bounds"
|
39
|
-
fails "Array#slice! does not expand array with negative indices out of bounds"
|
40
|
-
fails "Array#slice! removes and return elements in range"
|
41
|
-
fails "Array#slice! removes and returns elements in end-exclusive ranges"
|
42
|
-
fails "Array#slice! returns nil if length is negative"
|
43
|
-
fails "Array#sort_by! completes when supplied a block that always returns the same result"
|
44
|
-
fails "Array#sort_by! makes some modification even if finished sorting when it would break in the given block"
|
45
|
-
fails "Array#sort_by! raises a RuntimeError on a frozen array"
|
46
|
-
fails "Array#sort_by! raises a RuntimeError on an empty frozen array"
|
47
|
-
fails "Array#sort_by! returns an Enumerator if not given a block"
|
48
|
-
fails "Array#sort_by! returns the specified value when it would break in the given block"
|
49
|
-
fails "Array#sort_by! sorts array in place by passing each element to the given block"
|
50
|
-
fails "Array#sort_by! when no block is given returned Enumerator size returns the enumerable size"
|
51
9
|
fails "Array#uniq! properly handles recursive arrays"
|
52
10
|
fails "Array#zip fills nil when the given enumereator is shorter than self"
|
53
11
|
fails "Array.[] can unpack 2 or more nested referenced array"
|