opal 1.3.2 → 1.4.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -0
  3. data/.github/workflows/build.yml +0 -3
  4. data/.rubocop.yml +5 -1
  5. data/UNRELEASED.md +66 -2
  6. data/benchmark-ips/bm_truthy.rb +30 -0
  7. data/bin/opal-mspec +1 -3
  8. data/bin/opal-repl +1 -2
  9. data/bin/remove-filters +1 -4
  10. data/docs/compiled_ruby.md +10 -6
  11. data/exe/opal-repl +1 -3
  12. data/lib/opal/ast/builder.rb +1 -1
  13. data/lib/opal/cli.rb +2 -2
  14. data/lib/opal/cli_runners/nodejs.rb +9 -2
  15. data/lib/opal/cli_runners/source-map-support-browser.js +80 -216
  16. data/lib/opal/cli_runners/source-map-support-node.js +80 -216
  17. data/lib/opal/cli_runners/source-map-support.js +5 -1
  18. data/lib/opal/cli_runners/system_runner.rb +10 -4
  19. data/lib/opal/compiler.rb +3 -5
  20. data/lib/opal/fragment.rb +5 -1
  21. data/lib/opal/nodes/args/extract_block_arg.rb +1 -8
  22. data/lib/opal/nodes/args/extract_kwoptarg.rb +1 -3
  23. data/lib/opal/nodes/args/extract_optarg.rb +1 -3
  24. data/lib/opal/nodes/args/extract_post_arg.rb +2 -5
  25. data/lib/opal/nodes/args/extract_post_optarg.rb +2 -7
  26. data/lib/opal/nodes/args/initialize_iterarg.rb +1 -3
  27. data/lib/opal/nodes/args/prepare_post_args.rb +5 -1
  28. data/lib/opal/nodes/base.rb +3 -2
  29. data/lib/opal/nodes/call.rb +20 -9
  30. data/lib/opal/nodes/call_special.rb +50 -0
  31. data/lib/opal/nodes/class.rb +24 -15
  32. data/lib/opal/nodes/constants.rb +23 -5
  33. data/lib/opal/nodes/def.rb +20 -23
  34. data/lib/opal/nodes/defined.rb +5 -5
  35. data/lib/opal/nodes/definitions.rb +2 -2
  36. data/lib/opal/nodes/defs.rb +2 -5
  37. data/lib/opal/nodes/helpers.rb +48 -18
  38. data/lib/opal/nodes/if.rb +109 -8
  39. data/lib/opal/nodes/iter.rb +23 -16
  40. data/lib/opal/nodes/literal.rb +18 -4
  41. data/lib/opal/nodes/logic.rb +2 -1
  42. data/lib/opal/nodes/masgn.rb +4 -9
  43. data/lib/opal/nodes/module.rb +29 -19
  44. data/lib/opal/nodes/node_with_args.rb +1 -7
  45. data/lib/opal/nodes/scope.rb +54 -15
  46. data/lib/opal/nodes/singleton_class.rb +5 -3
  47. data/lib/opal/nodes/super.rb +3 -3
  48. data/lib/opal/nodes/top.rb +34 -31
  49. data/lib/opal/nodes/variables.rb +2 -2
  50. data/lib/opal/nodes/x_string.rb +3 -0
  51. data/lib/opal/nodes.rb +0 -1
  52. data/lib/opal/parser/patch.rb +75 -0
  53. data/lib/opal/parser/with_ruby_lexer.rb +1 -1
  54. data/lib/opal/regexp_anchors.rb +7 -7
  55. data/lib/opal/requires.rb +19 -0
  56. data/lib/opal/rewriters/pattern_matching.rb +1 -1
  57. data/lib/opal/rewriters/returnable_logic.rb +102 -4
  58. data/lib/opal/util.rb +2 -2
  59. data/lib/opal/version.rb +1 -1
  60. data/lib/opal.rb +1 -17
  61. data/opal/corelib/array/pack.rb +11 -11
  62. data/opal/corelib/array.rb +193 -152
  63. data/opal/corelib/basic_object.rb +14 -14
  64. data/opal/corelib/binding.rb +7 -7
  65. data/opal/corelib/boolean.rb +12 -15
  66. data/opal/corelib/class.rb +23 -1
  67. data/opal/corelib/comparable.rb +8 -8
  68. data/opal/corelib/complex/base.rb +2 -2
  69. data/opal/corelib/complex.rb +79 -88
  70. data/opal/corelib/constants.rb +9 -9
  71. data/opal/corelib/dir.rb +4 -3
  72. data/opal/corelib/enumerable.rb +140 -127
  73. data/opal/corelib/enumerator/arithmetic_sequence.rb +177 -0
  74. data/opal/corelib/enumerator/chain.rb +42 -0
  75. data/opal/corelib/enumerator/generator.rb +35 -0
  76. data/opal/corelib/enumerator/lazy.rb +243 -0
  77. data/opal/corelib/enumerator/yielder.rb +36 -0
  78. data/opal/corelib/enumerator.rb +45 -300
  79. data/opal/corelib/error/errno.rb +47 -0
  80. data/opal/corelib/error.rb +62 -60
  81. data/opal/corelib/file.rb +26 -12
  82. data/opal/corelib/hash.rb +98 -107
  83. data/opal/corelib/helpers.rb +62 -13
  84. data/opal/corelib/io.rb +47 -34
  85. data/opal/corelib/kernel/format.rb +29 -29
  86. data/opal/corelib/kernel.rb +86 -83
  87. data/opal/corelib/main.rb +14 -12
  88. data/opal/corelib/marshal/read_buffer.rb +15 -15
  89. data/opal/corelib/marshal/write_buffer.rb +45 -44
  90. data/opal/corelib/marshal.rb +3 -3
  91. data/opal/corelib/math.rb +50 -50
  92. data/opal/corelib/method.rb +12 -8
  93. data/opal/corelib/module.rb +96 -79
  94. data/opal/corelib/nil.rb +9 -11
  95. data/opal/corelib/number.rb +113 -118
  96. data/opal/corelib/numeric.rb +37 -33
  97. data/opal/corelib/object_space.rb +11 -10
  98. data/opal/corelib/pack_unpack/format_string_parser.rb +3 -3
  99. data/opal/corelib/pattern_matching/base.rb +7 -7
  100. data/opal/corelib/pattern_matching.rb +1 -1
  101. data/opal/corelib/proc.rb +15 -16
  102. data/opal/corelib/process/base.rb +2 -2
  103. data/opal/corelib/process/status.rb +21 -0
  104. data/opal/corelib/process.rb +5 -5
  105. data/opal/corelib/random/formatter.rb +11 -11
  106. data/opal/corelib/random/math_random.js.rb +1 -1
  107. data/opal/corelib/random/mersenne_twister.rb +3 -3
  108. data/opal/corelib/random/seedrandom.js.rb +3 -3
  109. data/opal/corelib/random.rb +17 -17
  110. data/opal/corelib/range.rb +51 -35
  111. data/opal/corelib/rational/base.rb +4 -4
  112. data/opal/corelib/rational.rb +61 -62
  113. data/opal/corelib/regexp.rb +47 -38
  114. data/opal/corelib/runtime.js +245 -139
  115. data/opal/corelib/string/encoding.rb +21 -21
  116. data/opal/corelib/string/unpack.rb +19 -14
  117. data/opal/corelib/string.rb +135 -128
  118. data/opal/corelib/struct.rb +59 -46
  119. data/opal/corelib/time.rb +47 -57
  120. data/opal/corelib/trace_point.rb +2 -2
  121. data/opal/corelib/unsupported.rb +31 -120
  122. data/opal/corelib/variables.rb +3 -3
  123. data/opal/opal/base.rb +9 -8
  124. data/opal/opal/full.rb +8 -8
  125. data/opal/opal/mini.rb +17 -17
  126. data/opal/opal.rb +17 -18
  127. data/opal.gemspec +1 -1
  128. data/spec/filters/bugs/array.rb +4 -24
  129. data/spec/filters/bugs/bigdecimal.rb +0 -23
  130. data/spec/filters/bugs/binding.rb +0 -1
  131. data/spec/filters/bugs/boolean.rb +3 -0
  132. data/spec/filters/bugs/class.rb +2 -0
  133. data/spec/filters/bugs/date.rb +0 -5
  134. data/spec/filters/bugs/encoding.rb +8 -50
  135. data/spec/filters/bugs/enumerable.rb +4 -1
  136. data/spec/filters/bugs/enumerator.rb +3 -36
  137. data/spec/filters/bugs/exception.rb +0 -2
  138. data/spec/filters/bugs/file.rb +0 -2
  139. data/spec/filters/bugs/float.rb +0 -3
  140. data/spec/filters/bugs/hash.rb +5 -3
  141. data/spec/filters/bugs/integer.rb +2 -3
  142. data/spec/filters/bugs/kernel.rb +2 -31
  143. data/spec/filters/bugs/language.rb +29 -49
  144. data/spec/filters/bugs/main.rb +0 -2
  145. data/spec/filters/bugs/marshal.rb +2 -3
  146. data/spec/filters/bugs/matrix.rb +0 -36
  147. data/spec/filters/bugs/module.rb +7 -61
  148. data/spec/filters/bugs/numeric.rb +0 -7
  149. data/spec/filters/bugs/objectspace.rb +1 -1
  150. data/spec/filters/bugs/pack_unpack.rb +0 -4
  151. data/spec/filters/bugs/proc.rb +0 -9
  152. data/spec/filters/bugs/random.rb +0 -5
  153. data/spec/filters/bugs/range.rb +1 -6
  154. data/spec/filters/bugs/regexp.rb +0 -3
  155. data/spec/filters/bugs/set.rb +8 -1
  156. data/spec/filters/bugs/string.rb +9 -34
  157. data/spec/filters/bugs/stringscanner.rb +8 -7
  158. data/spec/filters/bugs/struct.rb +2 -3
  159. data/spec/filters/bugs/symbol.rb +0 -1
  160. data/spec/filters/bugs/time.rb +0 -8
  161. data/spec/filters/bugs/unboundmethod.rb +0 -8
  162. data/spec/filters/bugs/warnings.rb +1 -7
  163. data/spec/filters/unsupported/freeze.rb +24 -0
  164. data/spec/filters/unsupported/integer.rb +1 -0
  165. data/spec/filters/unsupported/kernel.rb +12 -0
  166. data/spec/filters/unsupported/privacy.rb +3 -0
  167. data/spec/filters/unsupported/string.rb +2 -0
  168. data/spec/lib/builder_spec.rb +2 -2
  169. data/spec/lib/cli_spec.rb +1 -1
  170. data/spec/lib/compiler_spec.rb +37 -37
  171. data/spec/lib/simple_server_spec.rb +2 -2
  172. data/spec/lib/source_map/file_spec.rb +1 -1
  173. data/spec/opal/compiler/irb_spec.rb +2 -2
  174. data/spec/opal/core/kernel/puts_spec.rb +90 -0
  175. data/spec/opal/core/language/super_spec.rb +24 -0
  176. data/spec/ruby_specs +4 -2
  177. data/spec/support/rewriters_helper.rb +1 -1
  178. data/stdlib/bigdecimal.rb +7 -11
  179. data/stdlib/buffer/view.rb +2 -2
  180. data/stdlib/buffer.rb +2 -2
  181. data/stdlib/date.rb +5 -6
  182. data/stdlib/erb.rb +1 -0
  183. data/stdlib/js.rb +2 -1
  184. data/stdlib/native.rb +7 -8
  185. data/stdlib/nodejs/argf.rb +4 -4
  186. data/stdlib/nodejs/base.rb +29 -0
  187. data/stdlib/nodejs/dir.rb +1 -1
  188. data/stdlib/nodejs/env.rb +6 -9
  189. data/stdlib/nodejs/file.rb +23 -17
  190. data/stdlib/nodejs/fileutils.rb +3 -3
  191. data/stdlib/nodejs/io.rb +2 -20
  192. data/stdlib/nodejs/irb.rb +0 -0
  193. data/stdlib/nodejs/kernel.rb +2 -37
  194. data/stdlib/nodejs.rb +1 -3
  195. data/stdlib/opal/miniracer.rb +2 -0
  196. data/stdlib/opal/platform.rb +6 -13
  197. data/stdlib/opal/replutils.rb +16 -5
  198. data/stdlib/opal-parser.rb +2 -2
  199. data/stdlib/optparse/ac.rb +54 -0
  200. data/stdlib/optparse/date.rb +14 -0
  201. data/stdlib/optparse/kwargs.rb +22 -0
  202. data/stdlib/optparse/shellwords.rb +7 -0
  203. data/stdlib/optparse/time.rb +15 -0
  204. data/stdlib/optparse/uri.rb +7 -0
  205. data/stdlib/optparse/version.rb +69 -0
  206. data/stdlib/optparse.rb +2279 -0
  207. data/stdlib/pathname.rb +5 -6
  208. data/stdlib/pp.rb +18 -2
  209. data/stdlib/promise/v2.rb +18 -22
  210. data/stdlib/promise.rb +15 -21
  211. data/stdlib/set.rb +32 -32
  212. data/stdlib/shellwords.rb +240 -0
  213. data/stdlib/stringio.rb +3 -6
  214. data/stdlib/strscan.rb +5 -8
  215. data/stdlib/template.rb +2 -2
  216. data/stdlib/thread.rb +7 -9
  217. data/tasks/performance.rake +5 -2
  218. data/tasks/testing/mspec_special_calls.rb +0 -12
  219. data/tasks/testing.rake +55 -37
  220. data/test/nodejs/test_file.rb +11 -0
  221. metadata +55 -10
  222. data/lib/opal/nodes/case.rb +0 -114
