opal 0.8.1 → 0.9.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (331) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/.gitmodules +3 -3
  4. data/.jshintrc +17 -20
  5. data/.travis.yml +22 -11
  6. data/CHANGELOG.md +51 -1
  7. data/CODE_OF_CONDUCT.md +15 -0
  8. data/CONTRIBUTING.md +125 -9
  9. data/Gemfile +1 -1
  10. data/Guardfile +2 -2
  11. data/README.md +95 -29
  12. data/Rakefile +1 -1
  13. data/benchmark/benchmarks +103 -0
  14. data/benchmark/bm_array_flatten.rb +9 -0
  15. data/benchmark/bm_array_intersection_numbers.rb +7 -0
  16. data/benchmark/bm_array_intersection_objects.rb +7 -0
  17. data/benchmark/bm_array_intersection_strings.rb +7 -0
  18. data/benchmark/bm_array_join_ary.rb +9 -0
  19. data/benchmark/bm_array_minus_numbers.rb +7 -0
  20. data/benchmark/bm_array_minus_objects.rb +7 -0
  21. data/benchmark/bm_array_minus_strings.rb +7 -0
  22. data/benchmark/bm_array_union_numbers.rb +7 -0
  23. data/benchmark/bm_array_union_objects.rb +7 -0
  24. data/benchmark/bm_array_union_strings.rb +7 -0
  25. data/benchmark/bm_array_uniq_bang_numbers.rb +5 -0
  26. data/benchmark/bm_array_uniq_bang_objects.rb +5 -0
  27. data/benchmark/bm_array_uniq_bang_strings.rb +5 -0
  28. data/benchmark/bm_array_uniq_numbers.rb +5 -0
  29. data/benchmark/bm_array_uniq_objects.rb +5 -0
  30. data/benchmark/bm_array_uniq_strings.rb +5 -0
  31. data/benchmark/bm_dispatch_bind_table.rb +57 -0
  32. data/benchmark/bm_dispatch_code_gen.rb +65 -0
  33. data/benchmark/bm_dispatch_code_gen_if.rb +64 -0
  34. data/benchmark/bm_dispatch_hardcoded.rb +44 -0
  35. data/benchmark/bm_dispatch_send.rb +38 -0
  36. data/benchmark/bm_dispatch_send_table.rb +57 -0
  37. data/benchmark/bm_hash_assoc_object.rb +11 -0
  38. data/benchmark/bm_hash_assoc_string.rb +9 -0
  39. data/benchmark/bm_hash_clone_object.rb +9 -0
  40. data/benchmark/bm_hash_clone_string.rb +9 -0
  41. data/benchmark/bm_hash_delete_object.rb +11 -0
  42. data/benchmark/bm_hash_delete_string.rb +9 -0
  43. data/benchmark/bm_hash_each_key_object.rb +9 -0
  44. data/benchmark/bm_hash_each_key_string.rb +9 -0
  45. data/benchmark/bm_hash_each_object.rb +9 -0
  46. data/benchmark/bm_hash_each_string.rb +9 -0
  47. data/benchmark/bm_hash_each_value_object.rb +9 -0
  48. data/benchmark/bm_hash_each_value_string.rb +9 -0
  49. data/benchmark/bm_hash_element_reference_object.rb +11 -0
  50. data/benchmark/bm_hash_element_reference_string.rb +9 -0
  51. data/benchmark/bm_hash_element_set_object.rb +5 -0
  52. data/benchmark/bm_hash_element_set_string.rb +5 -0
  53. data/benchmark/bm_hash_equal_value_object.rb +14 -0
  54. data/benchmark/bm_hash_equal_value_string.rb +11 -0
  55. data/benchmark/bm_hash_fetch_object.rb +11 -0
  56. data/benchmark/bm_hash_fetch_string.rb +9 -0
  57. data/benchmark/bm_hash_flatten_object.rb +9 -0
  58. data/benchmark/bm_hash_flatten_string.rb +9 -0
  59. data/benchmark/bm_hash_has_key_object.rb +11 -0
  60. data/benchmark/bm_hash_has_key_string.rb +9 -0
  61. data/benchmark/bm_hash_has_value_object.rb +9 -0
  62. data/benchmark/bm_hash_has_value_string.rb +9 -0
  63. data/benchmark/bm_hash_hash_object.rb +9 -0
  64. data/benchmark/bm_hash_hash_string.rb +9 -0
  65. data/benchmark/bm_hash_inspect_object.rb +9 -0
  66. data/benchmark/bm_hash_inspect_string.rb +9 -0
  67. data/benchmark/bm_hash_invert_object.rb +9 -0
  68. data/benchmark/bm_hash_invert_string.rb +9 -0
  69. data/benchmark/bm_hash_keep_if_object.rb +9 -0
  70. data/benchmark/bm_hash_keep_if_string.rb +9 -0
  71. data/benchmark/bm_hash_key_object.rb +9 -0
  72. data/benchmark/bm_hash_key_string.rb +9 -0
  73. data/benchmark/bm_hash_keys_object.rb +9 -0
  74. data/benchmark/bm_hash_keys_string.rb +9 -0
  75. data/benchmark/bm_hash_literal_mixed_large.rb +3 -0
  76. data/benchmark/bm_hash_literal_mixed_small.rb +3 -0
  77. data/benchmark/bm_hash_literal_object_large.rb +4 -0
  78. data/benchmark/bm_hash_literal_object_small.rb +3 -0
  79. data/benchmark/bm_hash_literal_string_large.rb +4 -0
  80. data/benchmark/bm_hash_literal_string_small.rb +3 -0
  81. data/benchmark/bm_hash_merge_object.rb +22 -0
  82. data/benchmark/bm_hash_merge_string.rb +18 -0
  83. data/benchmark/bm_hash_rassoc_object.rb +9 -0
  84. data/benchmark/bm_hash_rassoc_string.rb +9 -0
  85. data/benchmark/bm_hash_rehash_object.rb +9 -0
  86. data/benchmark/bm_hash_rehash_string.rb +9 -0
  87. data/benchmark/bm_hash_reject_bang_object.rb +9 -0
  88. data/benchmark/bm_hash_reject_bang_string.rb +9 -0
  89. data/benchmark/bm_hash_reject_object.rb +9 -0
  90. data/benchmark/bm_hash_reject_string.rb +9 -0
  91. data/benchmark/bm_hash_replace_object.rb +18 -0
  92. data/benchmark/bm_hash_replace_string.rb +14 -0
  93. data/benchmark/bm_hash_select_bang_object.rb +9 -0
  94. data/benchmark/bm_hash_select_bang_string.rb +9 -0
  95. data/benchmark/bm_hash_select_object.rb +9 -0
  96. data/benchmark/bm_hash_select_string.rb +9 -0
  97. data/benchmark/bm_hash_shift_object.rb +10 -0
  98. data/benchmark/bm_hash_shift_string.rb +10 -0
  99. data/benchmark/bm_hash_to_a_object.rb +9 -0
  100. data/benchmark/bm_hash_to_a_string.rb +9 -0
  101. data/benchmark/bm_hash_to_h_object.rb +10 -0
  102. data/benchmark/bm_hash_to_h_string.rb +10 -0
  103. data/benchmark/bm_hash_values_object.rb +9 -0
  104. data/benchmark/bm_hash_values_string.rb +9 -0
  105. data/benchmark/run.rb +48 -0
  106. data/bin/opal-mspec +1 -1
  107. data/bin/opal-repl +4 -4
  108. data/docs/compiled_ruby.md +214 -56
  109. data/docs/configuring_gems.md +2 -2
  110. data/docs/faq.md +2 -2
  111. data/docs/getting_started.md +19 -2
  112. data/docs/jquery.md +5 -5
  113. data/docs/opal_parser.md +53 -0
  114. data/docs/unsupported_features.md +2 -2
  115. data/docs/upgrading.md +22 -0
  116. data/docs/using_sprockets.md +15 -0
  117. data/examples/rack/config.ru +13 -0
  118. data/examples/sinatra/config.ru +4 -5
  119. data/lib/mspec/opal/runner.rb +54 -11
  120. data/lib/opal.rb +1 -1
  121. data/lib/opal/builder.rb +1 -1
  122. data/lib/opal/builder_processors.rb +1 -1
  123. data/lib/opal/cli.rb +17 -13
  124. data/lib/opal/cli_options.rb +1 -1
  125. data/lib/opal/compiler.rb +12 -0
  126. data/lib/opal/config.rb +4 -0
  127. data/lib/opal/nodes/arglist.rb +5 -7
  128. data/lib/opal/nodes/call.rb +6 -1
  129. data/lib/opal/nodes/call_special.rb +74 -0
  130. data/lib/opal/nodes/def.rb +35 -28
  131. data/lib/opal/nodes/definitions.rb +3 -5
  132. data/lib/opal/nodes/for.rb +13 -0
  133. data/lib/opal/nodes/helpers.rb +15 -1
  134. data/lib/opal/nodes/if.rb +5 -5
  135. data/lib/opal/nodes/iter.rb +6 -1
  136. data/lib/opal/nodes/literal.rb +1 -1
  137. data/lib/opal/nodes/logic.rb +2 -2
  138. data/lib/opal/nodes/masgn.rb +1 -2
  139. data/lib/opal/nodes/module.rb +2 -1
  140. data/lib/opal/nodes/rescue.rb +10 -1
  141. data/lib/opal/nodes/scope.rb +8 -2
  142. data/lib/opal/nodes/singleton_class.rb +1 -1
  143. data/lib/opal/nodes/top.rb +11 -0
  144. data/lib/opal/nodes/variables.rb +4 -4
  145. data/lib/opal/parser.rb +21 -3
  146. data/lib/opal/parser/grammar.rb +3115 -2961
  147. data/lib/opal/parser/grammar.y +29 -6
  148. data/lib/opal/parser/lexer.rb +18 -8
  149. data/lib/opal/sprockets.rb +85 -0
  150. data/lib/opal/sprockets/processor.rb +11 -35
  151. data/lib/opal/sprockets/server.rb +3 -15
  152. data/lib/opal/version.rb +2 -2
  153. data/opal.gemspec +4 -4
  154. data/opal/README.md +9 -0
  155. data/opal/corelib/array.rb +433 -181
  156. data/opal/corelib/basic_object.rb +48 -4
  157. data/opal/corelib/boolean.rb +15 -6
  158. data/opal/corelib/class.rb +6 -5
  159. data/opal/corelib/comparable.rb +12 -0
  160. data/opal/corelib/complex.rb +282 -0
  161. data/opal/corelib/constants.rb +9 -0
  162. data/opal/corelib/enumerable.rb +83 -34
  163. data/opal/corelib/enumerator.rb +3 -1
  164. data/opal/corelib/error.rb +49 -10
  165. data/opal/corelib/file.rb +1 -0
  166. data/opal/corelib/hash.rb +353 -577
  167. data/opal/corelib/helpers.rb +20 -0
  168. data/opal/corelib/kernel.rb +114 -59
  169. data/opal/corelib/math.rb +470 -0
  170. data/opal/corelib/method.rb +11 -2
  171. data/opal/corelib/module.rb +96 -96
  172. data/opal/corelib/{nil_class.rb → nil.rb} +20 -1
  173. data/opal/corelib/number.rb +751 -0
  174. data/opal/corelib/numeric.rb +77 -437
  175. data/opal/corelib/proc.rb +81 -1
  176. data/opal/corelib/process.rb +27 -0
  177. data/opal/corelib/rational.rb +358 -0
  178. data/opal/corelib/regexp.rb +156 -27
  179. data/opal/corelib/runtime.js +724 -335
  180. data/opal/corelib/string.rb +93 -104
  181. data/opal/corelib/string/encoding.rb +177 -0
  182. data/opal/corelib/string/inheritance.rb +2 -0
  183. data/opal/corelib/struct.rb +105 -18
  184. data/opal/corelib/time.rb +267 -146
  185. data/opal/corelib/unsupported.rb +216 -0
  186. data/opal/corelib/variables.rb +0 -6
  187. data/opal/opal.rb +8 -22
  188. data/opal/opal/base.rb +9 -0
  189. data/opal/opal/mini.rb +17 -0
  190. data/spec/README.md +1 -1
  191. data/spec/filters/bugs/array.rb +38 -136
  192. data/spec/filters/bugs/{basic_object.rb → basicobject.rb} +14 -15
  193. data/spec/filters/bugs/class.rb +6 -12
  194. data/spec/filters/bugs/complex.rb +3 -0
  195. data/spec/filters/bugs/date.rb +162 -10
  196. data/spec/filters/bugs/enumerable.rb +31 -58
  197. data/spec/filters/bugs/enumerator.rb +42 -0
  198. data/spec/filters/bugs/exception.rb +66 -10
  199. data/spec/filters/bugs/float.rb +17 -0
  200. data/spec/filters/bugs/hash.rb +11 -97
  201. data/spec/filters/bugs/inheritance.rb +5 -0
  202. data/spec/filters/bugs/integer.rb +28 -0
  203. data/spec/filters/bugs/kernel.rb +304 -12
  204. data/spec/filters/bugs/language.rb +133 -399
  205. data/spec/filters/bugs/language_opal.rb +88 -0
  206. data/spec/filters/bugs/module.rb +203 -62
  207. data/spec/filters/bugs/numeric.rb +32 -0
  208. data/spec/filters/bugs/proc.rb +39 -0
  209. data/spec/filters/bugs/range.rb +148 -0
  210. data/spec/filters/bugs/regexp.rb +168 -0
  211. data/spec/filters/bugs/set.rb +46 -3
  212. data/spec/filters/bugs/singleton.rb +1 -2
  213. data/spec/filters/bugs/string.rb +59 -90
  214. data/spec/filters/bugs/strscan.rb +80 -0
  215. data/spec/filters/bugs/struct.rb +10 -20
  216. data/spec/filters/bugs/time.rb +17 -184
  217. data/spec/filters/bugs/unboundmethod.rb +22 -0
  218. data/spec/filters/unsupported/array.rb +163 -0
  219. data/spec/filters/unsupported/basicobject.rb +14 -0
  220. data/spec/filters/unsupported/bignum.rb +46 -0
  221. data/spec/filters/unsupported/class.rb +4 -0
  222. data/spec/filters/unsupported/delegator.rb +5 -0
  223. data/spec/filters/unsupported/enumerable.rb +11 -0
  224. data/spec/filters/unsupported/enumerator.rb +8 -9
  225. data/spec/filters/unsupported/fixnum.rb +14 -0
  226. data/spec/filters/unsupported/float.rb +41 -7
  227. data/spec/filters/unsupported/freeze.rb +45 -0
  228. data/spec/filters/unsupported/hash.rb +50 -0
  229. data/spec/filters/unsupported/integer.rb +3 -0
  230. data/spec/filters/unsupported/kernel.rb +31 -0
  231. data/spec/filters/unsupported/language.rb +17 -0
  232. data/spec/filters/unsupported/matchdata.rb +30 -0
  233. data/spec/filters/unsupported/math.rb +3 -0
  234. data/spec/filters/unsupported/module.rb +5 -3
  235. data/spec/filters/unsupported/pathname.rb +3 -0
  236. data/spec/filters/unsupported/privacy.rb +136 -0
  237. data/spec/filters/unsupported/proc.rb +3 -0
  238. data/spec/filters/unsupported/regexp.rb +59 -0
  239. data/spec/filters/unsupported/set.rb +4 -0
  240. data/spec/filters/unsupported/{marshal.rb → singleton.rb} +4 -2
  241. data/spec/filters/unsupported/{mutable_strings.rb → string.rb} +456 -336
  242. data/spec/filters/unsupported/struct.rb +3 -0
  243. data/spec/filters/unsupported/symbol.rb +5 -0
  244. data/spec/filters/unsupported/taint.rb +16 -0
  245. data/spec/filters/unsupported/thread.rb +5 -0
  246. data/spec/filters/unsupported/time.rb +197 -16
  247. data/spec/lib/cli_spec.rb +14 -4
  248. data/spec/lib/compiler_spec.rb +9 -1
  249. data/spec/lib/parser/call_spec.rb +18 -0
  250. data/spec/lib/parser/not_spec.rb +2 -8
  251. data/spec/lib/sprockets_spec.rb +24 -0
  252. data/spec/opal/core/array/intersection_spec.rb +38 -0
  253. data/spec/opal/core/array/minus_spec.rb +38 -0
  254. data/spec/opal/core/array/union_spec.rb +38 -0
  255. data/spec/opal/core/array/uniq_spec.rb +49 -0
  256. data/spec/opal/core/exception_spec.rb +7 -0
  257. data/spec/opal/core/fixtures/require_tree_with_dot/file 1.rb +1 -0
  258. data/spec/opal/core/fixtures/require_tree_with_dot/file 2.rb +1 -0
  259. data/spec/opal/core/fixtures/require_tree_with_dot/file 3.rb +1 -0
  260. data/spec/opal/core/fixtures/require_tree_with_dot/index.rb +3 -0
  261. data/spec/opal/core/hash/internals_spec.rb +332 -0
  262. data/spec/opal/core/helpers_spec.rb +14 -0
  263. data/spec/opal/core/kernel/freeze_spec.rb +1 -1
  264. data/spec/opal/core/kernel/raise_spec.rb +13 -0
  265. data/spec/opal/core/kernel/require_tree_spec.rb +9 -0
  266. data/spec/opal/core/language/class_spec.rb +55 -0
  267. data/spec/opal/core/language/fixtures/send.rb +1 -0
  268. data/spec/opal/core/language/keyword_arguments_spec.rb +11 -0
  269. data/spec/opal/core/language/send_spec.rb +5 -0
  270. data/spec/opal/core/method/to_proc_spec.rb +28 -0
  271. data/spec/opal/core/module/name_spec.rb +0 -17
  272. data/spec/opal/core/runtime/bridged_classes_spec.rb +2 -2
  273. data/spec/opal/core/runtime/eval_spec.rb +1 -1
  274. data/spec/opal/core/runtime/method_missing_spec.rb +6 -0
  275. data/spec/opal/core/runtime_spec.rb +51 -0
  276. data/spec/opal/stdlib/js_spec.rb +66 -0
  277. data/spec/opal/stdlib/native/hash_spec.rb +36 -0
  278. data/spec/rubyspecs +152 -273
  279. data/spec/spec_helper.rb +10 -11
  280. data/stdlib/base64.rb +9 -9
  281. data/stdlib/benchmark.rb +551 -4
  282. data/stdlib/console.rb +94 -0
  283. data/stdlib/date.rb +1 -1
  284. data/stdlib/encoding.rb +1 -170
  285. data/stdlib/js.rb +56 -0
  286. data/stdlib/json.rb +9 -14
  287. data/stdlib/math.rb +1 -370
  288. data/stdlib/native.rb +133 -63
  289. data/stdlib/nodejs/file.rb +5 -0
  290. data/stdlib/nodejs/fileutils.rb +13 -6
  291. data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/README.md +1 -1
  292. data/stdlib/opal-parser.rb +1 -2
  293. data/stdlib/ostruct.rb +65 -6
  294. data/stdlib/pp.rb +2 -4
  295. data/stdlib/rbconfig.rb +1 -3
  296. data/stdlib/strscan.rb +164 -28
  297. data/tasks/benchmarking.rake +88 -0
  298. data/tasks/testing.rake +181 -55
  299. data/{lib/mspec/opal/special_calls.rb → tasks/testing/mspec_special_calls.rb} +1 -1
  300. data/{lib/mspec/opal/sprockets.js → tasks/testing/phantomjs1-sprockets.js} +17 -6
  301. data/test/opal/test_keyword.rb +590 -0
  302. data/vendored-minitest/minitest.rb +2 -2
  303. data/vendored-minitest/test/unit.rb +5 -0
  304. metadata +229 -62
  305. data/benchmarks/operators.rb +0 -11
  306. data/benchmarks/prova.js.rb +0 -13
  307. data/docs/libraries.md +0 -36
  308. data/lib/mspec/opal/new.html.erb +0 -1
  309. data/lib/mspec/opal/rake_task.rb +0 -248
  310. data/opal/corelib/match_data.rb +0 -128
  311. data/spec/filters/bugs/math.rb +0 -95
  312. data/spec/filters/bugs/nil.rb +0 -7
  313. data/spec/filters/bugs/opal.rb +0 -9
  314. data/spec/filters/bugs/regular_expressions.rb +0 -41
  315. data/spec/filters/bugs/stringscanner.rb +0 -33
  316. data/spec/filters/unsupported/encoding.rb +0 -102
  317. data/spec/filters/unsupported/frozen.rb +0 -92
  318. data/spec/filters/unsupported/hash_compare_by_identity.rb +0 -16
  319. data/spec/filters/unsupported/integer_size.rb +0 -59
  320. data/spec/filters/unsupported/method_added.rb +0 -10
  321. data/spec/filters/unsupported/private_constants.rb +0 -30
  322. data/spec/filters/unsupported/private_methods.rb +0 -55
  323. data/spec/filters/unsupported/random.rb +0 -4
  324. data/spec/filters/unsupported/rational_numbers.rb +0 -4
  325. data/spec/filters/unsupported/regular_expressions.rb +0 -137
  326. data/spec/filters/unsupported/ruby_exe.rb +0 -5
  327. data/spec/filters/unsupported/symbols.rb +0 -17
  328. data/spec/filters/unsupported/tainted.rb +0 -180
  329. data/spec/filters/unsupported/trusted.rb +0 -88
  330. data/stdlib/process.rb +0 -10
  331. data/tasks/documenting.rake +0 -37
