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
@@ -1,12 +1,12 @@
1
- class NilClass
1
+ class ::NilClass
2
2
  def __marshal__(buffer)
3
3
  buffer.append('0')
4
4
  end
5
5
  end
6
6
 
7
- class Boolean
7
+ class ::Boolean
8
8
  def __marshal__(buffer)
9
- if `self`
9
+ if `self == true`
10
10
  buffer.append('T')
11
11
  else
12
12
  buffer.append('F')
@@ -14,7 +14,7 @@ class Boolean
14
14
  end
15
15
  end
16
16
 
17
- class Integer
17
+ class ::Integer
18
18
  def __marshal__(buffer)
19
19
  if self >= -0x40000000 && self < 0x40000000
20
20
  buffer.append('i')
@@ -26,7 +26,7 @@ class Integer
26
26
  end
27
27
  end
28
28
 
29
- class Float
29
+ class ::Float
30
30
  def __marshal__(buffer)
31
31
  buffer.save_link(self)
32
32
  buffer.append('f')
@@ -34,33 +34,33 @@ class Float
34
34
  end
35
35
  end
36
36
 
37
- class String
37
+ class ::String
38
38
  def __marshal__(buffer)
39
39
  buffer.save_link(self)
40
40
  buffer.write_ivars_prefix(self)
41
41
  buffer.write_extends(self)
42
- buffer.write_user_class(String, self)
42
+ buffer.write_user_class(::String, self)
43
43
  buffer.append('"')
44
44
  buffer.write_string(self)
45
45
  end
46
46
  end
47
47
 
48
- class Array
48
+ class ::Array
49
49
  def __marshal__(buffer)
50
50
  buffer.save_link(self)
51
51
  buffer.write_ivars_prefix(self)
52
52
  buffer.write_extends(self)
53
- buffer.write_user_class(Array, self)
53
+ buffer.write_user_class(::Array, self)
54
54
  buffer.append('[')
55
55
  buffer.write_array(self)
56
56
  buffer.write_ivars_suffix(self)
57
57
  end
58
58
  end
59
59
 
60
- class Hash
60
+ class ::Hash
61
61
  def __marshal__(buffer)
62
62
  if default_proc
63
- raise TypeError, "can't dump hash with default proc"
63
+ ::Kernel.raise ::TypeError, "can't dump hash with default proc"
64
64
  end
65
65
 
66
66
  buffer.save_link(self)
@@ -79,40 +79,40 @@ class Hash
79
79
  end
80
80
  end
81
81
 
82
- class Regexp
82
+ class ::Regexp
83
83
  def __marshal__(buffer)
84
84
  buffer.save_link(self)
85
85
  buffer.write_ivars_prefix(self)
86
86
  buffer.write_extends(self)
87
- buffer.write_user_class(Regexp, self)
87
+ buffer.write_user_class(::Regexp, self)
88
88
  buffer.append('/')
89
89
  buffer.write_regexp(self)
90
90
  buffer.write_ivars_suffix(self)
91
91
  end
92
92
  end
93
93
 
94
- class Proc
94
+ class ::Proc
95
95
  def __marshal__(buffer)
96
- raise TypeError, "no _dump_data is defined for class #{self.class}"
96
+ ::Kernel.raise ::TypeError, "no _dump_data is defined for class #{self.class}"
97
97
  end
98
98
  end
99
99
 
100
- class Method
100
+ class ::Method
101
101
  def __marshal__(buffer)
102
- raise TypeError, "no _dump_data is defined for class #{self.class}"
102
+ ::Kernel.raise ::TypeError, "no _dump_data is defined for class #{self.class}"
103
103
  end
104
104
  end
105
105
 
106
- class MatchData
106
+ class ::MatchData
107
107
  def __marshal__(buffer)
108
- raise TypeError, "no _dump_data is defined for class #{self.class}"
108
+ ::Kernel.raise ::TypeError, "no _dump_data is defined for class #{self.class}"
109
109
  end