@@ -4,7 +4,7 @@
4
4
  function handle_unsupported_feature(message) {
5
5
  switch (Opal.config.unsupported_features_severity) {
6
6
  case 'error':
7
- #{Kernel.raise NotImplementedError, `message`}
7
+ #{::Kernel.raise ::NotImplementedError, `message`}
8
8
  break;
9
9
  case 'warning':
10
10
  warn(message)
@@ -24,103 +24,21 @@
24
24
  }
25
25
  }
26
26
 
27
- class String
27
+ class ::String
28
28
  `var ERROR = "String#%s not supported. Mutable String methods are not supported in Opal."`
29
29
 
30
- def <<(*)
31
- raise NotImplementedError, `ERROR` % '<<'
32
- end
33
-
34
- def capitalize!(*)
35
- raise NotImplementedError, `ERROR` % 'capitalize!'
36
- end
37
-
38
- def chomp!(*)
39
- raise NotImplementedError, `ERROR` % 'chomp!'
40
- end
41
-
42
- def chop!(*)
43
- raise NotImplementedError, `ERROR` % 'chop!'
44
- end
45
-
46
- def downcase!(*)
47
- raise NotImplementedError, `ERROR` % 'downcase!'
48
- end
49
-
50
- def gsub!(*)
51
- raise NotImplementedError, `ERROR` % 'gsub!'
52
- end
53
-
54
- def lstrip!(*)
55
- raise NotImplementedError, `ERROR` % 'lstrip!'
56
- end
57
-
58
- def next!(*)
59
- raise NotImplementedError, `ERROR` % 'next!'
60
- end
61
-
62
- def reverse!(*)
63
- raise NotImplementedError, `ERROR` % 'reverse!'
64
- end
65
-
66
- def slice!(*)
67
- raise NotImplementedError, `ERROR` % 'slice!'
68
- end
69
-
70
- def squeeze!(*)
71
- raise NotImplementedError, `ERROR` % 'squeeze!'
72
- end
73
-
74
- def strip!(*)
75
- raise NotImplementedError, `ERROR` % 'strip!'
76
- end
77
-
78
- def sub!(*)
79
- raise NotImplementedError, `ERROR` % 'sub!'
80
- end
81
-
82
- def succ!(*)
83
- raise NotImplementedError, `ERROR` % 'succ!'
84
- end
85
-
86
- def swapcase!(*)
87
- raise NotImplementedError, `ERROR` % 'swapcase!'
88
- end
89
-
90
- def tr!(*)
91
- raise NotImplementedError, `ERROR` % 'tr!'
92
- end
93
-
94
- def tr_s!(*)
95
- raise NotImplementedError, `ERROR` % 'tr_s!'
96
- end
97
-
98
- def upcase!(*)
99
- raise NotImplementedError, `ERROR` % 'upcase!'
100
- end
101
-
102
- def prepend(*)
103
- raise NotImplementedError, `ERROR` % 'prepend'
104
- end
105
-
106
- def []=(*)
107
- raise NotImplementedError, `ERROR` % '[]='
108
- end
109
-
110
- def clear(*)
111
- raise NotImplementedError, `ERROR` % 'clear'
112
- end
113
-
114
- def encode!(*)
115
- raise NotImplementedError, `ERROR` % 'encode!'
116
- end
117
-
118
- def unicode_normalize!(*)
119
- raise NotImplementedError, `ERROR` % 'unicode_normalize!'
30
+ %i[
31
+ << capitalize! chomp! chop! downcase! gsub! lstrip! next! reverse!
32
+ slice! squeeze! strip! sub! succ! swapcase! tr! tr_s! upcase! prepend
33
+ []= clear encode! unicode_normalize!
34
+ ].each do |method_name|
35
+ define_method method_name do |*|
36
+ ::Kernel.raise ::NotImplementedError, `ERROR` % method_name
37
+ end
120
38
  end