@@ -1,6 +1,7 @@
1
1
  require 'corelib/comparable'
2
+ require 'corelib/regexp'
2
3
 
3
- class String
4
+ class String < `String`
4
5
  include Comparable
5
6
 
6
7
  `def.$$is_string = true`
@@ -8,6 +9,7 @@ class String
8
9
  def __id__
9
10
  `self.toString()`
10
11
  end
12
+
11
13
  alias object_id __id__
12
14
 
13
15
  def self.try_convert(what)
@@ -99,10 +101,6 @@ class String
99
101
  end
100
102
  end
101
103
 
102
- def <<(other)
103
- raise NotImplementedError, '#<< not supported. Mutable String methods are not supported in Opal.'
104
- end
105
-
106
104
  def ==(other)
107
105
  %x{
108
106
  if (other.$$is_string) {
@@ -130,12 +128,12 @@ class String
130
128
 
131
129
  def [](index, length = undefined)
132
130
  %x{
133
- var size = self.length;
131
+ var size = self.length, exclude;
134
132
 
135
133
  if (index.$$is_range) {
136
- var exclude = index.exclude,
137
- length = #{Opal.coerce_to(`index.end`, Integer, :to_int)},
138
- index = #{Opal.coerce_to(`index.begin`, Integer, :to_int)};
134
+ exclude = index.exclude;
135
+ length = #{Opal.coerce_to(`index.end`, Integer, :to_int)};
136
+ index = #{Opal.coerce_to(`index.begin`, Integer, :to_int)};
139
137
 
140
138
  if (Math.abs(index) > size) {
141
139
  return nil;
@@ -226,12 +224,12 @@ class String
226
224
  }
227
225
  end
228
226
 
227
+ alias byteslice []
228
+
229
229
  def capitalize
230
230
  `self.charAt(0).toUpperCase() + self.substr(1).toLowerCase()`
231
231
  end
232
232
 
233
- alias capitalize! <<
234
-
235
233
  def casecmp(other)
236
234
  other = Opal.coerce_to(other, String, :to_str).to_s
237
235
  %x{
@@ -292,8 +290,6 @@ class String
292
290
  self
293
291
  end
294
292
 
295
- alias chomp! <<
296
-
297
293
  def chop
298
294
  %x{
299
295
  var length = self.length;
@@ -311,14 +307,13 @@ class String
311
307
  }
312
308
  end
313
309
 
314
- alias chop! <<
315
-
316
310
  def chr
317
311
  `self.charAt(0)`
318
312
  end
319
313
 
320
314
  def clone
321
315
  copy = `self.slice()`
316
+ copy.copy_singleton_methods(self)
322
317
  copy.initialize_clone(self)
323
318
  copy
324
319
  end
@@ -355,56 +350,79 @@ class String
355
350
  }
356
351
  end
357
352
 
358
- alias dup clone
359
-
360
353
  def downcase
361
354
  `self.toLowerCase()`
362
355
  end
363
356
 
364
- alias downcase! <<
365
-
366
357
  def each_char(&block)
367
- return enum_for :each_char unless block_given?
358
+ return enum_for(:each_char){self.size} unless block_given?
368
359
 
369
360
  %x{
370
361
  for (var i = 0, length = self.length; i < length; i++) {
371
- #{yield `self.charAt(i)`};
362
+ var value = Opal.yield1(block, self.charAt(i));
363
+
364
+ if (value === $breaker) {
365
+ return $breaker.$v;
366
+ }
372
367
  }
373
368
  }
374
369
 
375
370
  self
376
371
  end
377
372
 
378
- def each_line(separator = $/)
373
+ def each_line(separator = $/, &block)
379
374
  return enum_for :each_line, separator unless block_given?
380
375
 
381
376
  %x{
377
+ var value;
378
+
382
379
  if (separator === nil) {
383
- #{yield self};
384
- return self;
380
+ value = Opal.yield1(block, self);
381
+
382
+ if (value === $breaker) {
383
+ return value.$v;
384
+ }
385
+ else {
386
+ return self;
387
+ }
385
388
  }
386
389
 
387
390
  separator = #{Opal.coerce_to(`separator`, String, :to_str)}
388
391
 
392
+ var a, i, n, length, chomped, trailing, splitted;
393
+
389
394
  if (separator.length === 0) {
390
- for (var a = self.split(/(\n{2,})/), i = 0, n = a.length; i < n; i += 2) {
395
+ for (a = self.split(/(\n{2,})/), i = 0, n = a.length; i < n; i += 2) {
391
396
  if (a[i] || a[i + 1]) {
392
- #{yield `(a[i] || "") + (a[i + 1] || "")`};
397
+ value = Opal.yield1(block, (a[i] || "") + (a[i + 1] || ""));
398
+
399
+ if (value === $breaker) {
400
+ return value.$v;
401
+ }
393
402
  }
394
403
  }
404
+
395
405
  return self;
396
406
  }
397
407
 
398
- var chomped = #{chomp(separator)},
399
- trailing = self.length != chomped.length,
400
- splitted = chomped.split(separator);
408
+ chomped = #{chomp(separator)};
409
+ trailing = self.length != chomped.length;
410
+ splitted = chomped.split(separator);
401
411
 
402
- for (var i = 0, length = splitted.length; i < length; i++) {
412
+ for (i = 0, length = splitted.length; i < length; i++) {
403
413
  if (i < length - 1 || trailing) {
404
- #{yield `splitted[i] + separator`};
414
+ value = Opal.yield1(block, splitted[i] + separator);
415
+
416
+ if (value === $breaker) {
417
+ return value.$v;
418
+ }
405
419
  }
406
420
  else {
407
- #{yield `splitted[i]`};
421
+ value = Opal.yield1(block, splitted[i]);
422
+
423
+ if (value === $breaker) {
424
+ return value.$v;
425
+ }
408
426
  }
409
427
  }
410
428
  }
@@ -436,6 +454,10 @@ class String
436
454
 
437
455
  def gsub(pattern, replacement = undefined, &block)
438
456
  %x{
457
+ if (replacement === undefined && block === nil) {
458
+ #{return enum_for :gsub, pattern}
459
+ }
460
+
439
461
  var result = '', match_data = nil, index = 0, match, _replacement;
440
462
 
441
463
  if (pattern.$$is_regexp) {
@@ -457,9 +479,6 @@ class String
457
479
  match_data = #{MatchData.new `pattern`, `match`};
458
480
 
459
481
  if (replacement === undefined) {
460
- if (block === nil) {
461
- #{raise ArgumentError, 'wrong number of arguments (1 for 2)'}
462
- }
463
482
  _replacement = block(match[0]);
464
483
  }
465
484
  else if (replacement.$$is_hash) {
@@ -504,8 +523,6 @@ class String
504
523
  }
505
524
  end
506
525
 
507
- alias gsub! <<
508
-
509
526
  def hash
510
527
  `self.toString()`
511
528
  end
@@ -638,8 +655,6 @@ class String
638
655
  `self.replace(/^\s*/, '')`
639
656
  end
640
657
 
641
- alias lstrip! <<
642
-
643
658
  def match(pattern, pos = undefined, &block)
644
659
  if String === pattern || pattern.respond_to?(:to_str)
645
660
  pattern = Regexp.new(pattern.to_str)
@@ -722,8 +737,6 @@ class String
722
737
  }
723
738
  end
724
739
 
725
- alias next! <<
726
-
727
740
  def oct
728
741
  %x{
729
742
  var result,
@@ -805,8 +818,6 @@ class String
805
818
  `self.split('').reverse().join('')`
806
819
  end
807
820
 
808
- alias reverse! <<
809
-
810
821
  def rindex(search, offset = undefined)
811
822
  %x{
812
823
  var i, m, r, _m;
@@ -950,7 +961,6 @@ class String
950
961
  alias size length
951
962
 
952
963
  alias slice []
953
- alias slice! <<
954
964
 
955
965
  def split(pattern = undefined, limit = undefined)
956
966
  %x{
@@ -1050,8 +1060,6 @@ class String
1050
1060
  }
1051
1061
  end
1052
1062
 
1053
- alias squeeze! <<
1054
-
1055
1063
  def start_with?(*prefixes)
1056
1064
  %x{
1057
1065
  for (var i = 0, length = prefixes.length; i < length; i++) {
@@ -1070,8 +1078,6 @@ class String
1070
1078
  `self.replace(/^\s*/, '').replace(/[\s\u0000]*$/, '')`
1071
1079
  end
1072
1080
 
1073
- alias strip! <<
1074
-
1075
1081
  def sub(pattern, replacement = undefined, &block)
1076
1082
  %x{
1077
1083
  if (!pattern.$$is_regexp) {
@@ -1124,10 +1130,7 @@ class String
1124
1130
  }
1125
1131
  end
1126
1132
 
1127
- alias sub! <<
1128
-
1129
1133
  alias succ next
1130
- alias succ! <<
1131
1134
 
1132
1135
  def sum(n = 16)
1133
1136
  %x{
@@ -1163,8 +1166,6 @@ class String
1163
1166
  }
1164
1167
  end
1165
1168
 
1166
- alias swapcase! <<
1167
-
1168
1169
  def to_f
1169
1170
  %x{
1170
1171
  if (self.charAt(0) === '_') {
@@ -1268,6 +1269,7 @@ class String
1268
1269
  return self;
1269
1270
  }
1270
1271
 
1272
+ var i, in_range, c, ch, start, end, length;
1271
1273
  var subs = {};
1272
1274
  var from_chars = from.split('');
1273
1275
  var from_length = from_chars.length;
@@ -1285,9 +1287,9 @@ class String
1285
1287
 
1286
1288
  var from_chars_expanded = [];
1287
1289
  var last_from = null;
1288
- var in_range = false;
1289
- for (var i = 0; i < from_length; i++) {
1290
- var ch = from_chars[i];
1290
+ in_range = false;
1291
+ for (i = 0; i < from_length; i++) {
1292
+ ch = from_chars[i];
1291
1293
  if (last_from == null) {
1292
1294
  last_from = ch;
1293
1295
  from_chars_expanded.push(ch);
@@ -1305,12 +1307,12 @@ class String
1305
1307
  }
1306
1308
  }
1307
1309
  else if (in_range) {
1308
- var start = last_from.charCodeAt(0);
1309
- var end = ch.charCodeAt(0);
1310
+ start = last_from.charCodeAt(0);
1311
+ end = ch.charCodeAt(0);
1310
1312
  if (start > end) {
1311
1313
  #{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
1312
1314
  }
1313
- for (var c = start + 1; c < end; c++) {
1315
+ for (c = start + 1; c < end; c++) {
1314
1316
  from_chars_expanded.push(String.fromCharCode(c));
1315
1317
  }
1316
1318
  from_chars_expanded.push(ch);
@@ -1326,7 +1328,7 @@ class String
1326
1328
  from_length = from_chars.length;
1327
1329
 
1328
1330
  if (inverse) {
1329
- for (var i = 0; i < from_length; i++) {
1331
+ for (i = 0; i < from_length; i++) {
1330
1332
  subs[from_chars[i]] = true;
1331
1333
  }
1332
1334
  }
@@ -1334,9 +1336,9 @@ class String
1334
1336
  if (to_length > 0) {
1335
1337
  var to_chars_expanded = [];
1336
1338
  var last_to = null;
1337
- var in_range = false;
1338
- for (var i = 0; i < to_length; i++) {
1339
- var ch = to_chars[i];
1339
+ in_range = false;
1340
+ for (i = 0; i < to_length; i++) {
1341
+ ch = to_chars[i];
1340
1342
  if (last_from == null) {
1341
1343
  last_from = ch;
1342
1344
  to_chars_expanded.push(ch);
@@ -1354,12 +1356,12 @@ class String
1354
1356
  }
1355
1357
  }
1356
1358
  else if (in_range) {
1357
- var start = last_from.charCodeAt(0);
1358
- var end = ch.charCodeAt(0);
1359
+ start = last_from.charCodeAt(0);
1360
+ end = ch.charCodeAt(0);
1359
1361
  if (start > end) {
1360
1362
  #{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
1361
1363
  }
1362
- for (var c = start + 1; c < end; c++) {
1364
+ for (c = start + 1; c < end; c++) {
1363
1365
  to_chars_expanded.push(String.fromCharCode(c));
1364
1366
  }
1365
1367
  to_chars_expanded.push(ch);
@@ -1378,19 +1380,19 @@ class String
1378
1380
  var length_diff = from_length - to_length;
1379
1381
  if (length_diff > 0) {
1380
1382
  var pad_char = (to_length > 0 ? to_chars[to_length - 1] : '');
1381
- for (var i = 0; i < length_diff; i++) {
1383
+ for (i = 0; i < length_diff; i++) {
1382
1384
  to_chars.push(pad_char);
1383
1385
  }
1384
1386
  }
1385
1387
 
1386
- for (var i = 0; i < from_length; i++) {
1388
+ for (i = 0; i < from_length; i++) {
1387
1389
  subs[from_chars[i]] = to_chars[i];
1388
1390
  }
1389
1391
  }
1390
1392
 
1391
1393
  var new_str = ''
1392
- for (var i = 0, length = self.length; i < length; i++) {
1393
- var ch = self.charAt(i);
1394
+ for (i = 0, length = self.length; i < length; i++) {
1395
+ ch = self.charAt(i);
1394
1396
  var sub = subs[ch];
1395
1397
  if (inverse) {
1396
1398
  new_str += (sub == null ? global_sub : ch);
@@ -1403,8 +1405,6 @@ class String
1403
1405
  }
1404
1406
  end
1405
1407
 
1406
- alias tr! <<
1407
-
1408
1408
  def tr_s(from, to)
1409
1409
  from = Opal.coerce_to(from, String, :to_str).to_s
1410
1410
  to = Opal.coerce_to(to, String, :to_str).to_s
@@ -1413,6 +1413,7 @@ class String
1413
1413
  return self;
1414
1414
  }
1415
1415
 
1416
+ var i, in_range, c, ch, start, end, length;
1416
1417
  var subs = {};
1417
1418
  var from_chars = from.split('');
1418
1419
  var from_length = from_chars.length;
@@ -1430,9 +1431,9 @@ class String
1430
1431
 
1431
1432
  var from_chars_expanded = [];
1432
1433
  var last_from = null;
1433
- var in_range = false;
1434
- for (var i = 0; i < from_length; i++) {
1435
- var ch = from_chars[i];
1434
+ in_range = false;
1435
+ for (i = 0; i < from_length; i++) {
1436
+ ch = from_chars[i];
1436
1437
  if (last_from == null) {
1437
1438
  last_from = ch;
1438
1439
  from_chars_expanded.push(ch);
@@ -1450,12 +1451,12 @@ class String
1450
1451
  }
1451
1452
  }
1452
1453
  else if (in_range) {
1453
- var start = last_from.charCodeAt(0);
1454
- var end = ch.charCodeAt(0);
1454
+ start = last_from.charCodeAt(0);
1455
+ end = ch.charCodeAt(0);
1455
1456
  if (start > end) {
1456
1457
  #{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
1457
1458
  }
1458
- for (var c = start + 1; c < end; c++) {
1459
+ for (c = start + 1; c < end; c++) {
1459
1460
  from_chars_expanded.push(String.fromCharCode(c));
1460
1461
  }
1461
1462
  from_chars_expanded.push(ch);
@@ -1471,7 +1472,7 @@ class String
1471
1472
  from_length = from_chars.length;
1472
1473
 
1473
1474
  if (inverse) {
1474
- for (var i = 0; i < from_length; i++) {
1475
+ for (i = 0; i < from_length; i++) {
1475
1476
  subs[from_chars[i]] = true;
1476
1477
  }
1477
1478
  }
@@ -1479,9 +1480,9 @@ class String
1479
1480
  if (to_length > 0) {
1480
1481
  var to_chars_expanded = [];
1481
1482
  var last_to = null;
1482
- var in_range = false;
1483
- for (var i = 0; i < to_length; i++) {
1484
- var ch = to_chars[i];
1483
+ in_range = false;
1484
+ for (i = 0; i < to_length; i++) {
1485
+ ch = to_chars[i];
1485
1486
  if (last_from == null) {
1486
1487
  last_from = ch;
1487
1488
  to_chars_expanded.push(ch);
@@ -1499,12 +1500,12 @@ class String
1499
1500
  }
1500
1501
  }
1501
1502
  else if (in_range) {
1502
- var start = last_from.charCodeAt(0);
1503
- var end = ch.charCodeAt(0);
1503
+ start = last_from.charCodeAt(0);
1504
+ end = ch.charCodeAt(0);
1504
1505
  if (start > end) {
1505
1506
  #{raise ArgumentError, "invalid range \"#{`String.fromCharCode(start)`}-#{`String.fromCharCode(end)`}\" in string transliteration"}
1506
1507
  }
1507
- for (var c = start + 1; c < end; c++) {
1508
+ for (c = start + 1; c < end; c++) {
1508
1509
  to_chars_expanded.push(String.fromCharCode(c));
1509
1510
  }
1510
1511
  to_chars_expanded.push(ch);
@@ -1523,19 +1524,19 @@ class String
1523
1524
  var length_diff = from_length - to_length;
1524
1525
  if (length_diff > 0) {
1525
1526
  var pad_char = (to_length > 0 ? to_chars[to_length - 1] : '');
1526
- for (var i = 0; i < length_diff; i++) {
1527
+ for (i = 0; i < length_diff; i++) {
1527
1528
  to_chars.push(pad_char);
1528
1529
  }
1529
1530
  }
1530
1531
 
1531
- for (var i = 0; i < from_length; i++) {
1532
+ for (i = 0; i < from_length; i++) {
1532
1533
  subs[from_chars[i]] = to_chars[i];
1533
1534
  }
1534
1535
  }
1535
1536
  var new_str = ''
1536
1537
  var last_substitute = null
1537
- for (var i = 0, length = self.length; i < length; i++) {
1538
- var ch = self.charAt(i);
1538
+ for (i = 0, length = self.length; i < length; i++) {
1539
+ ch = self.charAt(i);
1539
1540
  var sub = subs[ch]
1540
1541
  if (inverse) {
1541
1542
  if (sub == null) {
@@ -1566,22 +1567,10 @@ class String
1566
1567
  }
1567
1568
  end
1568
1569
 
1569
- alias tr_s! <<
1570
-
1571
1570
  def upcase
1572
1571
  `self.toUpperCase()`
1573
1572
  end
1574
1573
 
1575
- alias upcase! <<
1576
-
1577
- def freeze
1578
- self
1579
- end
1580
-
1581
- def frozen?
1582
- true
1583
- end
1584
-
1585
1574
  def upto(stop, excl = false, &block)
1586
1575
  return enum_for :upto, stop, excl unless block_given?
1587
1576
  stop = Opal.coerce_to(stop, String, :to_str)
@@ -1601,10 +1590,10 @@ class String
1601
1590
  a += 1;
1602
1591
  }
1603
1592
 
1604
- } else if (parseInt(s).toString() === s && parseInt(stop).toString() === stop) {
1593
+ } else if (parseInt(s, 10).toString() === s && parseInt(stop, 10).toString() === stop) {
1605
1594
 
1606
- a = parseInt(s);
1607
- b = parseInt(stop);
1595
+ a = parseInt(s, 10);
1596
+ b = parseInt(stop, 10);
1608
1597
 
1609
1598
  while (a <= b) {
1610
1599
  if (excl && a === b) {