110
110
  end
111
111
 
112
- class Module
112
+ class ::Module
113
113
  def __marshal__(buffer)
114
114
  unless name
115
- raise TypeError, "can't dump anonymous module"
115
+ ::Kernel.raise ::TypeError, "can't dump anonymous module"
116
116
  end
117
117
 
118
118
  buffer.save_link(self)
@@ -121,14 +121,14 @@ class Module
121
121
  end
122
122
  end
123
123
 
124
- class Class
124
+ class ::Class
125
125
  def __marshal__(buffer)
126
126
  unless name
127
- raise TypeError, "can't dump anonymous class"
127
+ ::Kernel.raise ::TypeError, "can't dump anonymous class"
128
128
  end
129
129
 
130
130
  if singleton_class?
131
- raise TypeError, "singleton class can't be dumped"
131
+ ::Kernel.raise ::TypeError, "singleton class can't be dumped"
132
132
  end
133
133
 
134
134
  buffer.save_link(self)
@@ -137,7 +137,7 @@ class Class
137
137
  end
138
138
  end
139
139
 
140
- class BasicObject
140
+ class ::BasicObject
141
141
  def __marshal__(buffer)
142
142
  buffer.save_link(self)
143
143
  buffer.write_extends(self)
@@ -146,7 +146,7 @@ class BasicObject
146
146
  end
147
147
  end
148
148
 
149
- class Range
149
+ class ::Range
150
150
  def __marshal__(buffer)
151
151
  buffer.save_link(self)
152
152
  buffer.write_extends(self)
@@ -162,7 +162,7 @@ class Range
162
162
  end
163
163
  end
164
164
 
165
- class Struct
165
+ class ::Struct
166
166
  def __marshal__(buffer)
167
167
  buffer.save_link(self)
168
168
  buffer.write_ivars_prefix(self)
@@ -178,8 +178,8 @@ class Struct
178
178
  end
179
179
  end
180
180
 
181
- module Marshal
182
- class WriteBuffer
181
+ module ::Marshal
182
+ class self::WriteBuffer
183
183
  attr_reader :buffer
184
184
 