121
39
  end
122
40
 
123
- module Kernel
41
+ module ::Kernel
124
42
  `var ERROR = "Object freezing is not supported by Opal"`
125
43
 
126
44
  def freeze
@@ -134,7 +52,7 @@ module Kernel
134
52
  end
135
53
  end
136
54
 
137
- module Kernel
55
+ module ::Kernel
138
56
  `var ERROR = "Object tainting is not supported by Opal"`
139
57
 
140
58
  def taint
@@ -153,29 +71,21 @@ module Kernel
153
71
  end
154
72
  end
155
73
 
156
- class Module
74
+ class ::Module
157
75
  def public(*methods)
158
76
  %x{
159
77
  if (methods.length === 0) {
160
78
  self.$$module_function = false;
79
+ return nil;
161
80
  }
162
-
163
- return nil;
81
+ return (methods.length === 1) ? methods[0] : methods;
164
82
  }
165
83
  end
166
84
 
167
- alias private public
168
-
169
- alias protected public
170
-
171
- alias nesting public
172
-
173
- def private_class_method(*)
174
- self
85
+ def private_class_method(*methods)
86
+ `return (methods.length === 1) ? methods[0] : methods`
175
87
  end
176
88
 
177
- alias public_class_method private_class_method
178
-
179
89
  def private_method_defined?(obj)
180
90
  false
181
91
  end
@@ -183,34 +93,35 @@ class Module
183
93
  def private_constant(*)
184
94
  end
185
95
 
96
+ alias nesting public
97
+ alias private public
98
+ alias protected public
186
99
  alias protected_method_defined? private_method_defined?
187
-
188
- alias public_instance_methods instance_methods
189
-
100
+ alias public_class_method private_class_method
190
101
  alias public_instance_method instance_method
191
-
102
+ alias public_instance_methods instance_methods
192
103
  alias public_method_defined? method_defined?
193
104
  end
194
105
 
195
- module Kernel
196
- def private_methods(*)
106
+ module ::Kernel
107
+ def private_methods(*methods)
197
108
  []
198
109
  end
199
110
 
200
111
  alias private_instance_methods private_methods
201
112
  end
202
113
 
203
- module Kernel
114
+ module ::Kernel
204
115
  def eval(*)
205
- raise NotImplementedError, "To use Kernel#eval, you must first require 'opal-parser'. "\
206
- "See https://github.com/opal/opal/blob/#{RUBY_ENGINE_VERSION}/docs/opal_parser.md for details."
116
+ ::Kernel.raise ::NotImplementedError, "To use Kernel#eval, you must first require 'opal-parser'. "\
117
+ "See https://github.com/opal/opal/blob/#{RUBY_ENGINE_VERSION}/docs/opal_parser.md for details."
207
118
  end
208
119
  end
209
120
 
210
- def self.public(*)
211
- # stub
121
+ def self.public(*methods)
122
+ `return (methods.length === 1) ? methods[0] : methods`
212
123
  end
213
124
 
214
- def self.private(*)
215
- # stub
125
+ def self.private(*methods)
126
+ `return (methods.length === 1) ? methods[0] : methods`
216
127
  end
@@ -9,9 +9,9 @@ $LOAD_PATH = $: = []
9
9
  $/ = "\n"
10
10
  $, = nil
11
11
 
12
- ARGV = []
13
- ARGF = Object.new
14
- ENV = {}
12
+ ::ARGV = []
13
+ ::ARGF = ::Object.new
14
+ ::ENV = {}
15
15
 
16
16
  $VERBOSE = false
17
17
  $DEBUG = false
data/opal/opal/base.rb CHANGED
@@ -1,9 +1,10 @@
1
- require 'corelib/runtime'
2
- require 'corelib/helpers'
3
- require 'corelib/module'
4
- require 'corelib/class'
5
- require 'corelib/basic_object'
6
- require 'corelib/kernel'
7
- require 'corelib/error'
1
+ ::Object.require 'corelib/runtime'
2
+ ::Object.require 'corelib/helpers'
3
+ ::Object.require 'corelib/module'
4
+ ::Object.require 'corelib/class'
5
+ ::Object.require 'corelib/basic_object'
6
+ ::Object.require 'corelib/kernel'
7
+ ::Object.require 'corelib/main'
8
+ ::Object.require 'corelib/error'
8
9
 