185
185
  %x{
@@ -194,7 +194,7 @@ module Marshal
194
194
  @object = object
195
195
  @buffer = ''
196
196
  @cache = []
197
- @extends = Hash.new { |h, k| h[k] = [] }
197
+ @extends = ::Hash.new { |h, k| h[k] = [] }
198
198
  append(version)
199
199
  end
200
200
 
@@ -207,16 +207,17 @@ module Marshal
207
207
  write_userdef(object)
208
208
  else
209
209
  case object
210
- when nil, true, false, Proc, Method, MatchData, Range, Struct, Array, Class, Module, Hash, Regexp
210
+ when nil, true, false, ::Proc, ::Method, ::MatchData, ::Range, ::Struct,
211
+ ::Array, ::Class, ::Module, ::Hash, ::Regexp
211
212
  object.__marshal__(self)
212
- when Integer
213
- Integer.instance_method(:__marshal__).bind(object).call(self)
214
- when Float
215
- Float.instance_method(:__marshal__).bind(object).call(self)
216
- when String
217
- String.instance_method(:__marshal__).bind(object).call(self)
213
+ when ::Integer
214
+ ::Integer.instance_method(:__marshal__).bind(object).call(self)
215
+ when ::Float
216
+ ::Float.instance_method(:__marshal__).bind(object).call(self)
217
+ when ::String
218
+ ::String.instance_method(:__marshal__).bind(object).call(self)
218
219
  else
219
- BasicObject.instance_method(:__marshal__).bind(object).call(self)
220
+ ::BasicObject.instance_method(:__marshal__).bind(object).call(self)
220
221
  end
221
222
  end
222
223
 
@@ -322,11 +323,11 @@ module Marshal
322
323
  end
323
324
 
324
325
  def write_float(f)
325
- if f.equal?(Float::INFINITY)
326
+ if f.equal?(::Float::INFINITY)
326
327
  write_string('inf')
327
- elsif f.equal?(-Float::INFINITY)
328
+ elsif f.equal?(-::Float::INFINITY)
328
329
  write_string('-inf')
329
- elsif f.equal?(Float::NAN)
330
+ elsif f.equal?(::Float::NAN)
330
331
  write_string('nan')
331
332
  else
332
333
  write_string(f.to_s)
@@ -378,7 +379,7 @@ module Marshal
378
379
  klass = object.class
379
380
  append('U')
380
381
  namespace = `#{klass}.$$base_module`
381
- if namespace.equal?(Object)
382
+ if namespace.equal?(::Object)
382
383
  append_symbol(`#{klass}.$$name`)
383
384
  else
384
385
  append_symbol(namespace.name + '::' + `#{klass}.$$name`)
@@ -389,8 +390,8 @@ module Marshal
389
390
  def write_userdef(object)
390
391
  value = object._dump(0)
391
392
 
392
- unless value.is_a?(String)
393
- raise TypeError, '_dump() must return string'
393
+ unless value.is_a?(::String)
394
+ ::Kernel.raise ::TypeError, '_dump() must return string'
394
395
  end
395
396
 
396
397
  write_ivars_prefix(value)
@@ -1,17 +1,17 @@
1
1
  require 'corelib/marshal/read_buffer'
2
2
  require 'corelib/marshal/write_buffer'
3
3
 
4
- module Marshal
4
+ module ::Marshal
5
5
  MAJOR_VERSION = 4
6
6
  MINOR_VERSION = 8
7
7
 
8
8
  class << self
9
9
  def dump(object)
10
- WriteBuffer.new(object).write
10
+ self::WriteBuffer.new(object).write
11
11
  end
12
12
 
13
13
  def load(marshaled)
14
- ReadBuffer.new(marshaled).read
14
+ self::ReadBuffer.new(marshaled).read
15
15
  end
16
16
 
17
17
  alias restore load
data/opal/corelib/math.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # helpers: type_error
2
2
 
3
- module Math
4
- E = `Math.E`
5
- PI = `Math.PI`
3
+ module ::Math
4
+ self::E = `Math.E`
5
+ self::PI = `Math.PI`
6
6
 
7
- DomainError = Class.new(StandardError)
7
+ self::DomainError = ::Class.new(::StandardError)
8
8
 
9
9
  def self.checked(method, *args)
10
10
  %x{
@@ -15,7 +15,7 @@ module Math
15
15
  var result = Math[method].apply(null, args);
16
16
 
17
17
  if (isNaN(result)) {
18
- #{raise DomainError, "Numerical argument is out of domain - \"#{method}\""};
18
+ #{::Kernel.raise DomainError, "Numerical argument is out of domain - \"#{method}\""};
19
19
  }
20
20
 
21
21
  return result;
@@ -23,21 +23,21 @@ module Math
23
23
  end
24
24
 
25
25
  def self.float!(value)
26
- Float(value)
27
- rescue ArgumentError
28
- raise `$type_error(value, #{Float})`
26
+ ::Kernel.Float(value)
27
+ rescue ::ArgumentError
28
+ ::Kernel.raise `$type_error(value, #{::Float})`
29
29
  end
30
30
 
31
31
  def self.integer!(value)
32
- Integer(value)
33
- rescue ArgumentError
34
- raise `$type_error(value, #{Integer})`
32
+ ::Kernel.Integer(value)
33
+ rescue ::ArgumentError
34
+ ::Kernel.raise `$type_error(value, #{::Integer})`
35
35
  end
36
36
 
37
37
  module_function
38
38
 
39
39
  def acos(x)
40
- Math.checked :acos, Math.float!(x)
40
+ ::Math.checked :acos, ::Math.float!(x)
41
41
  end
42
42
 
43
43
  unless defined?(`Math.acosh`)
@@ -49,11 +49,11 @@ module Math
49
49
  end
50
50
 
51
51
  def acosh(x)
52
- Math.checked :acosh, Math.float!(x)
52
+ ::Math.checked :acosh, ::Math.float!(x)
53
53
  end
54
54
 
55
55
  def asin(x)
56
- Math.checked :asin, Math.float!(x)
56
+ ::Math.checked :asin, ::Math.float!(x)
57
57
  end
58
58
 
59
59
  unless defined?(`Math.asinh`)
@@ -65,15 +65,15 @@ module Math
65
65
  end
66
66
 
67
67
  def asinh(x)
68
- Math.checked :asinh, Math.float!(x)
68
+ ::Math.checked :asinh, ::Math.float!(x)
69
69
  end
70
70
 
71
71
  def atan(x)
72
- Math.checked :atan, Math.float!(x)
72
+ ::Math.checked :atan, ::Math.float!(x)
73
73
  end
74
74
 
75
75
  def atan2(y, x)
76
- Math.checked :atan2, Math.float!(y), Math.float!(x)
76
+ ::Math.checked :atan2, ::Math.float!(y), ::Math.float!(x)
77
77
  end
78
78
 
79
79
  unless defined?(`Math.atanh`)
@@ -85,7 +85,7 @@ module Math
85
85
  end
86
86
 
87
87
  def atanh(x)
88
- Math.checked :atanh, Math.float!(x)
88
+ ::Math.checked :atanh, ::Math.float!(x)
89
89
  end
90
90
 
91
91
  unless defined?(`Math.cbrt`)
@@ -135,11 +135,11 @@ module Math
135
135
  end
136
136
 
137
137
  def cbrt(x)
138
- Math.checked :cbrt, Math.float!(x)
138
+ ::Math.checked :cbrt, ::Math.float!(x)
139
139
  end
140
140
 
141
141
  def cos(x)
142
- Math.checked :cos, Math.float!(x)
142
+ ::Math.checked :cos, ::Math.float!(x)
143
143
  end
144
144
 
145
145
  unless defined?(`Math.cosh`)
@@ -151,12 +151,12 @@ module Math
151
151
  end
152
152
 
153
153
  def cosh(x)
154
- Math.checked :cosh, Math.float!(x)
154
+ ::Math.checked :cosh, ::Math.float!(x)
155
155
  end
156
156
 
157
157
  unless defined?(`Math.erf`)
158
158
  %x{
159
- Opal.defineProperty(Math, 'erf', function(x) {
159
+ Opal.prop(Math, 'erf', function(x) {
160
160
  var A1 = 0.254829592,
161
161
  A2 = -0.284496736,
162
162
  A3 = 1.421413741,
@@ -181,12 +181,12 @@ module Math
181
181
  end
182
182
 
183
183
  def erf(x)
184
- Math.checked :erf, Math.float!(x)
184
+ ::Math.checked :erf, ::Math.float!(x)
185
185
  end
186
186
 
187
187
  unless defined?(`Math.erfc`)
188
188
  %x{
189
- Opal.defineProperty(Math, 'erfc', function(x) {
189
+ Opal.prop(Math, 'erfc', function(x) {
190
190
  var z = Math.abs(x),
191
191
  t = 1.0 / (0.5 * z + 1.0);
192
192
 
@@ -214,11 +214,11 @@ module Math
214
214
  end
215
215
 
216
216
  def erfc(x)
217
- Math.checked :erfc, Math.float!(x)
217
+ ::Math.checked :erfc, ::Math.float!(x)
218
218
  end
219
219
 
220
220
  def exp(x)
221
- Math.checked :exp, Math.float!(x)
221
+ ::Math.checked :exp, ::Math.float!(x)
222
222
  end
223
223
 
224
224
  def frexp(x)
@@ -272,7 +272,7 @@ module Math
272
272
  }
273
273
 
274
274
  if (n === -1 || n === -Infinity) {
275
- #{raise DomainError, 'Numerical argument is out of domain - "gamma"'};
275
+ #{::Kernel.raise DomainError, 'Numerical argument is out of domain - "gamma"'};
276
276
  }
277
277
 
278
278
  if (#{Integer === n}) {
@@ -300,7 +300,7 @@ module Math
300
300
  }
301
301
 
302
302
  if (n < 0.5) {
303
- return Math.PI / (Math.sin(Math.PI * n) * #{Math.gamma(1 - n)});
303
+ return Math.PI / (Math.sin(Math.PI * n) * #{::Math.gamma(1 - n)});
304
304
  }
305
305
 
306
306
  if (n >= 171.35) {
@@ -341,7 +341,7 @@ module Math
341
341
  end
342
342
 
343
343
  def hypot(x, y)
344
- Math.checked :hypot, Math.float!(x), Math.float!(y)
344
+ ::Math.checked :hypot, ::Math.float!(x), ::Math.float!(y)
345
345
  end
346
346
 
347
347
  def ldexp(mantissa, exponent)
@@ -350,7 +350,7 @@ module Math
350
350
 
351
351
  %x{
352
352
  if (isNaN(exponent)) {
353
- #{raise RangeError, 'float NaN out of range of integer'};
353
+ #{::Kernel.raise ::RangeError, 'float NaN out of range of integer'};
354
354
  }
355
355
 
356
356
  return mantissa * Math.pow(2, exponent);
@@ -363,24 +363,24 @@ module Math
363
363
  return [Infinity, 1];
364
364
  }
365
365
  else {
366
- return [Math.log(Math.abs(#{Math.gamma(n)})), #{Math.gamma(n)} < 0 ? -1 : 1];
366
+ return [Math.log(Math.abs(#{::Math.gamma(n)})), #{::Math.gamma(n)} < 0 ? -1 : 1];
367
367
  }
368
368
  }
369
369
  end
370
370
 
371
371
  def log(x, base = undefined)
372
- if String === x
373
- raise `$type_error(x, #{Float})`
372
+ if ::String === x
373
+ ::Kernel.raise `$type_error(x, #{::Float})`
374
374
  end
375
375
 
376
376
  if `base == null`
377
- Math.checked :log, Math.float!(x)
377
+ ::Math.checked :log, ::Math.float!(x)
378
378
  else
379
- if String === base
380
- raise `$type_error(base, #{Float})`
379
+ if ::String === base
380
+ ::Kernel.raise `$type_error(base, #{::Float})`
381
381
  end
382
382
 
383
- Math.checked(:log, Math.float!(x)) / Math.checked(:log, Math.float!(base))
383
+ ::Math.checked(:log, ::Math.float!(x)) / ::Math.checked(:log, ::Math.float!(base))
384
384
  end
385
385
  end
386
386
 
@@ -393,11 +393,11 @@ module Math
393
393
  end
394
394
 
395
395
  def log10(x)
396
- if String === x
397
- raise `$type_error(x, #{Float})`
396
+ if ::String === x
397
+ ::Kernel.raise `$type_error(x, #{::Float})`
398
398
  end
399
399
 
400
- Math.checked :log10, Math.float!(x)
400
+ ::Math.checked :log10, ::Math.float!(x)
401
401
  end
402
402
 
403
403
  unless defined?(`Math.log2`)
@@ -409,15 +409,15 @@ module Math
409
409
  end
410
410
 
411
411
  def log2(x)
412
- if String === x
413
- raise `$type_error(x, #{Float})`
412
+ if ::String === x
413
+ ::Kernel.raise `$type_error(x, #{::Float})`
414
414
  end
415
415
 
416
- Math.checked :log2, Math.float!(x)
416
+ ::Math.checked :log2, ::Math.float!(x)
417
417
  end
418
418
 
419
419
  def sin(x)
420
- Math.checked :sin, Math.float!(x)
420
+ ::Math.checked :sin, ::Math.float!(x)
421
421
  end
422
422
 
423
423
  unless defined?(`Math.sinh`)
@@ -429,21 +429,21 @@ module Math
429
429
  end
430
430
 
431
431
  def sinh(x)
432
- Math.checked :sinh, Math.float!(x)
432
+ ::Math.checked :sinh, ::Math.float!(x)
433
433
  end
434
434
 
435
435
  def sqrt(x)
436
- Math.checked :sqrt, Math.float!(x)
436
+ ::Math.checked :sqrt, ::Math.float!(x)
437
437
  end
438
438
 
439
439
  def tan(x)
440
- x = Math.float!(x)
440
+ x = ::Math.float!(x)
441
441
 
442
442
  if x.infinite?
443
- return Float::NAN
443
+ return ::Float::NAN
444
444
  end
445
445
 
446
- Math.checked :tan, Math.float!(x)
446
+ ::Math.checked :tan, ::Math.float!(x)
447
447
  end
448
448
 
449
449
  unless defined?(`Math.tanh`)
@@ -463,6 +463,6 @@ module Math
463
463
  end
464
464
 
465
465
  def tanh(x)
466
- Math.checked :tanh, Math.float!(x)
466
+ ::Math.checked :tanh, ::Math.float!(x)
467
467
  end
468
468
  end
@@ -1,4 +1,4 @@
1
- class Method
1
+ class ::Method
2
2
  attr_reader :owner, :receiver, :name
3
3
 
4
4
  def initialize(receiver, owner, method, name)
@@ -36,9 +36,6 @@ class Method
36
36
  @method.curry(arity)
37
37
  end
38
38
 
39
- alias [] call
40
- alias === call
41
-
42
39
  def >>(other)
43
40
  @method >> other
44
41
  end
@@ -48,7 +45,7 @@ class Method
48
45
  end
49
46
 
50
47
  def unbind
51
- UnboundMethod.new(@receiver.class, @owner, @method, @name)
48
+ ::UnboundMethod.new(@receiver.class, @owner, @method, @name)
52
49
  end
53
50
 
54
51
  def to_proc
@@ -65,9 +62,12 @@ class Method
65
62
  def inspect
66
63
  "#<#{self.class}: #{@receiver.class}##{@name} (defined in #{@owner} in #{source_location.join(':')})>"
67
64
  end
65
+
66
+ alias [] call
67
+ alias === call
68
68
  end
69
69
 
70
- class UnboundMethod
70
+ class ::UnboundMethod
71
71
  attr_reader :source, :owner, :name
72
72
 
73
73
  def initialize(source, owner, method, name)
@@ -96,14 +96,18 @@ class UnboundMethod
96
96
  def bind(object)
97
97
  %x{
98
98
  if (#{@owner}.$$is_module || Opal.is_a(#{object}, #{@owner})) {
99
- return #{Method.new(object, @owner, @method, @name)};
99
+ return #{::Method.new(object, @owner, @method, @name)};
100
100
  }
101
101
  else {
102
- #{raise TypeError, "can't bind singleton method to a different class (expected #{object}.kind_of?(#{@owner} to be true)"};
102
+ #{::Kernel.raise ::TypeError, "can't bind singleton method to a different class (expected #{object}.kind_of?(#{@owner} to be true)"};
103
103
  }
104
104
  }
105
105
  end
106
106
 
107
+ def bind_call(object, *args, &block)
108
+ bind(object).call(*args, &block)
109
+ end
110
+
107
111
  def inspect
108
112
  "#<#{self.class}: #{@source}##{@name} (defined in #{@owner} in #{source_location.join(':')})>"
109
113
  end