9
- require 'corelib/constants'
10
+ ::Object.require 'corelib/constants'
data/opal/opal/full.rb CHANGED
@@ -1,8 +1,8 @@
1
- autoload :Marshal, 'corelib/marshal'
2
- require 'corelib/string/unpack'
3
- require 'corelib/array/pack'
4
- autoload :ObjectSpace, 'corelib/object_space'
5
- require 'corelib/pattern_matching/base'
6
- autoload :PatternMatching, 'corelib/pattern_matching'
7
- autoload :TracePoint, 'corelib/trace_point'
8
- require 'corelib/binding'
1
+ ::Object.autoload :Marshal, 'corelib/marshal'
2
+ ::Object.require 'corelib/string/unpack'
3
+ ::Object.require 'corelib/array/pack'
4
+ ::Object.autoload :ObjectSpace, 'corelib/object_space'
5
+ ::Object.require 'corelib/pattern_matching/base'
6
+ ::Object.autoload :PatternMatching, 'corelib/pattern_matching'
7
+ ::Object.autoload :TracePoint, 'corelib/trace_point'
8
+ ::Object.require 'corelib/binding'
data/opal/opal/mini.rb CHANGED
@@ -1,18 +1,18 @@
1
- require 'opal/base'
1
+ ::Object.require 'opal/base'
2
2
 
3
- require 'corelib/nil'
4
- require 'corelib/boolean'
5
- require 'corelib/string'
6
- require 'corelib/comparable'
7
- require 'corelib/enumerable'
8
- require 'corelib/enumerator'
9
- require 'corelib/array'
10
- require 'corelib/hash'
11
- require 'corelib/number'
12
- require 'corelib/range'
13
- require 'corelib/proc'
14
- require 'corelib/method'
15
- require 'corelib/regexp'
16
- require 'corelib/variables'
17
- require 'corelib/io'
18
- require 'opal/regexp_anchors'
3
+ ::Object.require 'corelib/nil'
4
+ ::Object.require 'corelib/boolean'
5
+ ::Object.require 'corelib/string'
6
+ ::Object.require 'corelib/comparable'
7
+ ::Object.require 'corelib/enumerable'
8
+ ::Object.require 'corelib/enumerator'
9
+ ::Object.require 'corelib/array'
10
+ ::Object.require 'corelib/hash'
11
+ ::Object.require 'corelib/number'
12
+ ::Object.require 'corelib/range'
13
+ ::Object.require 'corelib/proc'
14
+ ::Object.require 'corelib/method'
15
+ ::Object.require 'corelib/regexp'
16
+ ::Object.require 'corelib/variables'
17
+ ::Object.require 'corelib/io'
18
+ ::Object.require 'opal/regexp_anchors'
data/opal/opal.rb CHANGED
@@ -1,21 +1,20 @@
1
- require 'opal/base'
2
- require 'opal/mini'
1
+ ::Object.require 'opal/base'
2
+ ::Object.require 'opal/mini'
3
3
 
4
- require 'corelib/main'
5
- require 'corelib/kernel/format'
6
- require 'corelib/string/encoding'
7
- autoload :Math, 'corelib/math'
8
- require 'corelib/complex/base'
9
- autoload :Complex, 'corelib/complex'
10
- require 'corelib/rational/base'
11
- autoload :Rational, 'corelib/rational'
12
- require 'corelib/time'
13
- autoload :Struct, 'corelib/struct'
14
- require 'corelib/dir'
15
- autoload :File, 'corelib/file'
4
+ ::Object.require 'corelib/kernel/format'
5
+ ::Object.require 'corelib/string/encoding'
6
+ ::Object.autoload :Math, 'corelib/math'
7
+ ::Object.require 'corelib/complex/base'
8
+ ::Object.autoload :Complex, 'corelib/complex'
9
+ ::Object.require 'corelib/rational/base'
10
+ ::Object.autoload :Rational, 'corelib/rational'
11
+ ::Object.require 'corelib/time'
12
+ ::Object.autoload :Struct, 'corelib/struct'
13
+ ::Object.require 'corelib/dir'
14
+ ::Object.autoload :File, 'corelib/file'
16
15
 
17
- require 'corelib/process/base'
18
- autoload :Process, 'corelib/process'
19
- autoload :Random, 'corelib/random'
16
+ ::Object.require 'corelib/process/base'
17
+ ::Object.autoload :Process, 'corelib/process'
18
+ ::Object.autoload :Random, 'corelib/random'
20
19
 
21
- require 'corelib/unsupported'
20
+ ::Object.require 'corelib/unsupported'
data/opal.gemspec CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.required_ruby_version = '>= 2.3'
35
35
 
36
36
  spec.add_dependency 'ast', '>= 2.3.0'
37
- spec.add_dependency 'parser', '~> 3.0'
37
+ spec.add_dependency 'parser', ['~> 3.0', '>= 3.0.3.2']
38
38
 
39
39
  spec.add_development_dependency 'sourcemap', '~> 0.1.0'
40
40
  spec.add_development_dependency 'rake', '~> 13.0'
@@ -2,29 +2,14 @@
2
2
  opal_filter "Array" do
3
3
  fails "Array#== compares with an equivalent Array-like object using #to_ary" # Expected false to be true
4
4
  fails "Array#== returns true for [NaN] == [NaN] because Array#== first checks with #equal? and NaN.equal?(NaN) is true" # Expected [NaN] to equal [NaN]
5
- fails "Array#[] can accept beginless ranges" # Opal::SyntaxError: undefined method `type' for nil
6
- fails "Array#[] can accept endless ranges" # Opal::SyntaxError: undefined method `type' for nil
7
- fails "Array#[] can accept nil...nil ranges" # TypeError: no implicit conversion of NilClass into Integer
5
+ fails "Array#[] can be sliced with Enumerator::ArithmeticSequence has endless range with start outside of array's bounds" # Expected [] == nil to be truthy but was false
6
+ fails "Array#[] can be sliced with Enumerator::ArithmeticSequence has range with bounds outside of array" # Expected RangeError but no exception was raised ([0, 2, 4] was returned)
8
7
  fails "Array#[] raises TypeError if to_int returns non-integer" # Expected TypeError but no exception was raised ([1, 2, 3, 4] was returned)
9
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)
10
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)
11
- fails "Array#[]= with [..n] and [...n] inserts at the beginning if n < negative the array size" # Opal::SyntaxError: undefined method `type' for nil
12
- fails "Array#[]= with [..n] and [...n] just sets the section defined by range to nil even if the rhs is nil" # Opal::SyntaxError: undefined method `type' for nil
13
- fails "Array#[]= with [..n] and [...n] just sets the section defined by range to nil if n < 0 and the rhs is nil" # Opal::SyntaxError: undefined method `type' for nil
14
- fails "Array#[]= with [..n] and [...n] replaces everything if n > the array size" # Opal::SyntaxError: undefined method `type' for nil
15
- fails "Array#[]= with [..n] and [...n] replaces the section defined by range" # Opal::SyntaxError: undefined method `type' for nil
16
- fails "Array#[]= with [..n] and [...n] replaces the section if n < 0" # Opal::SyntaxError: undefined method `type' for nil
17
- fails "Array#[]= with [m..] inserts at the end if m > the array size" # Opal::SyntaxError: undefined method `type' for nil
18
- fails "Array#[]= with [m..] just sets the section defined by range to nil even if the rhs is nil" # Opal::SyntaxError: undefined method `type' for nil
19
- fails "Array#[]= with [m..] just sets the section defined by range to nil if m and n < 0 and the rhs is nil" # Opal::SyntaxError: undefined method `type' for nil
20
- fails "Array#[]= with [m..] replaces the section defined by range" # Opal::SyntaxError: undefined method `type' for nil
21
- fails "Array#[]= with [m..] replaces the section if m and n < 0" # Opal::SyntaxError: undefined method `type' for nil
22
- fails "Array#drop raises a TypeError when the passed argument can't be coerced to Integer" # Expected TypeError but no exception was raised ([1, 2] was returned)
23
10
  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)
24
- fails "Array#drop tries to convert the passed argument to an Integer using #to_int" # Expected [1, 2, 3] == [3] to be truthy but was false
25
11
  fails "Array#each does not yield elements deleted from the end of the array" # Expected [2, 3, nil] to equal [2, 3]
26
12
  fails "Array#each yields elements added to the end of the array by the block" # Expected [2] to equal [2, 0, 0]
27
- fails "Array#fill with (filler, range) works with beginless ranges" # Opal::SyntaxError: undefined method `type' for nil
28
13
  fails "Array#fill with (filler, range) works with endless ranges" # Opal::SyntaxError: undefined method `type' for nil
29
14
  fails "Array#filter returns a new array of elements for which block is true" # NoMethodError: undefined method `filter' for [1, 3, 4, 5, 6, 9]
30
15
  fails "Array#flatten does not call #to_ary on elements beyond the given level"
@@ -35,18 +20,13 @@ opal_filter "Array" do
35
20
  fails "Array#rassoc calls elem == obj on the second element of each contained array"
36
21
  fails "Array#rassoc does not check the last element in each contained but specifically the second" # Expected [1, "foobar", #<MockObject:0x4ef6e>] to equal [2, #<MockObject:0x4ef6e>, 1]
37
22
  fails "Array#select returns a new array of elements for which block is true"
38
- fails "Array#slice can accept beginless ranges" # Opal::SyntaxError: undefined method `type' for nil
39
- fails "Array#slice can accept endless ranges" # Opal::SyntaxError: undefined method `type' for nil
40
- fails "Array#slice can accept nil...nil ranges" # TypeError: no implicit conversion of NilClass into Integer
23
+ 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
24
+ fails "Array#slice can be sliced with Enumerator::ArithmeticSequence has range with bounds outside of array" # Expected RangeError but no exception was raised ([0, 2, 4] was returned)
41
25
  fails "Array#slice raises TypeError if to_int returns non-integer" # Expected TypeError but no exception was raised ([1, 2, 3, 4] was returned)
42
26
  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)
43
27
  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)
44
- fails "Array#slice! works with beginless ranges" # Opal::SyntaxError: undefined method `type' for nil
45
- fails "Array#slice! works with endless ranges" # Opal::SyntaxError: undefined method `type' for nil
46
28
  fails "Array#to_h with block does not coerce returned pair to Array with #to_a" # Expected TypeError (/wrong element type MockObject at 0/) but got: TypeError (wrong element type NilClass at 0 (expected array))
47
29
  fails "Array#to_h with block raises TypeError if block returns something other than Array" # Expected TypeError (/wrong element type String at 0/) but got: TypeError (wrong element type NilClass at 0 (expected array))
48
30
  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
49
31
  fails "Array#uniq! properly handles recursive arrays"
50
- fails "Array#values_at works when given beginless ranges" # Opal::SyntaxError: undefined method `type' for nil
51
- fails "Array#values_at works when given endless ranges" # Opal::SyntaxError: undefined method `type' for nil
52
32
  end
@@ -81,12 +81,7 @@ opal_filter "BigDecimal" do
81
81
  fails "BigDecimal#frac returns a BigDecimal"
82
82
  fails "BigDecimal#frac returns the fractional part of the absolute value"
83
83
  fails "BigDecimal#inspect does not add an exponent for zero values" # Exception: self.$BigDecimal(...).$inspect is not a function
84
- fails "BigDecimal#inspect encloses information in angle brackets"
85
- fails "BigDecimal#inspect is comma separated list of three items"
86
- fails "BigDecimal#inspect last part is number of significant digits"
87
84
  fails "BigDecimal#inspect looks like this"
88
- fails "BigDecimal#inspect returns String starting with #"
89
- fails "BigDecimal#inspect value after first comma is value as string"
90
85
  fails "BigDecimal#mod_part_of_divmod returns NaN if NaN is involved"
91
86
  fails "BigDecimal#mod_part_of_divmod returns NaN if the dividend is Infinity"
92
87
  fails "BigDecimal#mod_part_of_divmod returns self modulo other"
@@ -162,7 +157,6 @@ opal_filter "BigDecimal" do
162
157
  fails "BigDecimal#sqrt returns 0 for 0, +0.0 and -0.0"
163
158
  fails "BigDecimal#sqrt returns 1 if precision is 0 or 1"
164
159
  fails "BigDecimal#sqrt returns positive infinity for infinity" # NoMethodError: undefined method `sqrt' for Infinity
165
- fails "BigDecimal#sqrt returns positive infitinity for infinity"
166
160
  fails "BigDecimal#sqrt returns square root of 0.9E-99999 with desired precision"
167
161
  fails "BigDecimal#sqrt returns square root of 121 with desired precision"
168
162
  fails "BigDecimal#sqrt returns square root of 2 with desired precision"
@@ -171,10 +165,8 @@ opal_filter "BigDecimal" do
171
165
  fails "BigDecimal#sub with Rational produces a BigDecimal" # Exception: lhs.$- is not a function
172
166
  fails "BigDecimal#to_f properly handles special values"
173
167
  fails "BigDecimal#to_i raises FloatDomainError if BigDecimal is infinity or NaN"
174
- fails "BigDecimal#to_i returns Integer or Bignum otherwise"
175
168
  fails "BigDecimal#to_i returns Integer otherwise" # NoMethodError: undefined method `to_i' for 3e-20001
176
169
  fails "BigDecimal#to_int raises FloatDomainError if BigDecimal is infinity or NaN"
177
- fails "BigDecimal#to_int returns Integer or Bignum otherwise"
178
170
  fails "BigDecimal#to_int returns Integer otherwise" # NoMethodError: undefined method `to_i' for 3e-20001
179
171
  fails "BigDecimal#to_r returns a Rational with bignum values" # NoMethodError: undefined method `to_r' for 3.141592653589793238462643
180
172
  fails "BigDecimal#to_r returns a Rational" # NoMethodError: undefined method `to_r' for 3.14159
@@ -189,7 +181,6 @@ opal_filter "BigDecimal" do
189
181
  fails "BigDecimal#to_s returns a String in US-ASCII encoding when Encoding.default_internal is not nil" # NoMethodError: undefined method `default_internal' for Encoding
190
182
  fails "BigDecimal#to_s starts with + if + is supplied and value is positive"
191
183
  fails "BigDecimal#to_s takes an optional argument" # Expected to not get Exception
192
- fails "BigDecimal#to_s the default format looks like 0.xxxxEnn"
193
184
  fails "BigDecimal#to_s the default format looks like 0.xxxxenn" # Expected "3.14159265358979323846264338327950288419716939937" to match /^0\.[0-9]*e[0-9]*$/
194
185
  fails "BigDecimal#truncate returns Infinity if self is infinite"
195
186
  fails "BigDecimal#truncate returns the same value if self is special value"
@@ -198,33 +189,19 @@ opal_filter "BigDecimal" do
198
189
  fails "BigDecimal.limit picks the global precision when limit 0 specified" # Expected 0.8888 to equal 0.889
199
190
  fails "BigDecimal.limit picks the specified precision over global limit" # Expected 0.888 to equal 0.89
200
191
  fails "BigDecimal.limit returns the value before set if the passed argument is nil or is not specified"
201
- fails "BigDecimal.limit use the global limit if no precision is specified"
202
192
  fails "BigDecimal.limit uses the global limit if no precision is specified" # Expected 0.888 to equal 0.9
203
193
  fails "BigDecimal.mode raise an exception if the flag is true"
204
194
  fails "BigDecimal.mode returns Infinity when too big"
205
195
  fails "BigDecimal.mode returns the appropriate value and continue the computation if the flag is false"
206
- fails "BigDecimal.new accepts significant digits >= given precision" # NoMethodError: undefined method `precs' for 3.1415923
207
- fails "BigDecimal.new allows for [eEdD] as exponent separator"
208
- fails "BigDecimal.new allows for underscores in all parts"
209
- fails "BigDecimal.new creates a new object of class BigDecimal"
210
- fails "BigDecimal.new determines precision from initial value"
211
- fails "BigDecimal.new ignores trailing garbage"
212
- fails "BigDecimal.new raises ArgumentError for invalid strings" # Exception: new BigNumber() not a number: ruby
213
- fails "BigDecimal.new raises ArgumentError when Float is used without precision"
214
- fails "BigDecimal.new treats invalid strings as 0.0"
215
- fails "BigDecimal.ver returns the Version number"
216
196
  fails "Float#to_d returns appropriate BigDecimal zero for signed zero" # NoMethodError: undefined method `to_d' for 0
217
197
  fails "Kernel#BigDecimal BigDecimal(Rational) with bigger-than-double numerator" # Expected 1000000000000000000 > 18446744073709552000 to be truthy but was false
218
198
  fails "Kernel#BigDecimal accepts significant digits >= given precision" # NoMethodError: undefined method `precs' for 3.1415923
219
199
  fails "Kernel#BigDecimal allows for [eEdD] as exponent separator" # Exception: new BigNumber() not a number: 12345.67d89
220
- fails "Kernel#BigDecimal allows for underscores in all parts" # Exception: new BigNumber() not a number: 12_345.67E89
221
200
  fails "Kernel#BigDecimal coerces the value argument with #to_str" # Exception: new BigNumber() not a number: #<MockObject:0x666>
222
201
  fails "Kernel#BigDecimal creates a new object of class BigDecimal" # Expected 1 to equal (1/1)
223
202
  fails "Kernel#BigDecimal determines precision from initial value" # NoMethodError: undefined method `precs' for 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043
224
203
  fails "Kernel#BigDecimal does not call to_s when calling inspect" # Expected "44.44" == "0.4444e2" to be truthy but was false
225
204
  fails "Kernel#BigDecimal does not ignores trailing garbage" # Expected ArgumentError but got: Exception (new BigNumber() not a number: 123E45ruby)
226
- fails "Kernel#BigDecimal ignores leading whitespace" # Exception: self.$BigDecimal(...).$should is not a function
227
- fails "Kernel#BigDecimal ignores trailing garbage" # Exception: new BigNumber() not a number: 123E45ruby
228
205
  fails "Kernel#BigDecimal pre-coerces long integers" # Expected 262000 == 1130000000000000 to be truthy but was false
229
206
  fails "Kernel#BigDecimal process underscores as Float()" # Exception: new BigNumber() not a number: 12_345.67E89
230
207
  fails "Kernel#BigDecimal raises ArgumentError for invalid strings" # Exception: new BigNumber() not a number: ruby
@@ -23,5 +23,4 @@ opal_filter "Binding" do
23
23
  fails "Binding#local_variables includes local variables defined after calling binding.local_variables" # Expected [] == ["a", "b"] to be truthy but was false
24
24
  fails "Binding#local_variables includes local variables of inherited scopes and eval'ed context" # Expected ["c"] == ["c", "a", "b", "p"] to be truthy but was false
25
25
  fails "Binding#local_variables includes new variables defined in the binding" # Expected ["b"] == ["a", "b"] to be truthy but was false
26
- fails "Proc#curry produces Procs that raise ArgumentError for #binding" # Expected ArguentError but no exception was raised (#<Binding:0x1ade4> was returned)
27
26
  end
@@ -0,0 +1,3 @@
1
+ # NOTE: run bin/format-filters after changing this file
2
+ opal_filter "Boolean" do
3
+ end
@@ -9,4 +9,6 @@ opal_filter "Class" do
9
9
  fails "Class#initialize when given the Class raises a TypeError"
10
10
  fails "Class#new uses the internal allocator and does not call #allocate" # RuntimeError: allocate should not be called
11
11
  fails "Class.new raises a TypeError if passed a metaclass"
12
+ fails_badly "Class#descendants returns a list of classes descended from self (excluding self)" # GC/Spec order issue. Expected [#<Class:0x2e77c>, #<Class:0x2e79a>, #<Class:0x37368>, ModuleSpecs::Child, ModuleSpecs::Child2, ModuleSpecs::Grandchild] == [ModuleSpecs::Child, ModuleSpecs::Child2, ModuleSpecs::Grandchild] to be truthy but was false
13
+ fails_badly "Class#subclasses returns a list of classes directly inheriting from self" # GC/Spec order issue. Expected [#<Class:0x2e77c>, #<Class:0x2e79a>, #<Class:0x37368>, ModuleSpecs::Child, ModuleSpecs::Child2] == [ModuleSpecs::Child, ModuleSpecs::Child2] to be truthy but was false
12
14
  end
@@ -33,9 +33,7 @@ opal_filter "Date" do
33
33
  fails "Date#strftime should be able to print the commercial year with only two digits"
34
34
  fails "Date#strftime should be able to show a full notation"
35
35
  fails "Date#strftime should be able to show the commercial week day"
36
- fails "Date#strftime should be able to show the commercial week"
37
36
  fails "Date#strftime should be able to show the number of seconds since the unix epoch for a date" # Expected "954964800" to equal "954979200"
38
- fails "Date#strftime should be able to show the number of seconds since the unix epoch"
39
37
  fails "Date#strftime should be able to show the timezone of the date with a : separator"
40
38
  fails "Date#strftime should be able to show the timezone with a : separator"
41
39
  fails "Date#strftime should be able to show the week number with the week starting on Sunday (%U) and Monday (%W)"
@@ -96,9 +94,6 @@ opal_filter "Date" do
96
94
  fails "Date.valid_jd? returns false if passed nil"
97
95
  fails "Date.valid_jd? returns false if passed symbol" # NoMethodError: undefined method `valid_jd?' for Date
98
96
  fails "Date.valid_jd? returns true if passed a number value" # NoMethodError: undefined method `valid_jd?' for Date
99
- fails "Date.valid_jd? returns true if passed any value other than nil"
100
- fails "Date.valid_jd? returns true if passed false"
101
- fails "Date.valid_jd? returns true if passed symbol" # NoMethodError: undefined method `valid_jd?' for Date
102
97
  fails "Date.valid_ordinal? determines if the date is a valid ordinal date"
103
98
  fails "Date.valid_ordinal? handles negative day numbers"
104
99
  end