opal 0.11.4 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (379) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +42 -10
  3. data/.rubocop.yml +398 -0
  4. data/.rubocop_todo.yml +44 -0
  5. data/.travis.yml +28 -34
  6. data/CHANGELOG.md +363 -142
  7. data/CONTRIBUTING.md +3 -5
  8. data/Gemfile +17 -12
  9. data/Guardfile +0 -1
  10. data/HACKING.md +1 -35
  11. data/LICENSE +2 -2
  12. data/README.md +42 -13
  13. data/Rakefile +1 -4
  14. data/UNRELEASED.md +133 -0
  15. data/benchmark-ips/README.md +6 -0
  16. data/benchmark-ips/bm_block_vs_yield.rb +21 -0
  17. data/benchmark-ips/bm_js_symbols_vs_strings.rb +28 -0
  18. data/benchmark-ips/bm_while_true_vs_loop.rb +19 -0
  19. data/bin/console +14 -0
  20. data/bin/opal +0 -1
  21. data/bin/opal-benchmark-ips +8 -0
  22. data/bin/opal-mspec +9 -1
  23. data/bin/opal-repl +2 -1
  24. data/bin/rake +7 -0
  25. data/bin/setup +8 -0
  26. data/docs/compiled_ruby.md +89 -8
  27. data/docs/compiler.md +3 -20
  28. data/docs/jquery.md +44 -11
  29. data/docs/promises.md +1 -1
  30. data/docs/rails.md +16 -12
  31. data/docs/sinatra.md +15 -8
  32. data/docs/using_sprockets.md +16 -11
  33. data/examples/rack/config.ru +1 -0
  34. data/examples/sinatra/Gemfile +1 -0
  35. data/examples/sinatra/config.ru +2 -11
  36. data/exe/opal-repl +3 -11
  37. data/lib/opal.rb +1 -0
  38. data/lib/opal/ast/builder.rb +4 -1
  39. data/lib/opal/ast/node.rb +1 -0
  40. data/lib/opal/builder.rb +84 -63
  41. data/lib/opal/builder_processors.rb +41 -56
  42. data/lib/opal/cli.rb +33 -49
  43. data/lib/opal/cli_options.rb +27 -17
  44. data/lib/opal/cli_runners.rb +73 -16
  45. data/lib/opal/cli_runners/applescript.rb +4 -4
  46. data/lib/opal/cli_runners/chrome.rb +29 -17
  47. data/lib/opal/cli_runners/nashorn.rb +5 -4
  48. data/lib/opal/cli_runners/nodejs.rb +8 -6
  49. data/lib/opal/cli_runners/server.rb +12 -11
  50. data/lib/opal/compiler.rb +85 -103
  51. data/lib/opal/config.rb +3 -3
  52. data/lib/opal/deprecations.rb +2 -1
  53. data/lib/opal/eof_content.rb +2 -2
  54. data/lib/opal/erb.rb +8 -7
  55. data/lib/opal/errors.rb +72 -1
  56. data/lib/opal/fragment.rb +23 -3
  57. data/lib/opal/hike.rb +305 -0
  58. data/lib/opal/nodes.rb +5 -10
  59. data/lib/opal/nodes/arglist.rb +7 -6
  60. data/lib/opal/nodes/args.rb +36 -0
  61. data/lib/opal/nodes/args/arg.rb +22 -0
  62. data/lib/opal/nodes/args/arity_check.rb +151 -0
  63. data/lib/opal/nodes/args/ensure_kwargs_are_kwargs.rb +28 -0
  64. data/lib/opal/nodes/args/extract_block_arg.rb +34 -0
  65. data/lib/opal/nodes/args/extract_kwarg.rb +32 -0
  66. data/lib/opal/nodes/args/extract_kwargs.rb +28 -0
  67. data/lib/opal/nodes/args/extract_kwoptarg.rb +35 -0
  68. data/lib/opal/nodes/args/extract_kwrestarg.rb +35 -0
  69. data/lib/opal/nodes/args/extract_optarg.rb +35 -0
  70. data/lib/opal/nodes/args/extract_post_arg.rb +28 -0
  71. data/lib/opal/nodes/args/extract_post_optarg.rb +41 -0
  72. data/lib/opal/nodes/args/extract_restarg.rb +40 -0
  73. data/lib/opal/nodes/args/fake_arg.rb +26 -0
  74. data/lib/opal/nodes/args/initialize_iterarg.rb +28 -0
  75. data/lib/opal/nodes/args/initialize_shadowarg.rb +24 -0
  76. data/lib/opal/nodes/args/parameters.rb +63 -0
  77. data/lib/opal/nodes/args/prepare_post_args.rb +22 -0
  78. data/lib/opal/nodes/array.rb +9 -8
  79. data/lib/opal/nodes/base.rb +20 -11
  80. data/lib/opal/nodes/call.rb +24 -25
  81. data/lib/opal/nodes/call_special.rb +4 -3
  82. data/lib/opal/nodes/case.rb +24 -26
  83. data/lib/opal/nodes/class.rb +4 -5
  84. data/lib/opal/nodes/constants.rb +8 -7
  85. data/lib/opal/nodes/csend.rb +2 -3
  86. data/lib/opal/nodes/def.rb +28 -74
  87. data/lib/opal/nodes/defined.rb +36 -36
  88. data/lib/opal/nodes/definitions.rb +10 -7
  89. data/lib/opal/nodes/defs.rb +8 -16
  90. data/lib/opal/nodes/hash.rb +5 -4
  91. data/lib/opal/nodes/helpers.rb +8 -8
  92. data/lib/opal/nodes/if.rb +10 -8
  93. data/lib/opal/nodes/iter.rb +16 -103
  94. data/lib/opal/nodes/lambda.rb +18 -0
  95. data/lib/opal/nodes/literal.rb +29 -63
  96. data/lib/opal/nodes/logic.rb +25 -24
  97. data/lib/opal/nodes/masgn.rb +8 -6
  98. data/lib/opal/nodes/module.rb +4 -4
  99. data/lib/opal/nodes/node_with_args.rb +14 -208
  100. data/lib/opal/nodes/rescue.rb +32 -32
  101. data/lib/opal/nodes/runtime_helpers.rb +5 -4
  102. data/lib/opal/nodes/scope.rb +18 -29
  103. data/lib/opal/nodes/singleton_class.rb +3 -3
  104. data/lib/opal/nodes/super.rb +12 -18
  105. data/lib/opal/nodes/top.rb +10 -8
  106. data/lib/opal/nodes/variables.rb +6 -6
  107. data/lib/opal/nodes/while.rb +7 -6
  108. data/lib/opal/nodes/x_string.rb +139 -0
  109. data/lib/opal/nodes/yield.rb +10 -7
  110. data/lib/opal/parser.rb +9 -46
  111. data/lib/opal/parser/default_config.rb +50 -0
  112. data/lib/opal/parser/patch.rb +26 -0
  113. data/lib/opal/parser/source_buffer.rb +11 -0
  114. data/lib/opal/parser/with_c_lexer.rb +14 -0
  115. data/lib/opal/parser/with_ruby_lexer.rb +6 -0
  116. data/lib/opal/path_reader.rb +6 -5
  117. data/lib/opal/paths.rb +9 -6
  118. data/lib/opal/regexp_anchors.rb +6 -5
  119. data/lib/opal/rewriter.rb +7 -0
  120. data/lib/opal/rewriters/arguments.rb +58 -0
  121. data/lib/opal/rewriters/base.rb +32 -12
  122. data/lib/opal/rewriters/binary_operator_assignment.rb +20 -20
  123. data/lib/opal/rewriters/block_to_iter.rb +2 -1
  124. data/lib/opal/rewriters/break_finder.rb +2 -0
  125. data/lib/opal/rewriters/dot_js_syntax.rb +3 -2
  126. data/lib/opal/rewriters/dump_args.rb +28 -0
  127. data/lib/opal/rewriters/explicit_writer_return.rb +4 -3
  128. data/lib/opal/rewriters/for_rewriter.rb +12 -12
  129. data/lib/opal/rewriters/hashes/key_duplicates_rewriter.rb +2 -1
  130. data/lib/opal/rewriters/inline_args.rb +220 -0
  131. data/lib/opal/rewriters/js_reserved_words.rb +21 -17
  132. data/lib/opal/rewriters/logical_operator_assignment.rb +24 -14
  133. data/lib/opal/rewriters/mlhs_args.rb +128 -0
  134. data/lib/opal/rewriters/opal_engine_check.rb +11 -6
  135. data/lib/opal/rewriters/rubyspec/filters_rewriter.rb +3 -2
  136. data/lib/opal/server.rb +1 -0
  137. data/lib/opal/simple_server.rb +15 -23
  138. data/lib/opal/source_map.rb +7 -70
  139. data/lib/opal/source_map/file.rb +199 -0
  140. data/lib/opal/source_map/index.rb +83 -0
  141. data/lib/opal/source_map/map.rb +26 -0
  142. data/lib/opal/source_map/vlq.rb +98 -0
  143. data/lib/opal/util.rb +7 -5
  144. data/lib/opal/version.rb +2 -1
  145. data/lib/tilt/opal.rb +3 -3
  146. data/opal.gemspec +18 -9
  147. data/opal/corelib/array.rb +135 -117
  148. data/opal/corelib/array/pack.rb +446 -0
  149. data/opal/corelib/basic_object.rb +23 -9
  150. data/opal/corelib/boolean.rb +3 -3
  151. data/opal/corelib/class.rb +4 -10
  152. data/opal/corelib/comparable.rb +36 -23
  153. data/opal/corelib/complex.rb +108 -14
  154. data/opal/corelib/constants.rb +4 -4
  155. data/opal/corelib/enumerable.rb +132 -135
  156. data/opal/corelib/enumerator.rb +47 -50
  157. data/opal/corelib/error.rb +65 -8
  158. data/opal/corelib/file.rb +37 -32
  159. data/opal/corelib/hash.rb +90 -21
  160. data/opal/corelib/helpers.rb +7 -6
  161. data/opal/corelib/kernel.rb +53 -586
  162. data/opal/corelib/kernel/format.rb +544 -0
  163. data/opal/corelib/marshal.rb +1 -13
  164. data/opal/corelib/marshal/read_buffer.rb +20 -23
  165. data/opal/corelib/marshal/write_buffer.rb +23 -15
  166. data/opal/corelib/math.rb +12 -16
  167. data/opal/corelib/method.rb +5 -3
  168. data/opal/corelib/module.rb +80 -109
  169. data/opal/corelib/nil.rb +2 -2
  170. data/opal/corelib/number.rb +177 -43
  171. data/opal/corelib/numeric.rb +22 -16
  172. data/opal/corelib/pack_unpack/format_string_parser.rb +135 -0
  173. data/opal/corelib/proc.rb +3 -4
  174. data/opal/corelib/process.rb +1 -1
  175. data/opal/corelib/random.rb +24 -16
  176. data/opal/corelib/random/MersenneTwister.js +137 -0
  177. data/opal/corelib/random/math_random.js.rb +9 -0
  178. data/opal/corelib/random/mersenne_twister.js.rb +13 -0
  179. data/opal/corelib/random/seedrandom.js.rb +12 -0
  180. data/opal/corelib/range.rb +25 -26
  181. data/opal/corelib/rational.rb +57 -17
  182. data/opal/corelib/regexp.rb +39 -43
  183. data/opal/corelib/runtime.js +806 -683
  184. data/opal/corelib/string.rb +213 -112
  185. data/opal/corelib/string/encoding.rb +14 -17
  186. data/opal/corelib/string/unpack.rb +793 -0
  187. data/opal/corelib/struct.rb +40 -24
  188. data/opal/corelib/time.rb +14 -15
  189. data/opal/corelib/unsupported.rb +26 -4
  190. data/opal/opal.rb +2 -1
  191. data/opal/opal/full.rb +2 -0
  192. data/stdlib/base64.rb +1 -1
  193. data/stdlib/bigdecimal.rb +11 -13
  194. data/stdlib/buffer.rb +9 -8
  195. data/stdlib/buffer/array.rb +46 -48
  196. data/stdlib/buffer/view.rb +85 -47
  197. data/stdlib/console.rb +18 -18
  198. data/stdlib/date.rb +85 -66
  199. data/stdlib/delegate.rb +2 -2
  200. data/stdlib/e2mmap.rb +176 -0
  201. data/stdlib/encoding.rb +1 -1
  202. data/stdlib/erb.rb +1 -1
  203. data/stdlib/forwardable.rb +14 -14
  204. data/stdlib/json.rb +1 -2
  205. data/stdlib/logger.rb +112 -0
  206. data/stdlib/math.rb +1 -1
  207. data/stdlib/matrix.rb +2169 -0
  208. data/stdlib/matrix/eigenvalue_decomposition.rb +883 -0
  209. data/stdlib/matrix/lup_decomposition.rb +219 -0
  210. data/stdlib/nashorn/file.rb +7 -9
  211. data/stdlib/native.rb +69 -63
  212. data/stdlib/nodejs.rb +3 -0
  213. data/stdlib/nodejs/dir.rb +25 -4
  214. data/stdlib/nodejs/env.rb +40 -0
  215. data/stdlib/nodejs/file.rb +184 -34
  216. data/stdlib/nodejs/fileutils.rb +4 -4
  217. data/stdlib/nodejs/io.rb +4 -46
  218. data/stdlib/nodejs/irb.rb +27 -29
  219. data/stdlib/nodejs/kernel.rb +2 -11
  220. data/stdlib/nodejs/node_modules/balanced-match/.npmignore +5 -0
  221. data/stdlib/nodejs/node_modules/balanced-match/LICENSE.md +21 -0
  222. data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match → balanced-match}/README.md +13 -2
  223. data/stdlib/nodejs/node_modules/balanced-match/index.js +59 -0
  224. data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match → balanced-match}/package.json +46 -42
  225. data/stdlib/nodejs/node_modules/brace-expansion/LICENSE +21 -0
  226. data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion → brace-expansion}/README.md +9 -1
  227. data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion → brace-expansion}/index.js +12 -2
  228. data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion → brace-expansion}/package.json +48 -48
  229. data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/.travis.yml +0 -0
  230. data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/LICENSE +0 -0
  231. data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/README.markdown +0 -0
  232. data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/example/map.js +0 -0
  233. data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/index.js +0 -0
  234. data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/package.json +47 -42
  235. data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/test/map.js +0 -0
  236. data/stdlib/nodejs/node_modules/fs.realpath/LICENSE +43 -0
  237. data/stdlib/nodejs/node_modules/fs.realpath/README.md +33 -0
  238. data/stdlib/nodejs/node_modules/fs.realpath/index.js +66 -0
  239. data/stdlib/nodejs/node_modules/fs.realpath/old.js +303 -0
  240. data/stdlib/nodejs/node_modules/fs.realpath/package.json +59 -0
  241. data/stdlib/nodejs/node_modules/glob/README.md +57 -46
  242. data/stdlib/nodejs/node_modules/glob/changelog.md +67 -0
  243. data/stdlib/nodejs/node_modules/glob/common.js +91 -28
  244. data/stdlib/nodejs/node_modules/glob/glob.js +196 -55
  245. data/stdlib/nodejs/node_modules/glob/package.json +55 -51
  246. data/stdlib/nodejs/node_modules/glob/sync.js +116 -39
  247. data/stdlib/nodejs/node_modules/{glob/node_modules/inflight → inflight}/LICENSE +0 -0
  248. data/stdlib/nodejs/node_modules/{glob/node_modules/inflight → inflight}/README.md +0 -0
  249. data/stdlib/nodejs/node_modules/inflight/inflight.js +54 -0
  250. data/stdlib/nodejs/node_modules/inflight/package.json +58 -0
  251. data/stdlib/nodejs/node_modules/{glob/node_modules/inherits → inherits}/LICENSE +0 -0
  252. data/stdlib/nodejs/node_modules/{glob/node_modules/inherits → inherits}/README.md +0 -0
  253. data/stdlib/nodejs/node_modules/inherits/inherits.js +7 -0
  254. data/stdlib/nodejs/node_modules/{glob/node_modules/inherits → inherits}/inherits_browser.js +0 -0
  255. data/stdlib/nodejs/node_modules/inherits/package.json +61 -0
  256. data/stdlib/nodejs/node_modules/{glob/node_modules/inflight/node_modules/wrappy → minimatch}/LICENSE +0 -0
  257. data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch → minimatch}/README.md +2 -9
  258. data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch → minimatch}/minimatch.js +284 -206
  259. data/stdlib/nodejs/node_modules/minimatch/package.json +63 -0
  260. data/stdlib/nodejs/node_modules/{glob/node_modules/once/node_modules/wrappy → once}/LICENSE +0 -0
  261. data/stdlib/nodejs/node_modules/{glob/node_modules/once → once}/README.md +28 -0
  262. data/stdlib/nodejs/node_modules/once/once.js +42 -0
  263. data/stdlib/nodejs/node_modules/once/package.json +67 -0
  264. data/stdlib/nodejs/node_modules/path-is-absolute/index.js +20 -0
  265. data/stdlib/nodejs/node_modules/path-is-absolute/license +21 -0
  266. data/stdlib/nodejs/node_modules/path-is-absolute/package.json +75 -0
  267. data/stdlib/nodejs/node_modules/path-is-absolute/readme.md +59 -0
  268. data/stdlib/nodejs/node_modules/unxhr/LICENSE +22 -0
  269. data/stdlib/nodejs/node_modules/unxhr/README.md +41 -0
  270. data/stdlib/nodejs/node_modules/unxhr/lib/XMLHttpRequest.js +598 -0
  271. data/stdlib/nodejs/node_modules/unxhr/lib/browser.js +2 -0
  272. data/stdlib/nodejs/node_modules/unxhr/lib/request.js +63 -0
  273. data/stdlib/nodejs/node_modules/unxhr/package.json +75 -0
  274. data/stdlib/nodejs/node_modules/wrappy/LICENSE +15 -0
  275. data/stdlib/nodejs/node_modules/{glob/node_modules/inflight/node_modules/wrappy → wrappy}/README.md +0 -0
  276. data/stdlib/nodejs/node_modules/wrappy/package.json +59 -0
  277. data/stdlib/nodejs/node_modules/{glob/node_modules/inflight/node_modules/wrappy → wrappy}/wrappy.js +0 -0
  278. data/stdlib/nodejs/open-uri.rb +26 -0
  279. data/stdlib/nodejs/package-lock.json +88 -0
  280. data/stdlib/nodejs/package.json +2 -1
  281. data/stdlib/nodejs/pathname.rb +20 -0
  282. data/stdlib/nodejs/require.rb +3 -3
  283. data/stdlib/nodejs/stacktrace.rb +1 -1
  284. data/stdlib/nodejs/yaml.rb +1 -1
  285. data/stdlib/opal-builder.rb +1 -0
  286. data/stdlib/opal-parser.rb +4 -1
  287. data/stdlib/opal-platform.rb +8 -10
  288. data/stdlib/opal-source-maps.rb +0 -1
  289. data/stdlib/open-uri.rb +349 -0
  290. data/stdlib/ostruct.rb +19 -17
  291. data/stdlib/pathname.rb +22 -22
  292. data/stdlib/pp.rb +5 -5
  293. data/stdlib/promise.rb +30 -26
  294. data/stdlib/rbconfig/sizeof.rb +50 -0
  295. data/stdlib/securerandom.rb +1 -1
  296. data/stdlib/set.rb +21 -23
  297. data/stdlib/singleton.rb +3 -4
  298. data/stdlib/stringio.rb +33 -0
  299. data/stdlib/strscan.rb +55 -55
  300. data/stdlib/template.rb +1 -2
  301. data/stdlib/thread.rb +6 -7
  302. data/tasks/benchmarking.rake +1 -1
  303. data/tasks/building.rake +4 -12
  304. data/tasks/linting.rake +17 -2
  305. data/tasks/releasing.rake +84 -0
  306. data/tasks/testing.rake +57 -15
  307. data/tasks/testing/mspec_special_calls.rb +23 -4
  308. data/vendored-minitest/minitest.rb +1 -1
  309. metadata +169 -168
  310. data/bin/opal-build +0 -3
  311. data/exe/opal-mspec +0 -10
  312. data/lib/opal/nodes/args/initialize_kwargs.rb +0 -29
  313. data/lib/opal/nodes/args/kwarg.rb +0 -31
  314. data/lib/opal/nodes/args/kwoptarg.rb +0 -34
  315. data/lib/opal/nodes/args/kwrestarg.rb +0 -39
  316. data/lib/opal/nodes/args/mlhsarg.rb +0 -78
  317. data/lib/opal/nodes/args/normarg.rb +0 -29
  318. data/lib/opal/nodes/args/optarg.rb +0 -25
  319. data/lib/opal/nodes/args/post_args.rb +0 -201
  320. data/lib/opal/nodes/args/post_kwargs.rb +0 -32
  321. data/lib/opal/nodes/args/restarg.rb +0 -38
  322. data/lib/opal/nodes/inline_args.rb +0 -60
  323. data/opal/corelib/string/inheritance.rb +0 -123
  324. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/.eslintrc +0 -17
  325. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/inflight.js +0 -44
  326. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/package.json +0 -52
  327. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js +0 -51
  328. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/package.json +0 -61
  329. data/stdlib/nodejs/node_modules/glob/node_modules/inflight/test.js +0 -97
  330. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/inherits.js +0 -1
  331. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/package.json +0 -51
  332. data/stdlib/nodejs/node_modules/glob/node_modules/inherits/test.js +0 -25
  333. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/.npmignore +0 -1
  334. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/.travis.yml +0 -4
  335. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/LICENSE +0 -23
  336. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/benchmark.js +0 -15
  337. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/browser.js +0 -1181
  338. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/.npmignore +0 -2
  339. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/.travis.yml +0 -3
  340. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/example.js +0 -8
  341. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.npmignore +0 -2
  342. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.travis.yml +0 -4
  343. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/Makefile +0 -6
  344. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/example.js +0 -5
  345. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js +0 -38
  346. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/test/balanced.js +0 -56
  347. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/bash-comparison.js +0 -32
  348. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/bash-results.txt +0 -1075
  349. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/cases.txt +0 -182
  350. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/dollar.js +0 -9
  351. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/empty-option.js +0 -10
  352. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/generate.sh +0 -24
  353. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/negative-increment.js +0 -15
  354. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/nested.js +0 -16
  355. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/order.js +0 -10
  356. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/pad.js +0 -13
  357. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/same-type.js +0 -7
  358. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/sequence.js +0 -50
  359. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/package.json +0 -60
  360. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/basic.js +0 -399
  361. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/brace-expand.js +0 -45
  362. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/defaults.js +0 -274
  363. data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/extglob-ending-with-state-char.js +0 -8
  364. data/stdlib/nodejs/node_modules/glob/node_modules/once/LICENSE +0 -27
  365. data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/README.md +0 -36
  366. data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/package.json +0 -52
  367. data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js +0 -51
  368. data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/wrappy.js +0 -33
  369. data/stdlib/nodejs/node_modules/glob/node_modules/once/once.js +0 -21
  370. data/stdlib/nodejs/node_modules/glob/node_modules/once/package.json +0 -60
  371. data/stdlib/nodejs/node_modules/glob/node_modules/once/test/once.js +0 -23
  372. data/stdlib/nodejs/rubygems.rb +0 -68
  373. data/stdlib/source_map.rb +0 -5
  374. data/stdlib/source_map/map.rb +0 -220
  375. data/stdlib/source_map/mapping.rb +0 -26
  376. data/stdlib/source_map/offset.rb +0 -88
  377. data/stdlib/source_map/version.rb +0 -3
  378. data/stdlib/source_map/vlq.rb +0 -99
  379. data/stdlib/sourcemap.rb +0 -1
@@ -4,7 +4,18 @@ require 'corelib/regexp'
4
4
  class String < `String`
5
5
  include Comparable
6
6
 
7
- `def.$$is_string = true`
7
+ %x{
8
+ Opal.defineProperty(#{self}.$$prototype, '$$is_string', true);
9
+
10
+ Opal.defineProperty(#{self}.$$prototype, '$$cast', function(string) {
11
+ var klass = this.$$class;
12
+ if (klass.$$constructor === String) {
13
+ return string;
14
+ } else {
15
+ return new klass.$$constructor(string);
16
+ }
17
+ });
18
+ }
8
19
 
9
20
  def __id__
10
21
  `self.toString()`
@@ -18,7 +29,7 @@ class String < `String`
18
29
 
19
30
  def self.new(str = '')
20
31
  str = Opal.coerce_to(str, String, :to_str)
21
- `new String(str)`
32
+ `new self.$$constructor(str)`
22
33
  end
23
34
 
24
35
  def initialize(str = undefined)
@@ -47,7 +58,7 @@ class String < `String`
47
58
  }
48
59
 
49
60
  if (count === 0) {
50
- return '';
61
+ return self.$$cast('');
51
62
  }
52
63
 
53
64
  var result = '',
@@ -72,7 +83,7 @@ class String < `String`
72
83
  string += string;
73
84
  }
74
85
 
75
- return result;
86
+ return self.$$cast(result);
76
87
  }
77
88
  end
78
89
 
@@ -157,7 +168,7 @@ class String < `String`
157
168
  length = 0;
158
169
  }
159
170
 
160
- return self.substr(index, length);
171
+ return self.$$cast(self.substr(index, length));
161
172
  }
162
173
 
163
174
 
@@ -165,7 +176,7 @@ class String < `String`
165
176
  if (length != null) {
166
177
  #{raise TypeError}
167
178
  }
168
- return self.indexOf(index) !== -1 ? index : nil;
179
+ return self.indexOf(index) !== -1 ? self.$$cast(index) : nil;
169
180
  }
170
181
 
171
182
 
@@ -180,17 +191,17 @@ class String < `String`
180
191
  #{$~ = MatchData.new(`index`, `match`)}
181
192
 
182
193
  if (length == null) {
183
- return match[0];
194
+ return self.$$cast(match[0]);
184
195
  }
185
196
 
186
197
  length = #{Opal.coerce_to(`length`, Integer, :to_int)};
187
198
 
188
199
  if (length < 0 && -length < match.length) {
189
- return match[length += match.length];
200
+ return self.$$cast(match[length += match.length]);
190
201
  }
191
202
 
192
203
  if (length >= 0 && length < match.length) {
193
- return match[length];
204
+ return self.$$cast(match[length]);
194
205
  }
195
206
 
196
207
  return nil;
@@ -207,7 +218,7 @@ class String < `String`
207
218
  if (index >= size || index < 0) {
208
219
  return nil;
209
220
  }
210
- return self.substr(index, 1);
221
+ return self.$$cast(self.substr(index, 1));
211
222
  }
212
223
 
213
224
  length = #{Opal.coerce_to(`length`, Integer, :to_int)};
@@ -220,17 +231,22 @@ class String < `String`
220
231
  return nil;
221
232
  }
222
233
 
223
- return self.substr(index, length);
234
+ return self.$$cast(self.substr(index, length));
224
235
  }
225
236
  end
226
237
 
227
238
  alias byteslice []
228
239
 
240
+ def b
241
+ force_encoding('binary')
242
+ end
243
+
229
244
  def capitalize
230
- `self.charAt(0).toUpperCase() + self.substr(1).toLowerCase()`
245
+ `self.$$cast(self.charAt(0).toUpperCase() + self.substr(1).toLowerCase())`
231
246
  end
232
247
 
233
248
  def casecmp(other)
249
+ return nil unless other.respond_to?(:to_str)
234
250
  other = Opal.coerce_to(other, String, :to_str).to_s
235
251
  %x{
236
252
  var ascii_only = /^[\x00-\x7F]*$/;
@@ -242,6 +258,17 @@ class String < `String`
242
258
  self <=> other
243
259
  end
244
260
 
261
+ def casecmp?(other)
262
+ %x{
263
+ var cmp = #{casecmp(other)};
264
+ if (cmp === nil) {
265
+ return nil;
266
+ } else {
267
+ return cmp === 0;
268
+ }
269
+ }
270
+ end
271
+
245
272
  def center(width, padstr = ' ')
246
273
  width = Opal.coerce_to(width, Integer, :to_int)
247
274
  padstr = Opal.coerce_to(padstr, String, :to_str).to_s
@@ -253,10 +280,10 @@ class String < `String`
253
280
  return self if `width <= self.length`
254
281
 
255
282
  %x{
256
- var ljustified = #{ljust ((width + @length) / 2).ceil, padstr},
257
- rjustified = #{rjust ((width + @length) / 2).floor, padstr};
283
+ var ljustified = #{ljust ((width + `self.length`) / 2).ceil, padstr},
284
+ rjustified = #{rjust ((width + `self.length`) / 2).floor, padstr};
258
285
 
259
- return rjustified + ljustified.slice(self.length);
286
+ return self.$$cast(rjustified + ljustified.slice(self.length));
260
287
  }
261
288
  end
262
289
 
@@ -272,19 +299,25 @@ class String < `String`
272
299
  separator = Opal.coerce_to!(separator, String, :to_str).to_s
273
300
 
274
301
  %x{
302
+ var result;
303
+
275
304
  if (separator === "\n") {
276
- return self.replace(/\r?\n?$/, '');
305
+ result = self.replace(/\r?\n?$/, '');
277
306
  }
278
307
  else if (separator === "") {
279
- return self.replace(/(\r?\n)+$/, '');
308
+ result = self.replace(/(\r?\n)+$/, '');
280
309
  }
281
- else if (self.length > separator.length) {
310
+ else if (self.length >= separator.length) {
282
311
  var tail = self.substr(self.length - separator.length, separator.length);
283
312
 
284
313
  if (tail === separator) {
285
- return self.substr(0, self.length - separator.length);
314
+ result = self.substr(0, self.length - separator.length);
286
315
  }
287
316
  }
317
+
318
+ if (result != null) {
319
+ return self.$$cast(result);
320
+ }
288
321
  }
289
322
 
290
323
  self
@@ -292,18 +325,17 @@ class String < `String`
292
325
 
293
326
  def chop
294
327
  %x{
295
- var length = self.length;
328
+ var length = self.length, result;
296
329
 
297
330
  if (length <= 1) {
298
- return "";
331
+ result = "";
332
+ } else if (self.charAt(length - 1) === "\n" && self.charAt(length - 2) === "\r") {
333
+ result = self.substr(0, length - 2);
334
+ } else {
335
+ result = self.substr(0, length - 1);
299
336
  }
300
337
 
301
- if (self.charAt(length - 1) === "\n" && self.charAt(length - 2) === "\r") {
302
- return self.substr(0, length - 2);
303
- }
304
- else {
305
- return self.substr(0, length - 1);
306
- }
338
+ return self.$$cast(result);
307
339
  }
308
340
  end
309
341
 
@@ -327,7 +359,7 @@ class String < `String`
327
359
  def count(*sets)
328
360
  %x{
329
361
  if (sets.length === 0) {
330
- #{raise ArgumentError, "ArgumentError: wrong number of arguments (0 for 1+)"}
362
+ #{raise ArgumentError, 'ArgumentError: wrong number of arguments (0 for 1+)'}
331
363
  }
332
364
  var char_class = char_class_from_char_sets(sets);
333
365
  if (char_class === null) {
@@ -340,22 +372,50 @@ class String < `String`
340
372
  def delete(*sets)
341
373
  %x{
342
374
  if (sets.length === 0) {
343
- #{raise ArgumentError, "ArgumentError: wrong number of arguments (0 for 1+)"}
375
+ #{raise ArgumentError, 'ArgumentError: wrong number of arguments (0 for 1+)'}
344
376
  }
345
377
  var char_class = char_class_from_char_sets(sets);
346
378
  if (char_class === null) {
347
379
  return self;
348
380
  }
349
- return self.replace(new RegExp(char_class, 'g'), '');
381
+ return self.$$cast(self.replace(new RegExp(char_class, 'g'), ''));
382
+ }
383
+ end
384
+
385
+ def delete_prefix(prefix)
386
+ %x{
387
+ if (!prefix.$$is_string) {
388
+ #{prefix = Opal.coerce_to(prefix, String, :to_str)}
389
+ }
390
+
391
+ if (self.slice(0, prefix.length) === prefix) {
392
+ return self.$$cast(self.slice(prefix.length));
393
+ } else {
394
+ return self;
395
+ }
396
+ }
397
+ end
398
+
399
+ def delete_suffix(suffix)
400
+ %x{
401
+ if (!suffix.$$is_string) {
402
+ #{suffix = Opal.coerce_to(suffix, String, :to_str)}
403
+ }
404
+
405
+ if (self.slice(self.length - suffix.length) === suffix) {
406
+ return self.$$cast(self.slice(0, self.length - suffix.length));
407
+ } else {
408
+ return self;
409
+ }
350
410
  }
351
411
  end
352
412
 
353
413
  def downcase
354
- `self.toLowerCase()`
414
+ `self.$$cast(self.toLowerCase())`
355
415
  end
356
416
 
357
417
  def each_char(&block)
358
- return enum_for(:each_char){self.size} unless block_given?
418
+ return enum_for(:each_char) { size } unless block_given?
359
419
 
360
420
  %x{
361
421
  for (var i = 0, length = self.length; i < length; i++) {
@@ -383,7 +443,8 @@ class String < `String`
383
443
  if (separator.length === 0) {
384
444
  for (a = self.split(/(\n{2,})/), i = 0, n = a.length; i < n; i += 2) {
385
445
  if (a[i] || a[i + 1]) {
386
- Opal.yield1(block, (a[i] || "") + (a[i + 1] || ""));
446
+ var value = (a[i] || "") + (a[i + 1] || "");
447
+ Opal.yield1(block, self.$$cast(value));
387
448
  }
388
449
  }
389
450
 
@@ -396,10 +457,10 @@ class String < `String`
396
457
 
397
458
  for (i = 0, length = splitted.length; i < length; i++) {
398
459
  if (i < length - 1 || trailing) {
399
- Opal.yield1(block, splitted[i] + separator);
460
+ Opal.yield1(block, self.$$cast(splitted[i] + separator));
400
461
  }
401
462
  else {
402
- Opal.yield1(block, splitted[i]);
463
+ Opal.yield1(block, self.$$cast(splitted[i]));
403
464
  }
404
465
  }
405
466
  }
@@ -426,7 +487,6 @@ class String < `String`
426
487
  false
427
488
  end
428
489
 
429
- alias eql? ==
430
490
  alias equal? ===
431
491
 
432
492
  def gsub(pattern, replacement = undefined, &block)
@@ -438,12 +498,13 @@ class String < `String`
438
498
  var result = '', match_data = nil, index = 0, match, _replacement;
439
499
 
440
500
  if (pattern.$$is_regexp) {
441
- pattern = new RegExp(pattern.source, 'gm' + (pattern.ignoreCase ? 'i' : ''));
501
+ pattern = Opal.global_multiline_regexp(pattern);
442
502
  } else {
443
503
  pattern = #{Opal.coerce_to(`pattern`, String, :to_str)};
444
504
  pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm');
445
505
  }
446
506
 
507
+ var lastIndex;
447
508
  while (true) {
448
509
  match = pattern.exec(self);
449
510
 
@@ -456,7 +517,9 @@ class String < `String`
456
517
  match_data = #{MatchData.new `pattern`, `match`};
457
518
 
458
519
  if (replacement === undefined) {
520
+ lastIndex = pattern.lastIndex;
459
521
  _replacement = block(match[0]);
522
+ pattern.lastIndex = lastIndex; // save and restore lastIndex
460
523
  }
461
524
  else if (replacement.$$is_hash) {
462
525
  _replacement = #{`replacement`[`match[0]`].to_s};
@@ -496,7 +559,7 @@ class String < `String`
496
559
  }
497
560
 
498
561
  #{$~ = `match_data`}
499
- return result;
562
+ return self.$$cast(result);
500
563
  }
501
564
  end
502
565
 
@@ -536,7 +599,7 @@ class String < `String`
536
599
  }
537
600
 
538
601
  if (search.$$is_regexp) {
539
- regex = new RegExp(search.source, 'gm' + (search.ignoreCase ? 'i' : ''));
602
+ regex = Opal.global_multiline_regexp(search);
540
603
  while (true) {
541
604
  match = regex.exec(self);
542
605
  if (match === null) {
@@ -587,7 +650,7 @@ class String < `String`
587
650
  end
588
651
 
589
652
  def intern
590
- self
653
+ `self.toString()`
591
654
  end
592
655
 
593
656
  def lines(separator = $/, &block)
@@ -619,7 +682,7 @@ class String < `String`
619
682
  result += padstr;
620
683
  }
621
684
 
622
- return self + result.slice(0, width);
685
+ return self.$$cast(self + result.slice(0, width));
623
686
  }
624
687
  end
625
688
 
@@ -643,11 +706,23 @@ class String < `String`
643
706
  pattern.match(self, pos, &block)
644
707
  end
645
708
 
709
+ def match?(pattern, pos = undefined)
710
+ if String === pattern || pattern.respond_to?(:to_str)
711
+ pattern = Regexp.new(pattern.to_str)
712
+ end
713
+
714
+ unless Regexp === pattern
715
+ raise TypeError, "wrong argument type #{pattern.class} (expected Regexp)"
716
+ end
717
+
718
+ pattern.match?(self, pos)
719
+ end
720
+
646
721
  def next
647
722
  %x{
648
723
  var i = self.length;
649
724
  if (i === 0) {
650
- return '';
725
+ return self.$$cast('');
651
726
  }
652
727
  var result = self;
653
728
  var first_alphanum_char_index = self.search(/[a-zA-Z0-9]/);
@@ -709,7 +784,7 @@ class String < `String`
709
784
  break;
710
785
  }
711
786
  }
712
- return result;
787
+ return self.$$cast(result);
713
788
  }
714
789
  end
715
790
 
@@ -812,7 +887,7 @@ class String < `String`
812
887
 
813
888
  if (search.$$is_regexp) {
814
889
  m = null;
815
- r = new RegExp(search.source, 'gm' + (search.ignoreCase ? 'i' : ''));
890
+ r = Opal.global_multiline_regexp(search);
816
891
  while (true) {
817
892
  _m = r.exec(self);
818
893
  if (_m === null || _m.index > offset) {
@@ -853,7 +928,7 @@ class String < `String`
853
928
  result = Array(patterns + 1).join(padstr),
854
929
  remaining = chars - result.length;
855
930
 
856
- return result + padstr.slice(0, remaining) + self;
931
+ return self.$$cast(result + padstr.slice(0, remaining) + self);
857
932
  }
858
933
  end
859
934
 
@@ -863,7 +938,7 @@ class String < `String`
863
938
 
864
939
  if (sep.$$is_regexp) {
865
940
  m = null;
866
- r = new RegExp(sep.source, 'gm' + (sep.ignoreCase ? 'i' : ''));
941
+ r = Opal.global_multiline_regexp(sep);
867
942
 
868
943
  while (true) {
869
944
  _m = r.exec(self);
@@ -910,7 +985,7 @@ class String < `String`
910
985
  match;
911
986
 
912
987
  if (pattern.$$is_regexp) {
913
- pattern = new RegExp(pattern.source, 'gm' + (pattern.ignoreCase ? 'i' : ''));
988
+ pattern = Opal.global_multiline_regexp(pattern);
914
989
  } else {
915
990
  pattern = #{Opal.coerce_to(`pattern`, String, :to_str)};
916
991
  pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm');
@@ -964,7 +1039,7 @@ class String < `String`
964
1039
  i, ii;
965
1040
 
966
1041
  if (pattern.$$is_regexp) {
967
- pattern = new RegExp(pattern.source, 'gm' + (pattern.ignoreCase ? 'i' : ''));
1042
+ pattern = Opal.global_multiline_regexp(pattern);
968
1043
  } else {
969
1044
  pattern = #{Opal.coerce_to(pattern, String, :to_str).to_s};
970
1045
  if (pattern === ' ') {
@@ -978,17 +1053,24 @@ class String < `String`
978
1053
  result = string.split(pattern);
979
1054
 
980
1055
  if (result.length === 1 && result[0] === string) {
981
- return result;
1056
+ return [self.$$cast(result[0])];
982
1057
  }
983
1058
 
984
1059
  while ((i = result.indexOf(undefined)) !== -1) {
985
1060
  result.splice(i, 1);
986
1061
  }
987
1062
 
1063
+ function castResult() {
1064
+ for (i = 0; i < result.length; i++) {
1065
+ result[i] = self.$$cast(result[i]);
1066
+ }
1067
+ }
1068
+
988
1069
  if (limit === 0) {
989
1070
  while (result[result.length - 1] === '') {
990
1071
  result.length -= 1;
991
1072
  }
1073
+ castResult();
992
1074
  return result;
993
1075
  }
994
1076
 
@@ -1000,15 +1082,18 @@ class String < `String`
1000
1082
  result.push('');
1001
1083
  }
1002
1084
  }
1085
+ castResult();
1003
1086
  return result;
1004
1087
  }
1005
1088
 
1006
1089
  if (match !== null && match[0] === '') {
1007
1090
  result.splice(limit - 1, result.length - 1, result.slice(limit - 1).join(''));
1091
+ castResult();
1008
1092
  return result;
1009
1093
  }
1010
1094
 
1011
1095
  if (limit >= result.length) {
1096
+ castResult();
1012
1097
  return result;
1013
1098
  }
1014
1099
 
@@ -1022,6 +1107,7 @@ class String < `String`
1022
1107
  match = pattern.exec(string);
1023
1108
  }
1024
1109
  result.splice(limit - 1, result.length - 1, string.slice(index));
1110
+ castResult();
1025
1111
  return result;
1026
1112
  }
1027
1113
  end
@@ -1029,13 +1115,13 @@ class String < `String`
1029
1115
  def squeeze(*sets)
1030
1116
  %x{
1031
1117
  if (sets.length === 0) {
1032
- return self.replace(/(.)\1+/g, '$1');
1118
+ return self.$$cast(self.replace(/(.)\1+/g, '$1'));
1033
1119
  }
1034
1120
  var char_class = char_class_from_char_sets(sets);
1035
1121
  if (char_class === null) {
1036
1122
  return self;
1037
1123
  }
1038
- return self.replace(new RegExp('(' + char_class + ')\\1+', 'g'), '$1');
1124
+ return self.$$cast(self.replace(new RegExp('(' + char_class + ')\\1+', 'g'), '$1'));
1039
1125
  }
1040
1126
  end
1041
1127
 
@@ -1064,48 +1150,53 @@ class String < `String`
1064
1150
  pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
1065
1151
  }
1066
1152
 
1067
- var result = pattern.exec(self);
1153
+ var result, match = pattern.exec(self);
1068
1154
 
1069
- if (result === null) {
1155
+ if (match === null) {
1070
1156
  #{$~ = nil}
1071
- return self.toString();
1072
- }
1157
+ result = self.toString();
1158
+ } else {
1159
+ #{MatchData.new `pattern`, `match`}
1073
1160
 
1074
- #{MatchData.new `pattern`, `result`}
1161
+ if (replacement === undefined) {
1075
1162
 
1076
- if (replacement === undefined) {
1077
- if (block === nil) {
1078
- #{raise ArgumentError, 'wrong number of arguments (1 for 2)'}
1079
- }
1080
- return self.slice(0, result.index) + block(result[0]) + self.slice(result.index + result[0].length);
1081
- }
1163
+ if (block === nil) {
1164
+ #{raise ArgumentError, 'wrong number of arguments (1 for 2)'}
1165
+ }
1166
+ result = self.slice(0, match.index) + block(match[0]) + self.slice(match.index + match[0].length);
1082
1167
 
1083
- if (replacement.$$is_hash) {
1084
- return self.slice(0, result.index) + #{`replacement`[`result[0]`].to_s} + self.slice(result.index + result[0].length);
1085
- }
1168
+ } else if (replacement.$$is_hash) {
1086
1169
 
1087
- replacement = #{Opal.coerce_to(`replacement`, String, :to_str)};
1170
+ result = self.slice(0, match.index) + #{`replacement`[`match[0]`].to_s} + self.slice(match.index + match[0].length);
1088
1171
 
1089
- replacement = replacement.replace(/([\\]+)([0-9+&`'])/g, function (original, slashes, command) {
1090
- if (slashes.length % 2 === 0) {
1091
- return original;
1092
- }
1093
- switch (command) {
1094
- case "+":
1095
- for (var i = result.length - 1; i > 0; i--) {
1096
- if (result[i] !== undefined) {
1097
- return slashes.slice(1) + result[i];
1172
+ } else {
1173
+
1174
+ replacement = #{Opal.coerce_to(`replacement`, String, :to_str)};
1175
+
1176
+ replacement = replacement.replace(/([\\]+)([0-9+&`'])/g, function (original, slashes, command) {
1177
+ if (slashes.length % 2 === 0) {
1178
+ return original;
1098
1179
  }
1099
- }
1100
- return '';
1101
- case "&": return slashes.slice(1) + result[0];
1102
- case "`": return slashes.slice(1) + self.slice(0, result.index);
1103
- case "'": return slashes.slice(1) + self.slice(result.index + result[0].length);
1104
- default: return slashes.slice(1) + (result[command] || '');
1180
+ switch (command) {
1181
+ case "+":
1182
+ for (var i = match.length - 1; i > 0; i--) {
1183
+ if (match[i] !== undefined) {
1184
+ return slashes.slice(1) + match[i];
1185
+ }
1186
+ }
1187
+ return '';
1188
+ case "&": return slashes.slice(1) + match[0];
1189
+ case "`": return slashes.slice(1) + self.slice(0, match.index);
1190
+ case "'": return slashes.slice(1) + self.slice(match.index + match[0].length);
1191
+ default: return slashes.slice(1) + (match[command] || '');
1192
+ }
1193
+ }).replace(/\\\\/g, '\\');
1194
+
1195
+ result = self.slice(0, match.index) + replacement + self.slice(match.index + match[0].length);
1105
1196
  }
1106
- }).replace(/\\\\/g, '\\');
1197
+ }
1107
1198
 
1108
- return self.slice(0, result.index) + replacement + self.slice(result.index + result[0].length);
1199
+ return self.$$cast(result);
1109
1200
  }
1110
1201
  end
1111
1202
 
@@ -1222,16 +1313,33 @@ class String < `String`
1222
1313
  end
1223
1314
 
1224
1315
  def to_proc
1225
- sym = `self.valueOf()`
1316
+ method_name = '$' + `self.valueOf()`
1226
1317
 
1227
1318
  proc do |*args, &block|
1228
1319
  %x{
1229
1320
  if (args.length === 0) {
1230
- #{raise ArgumentError, "no receiver given"}
1321
+ #{raise ArgumentError, 'no receiver given'}
1322
+ }
1323
+
1324
+ var recv = args[0];
1325
+
1326
+ if (recv == null) recv = nil;
1327
+
1328
+ var body = recv[#{method_name}];
1329
+
1330
+ if (!body) {
1331
+ return recv.$method_missing.apply(recv, args);
1332
+ }
1333
+
1334
+ if (typeof block === 'function') {
1335
+ body.$$p = block;
1336
+ }
1337
+
1338
+ if (args.length === 1) {
1339
+ return body.call(recv);
1340
+ } else {
1341
+ return body.apply(recv, args.slice(1));
1231
1342
  }
1232
- var obj = args.shift();
1233
- if (obj == null) obj = nil;
1234
- return Opal.send(obj, sym, args, block);
1235
1343
  }
1236
1344
  end
1237
1345
  end
@@ -1384,7 +1492,7 @@ class String < `String`
1384
1492
  new_str += (sub != null ? sub : ch);
1385
1493
  }
1386
1494
  }
1387
- return new_str;
1495
+ return self.$$cast(new_str);
1388
1496
  }
1389
1497
  end
1390
1498
 
@@ -1546,12 +1654,12 @@ class String < `String`
1546
1654
  }
1547
1655
  }
1548
1656
  }
1549
- return new_str;
1657
+ return self.$$cast(new_str);
1550
1658
  }
1551
1659
  end
1552
1660
 
1553
1661
  def upcase
1554
- `self.toUpperCase()`
1662
+ `self.$$cast(self.toUpperCase())`
1555
1663
  end
1556
1664
 
1557
1665
  def upto(stop, excl = false, &block)
@@ -1698,30 +1806,23 @@ class String < `String`
1698
1806
  end
1699
1807
 
1700
1808
  def self._load(*args)
1701
- self.new(*args)
1809
+ new(*args)
1702
1810
  end
1703
1811
 
1704
- def unpack(pattern)
1705
- %x{
1706
- function stringToBytes(string) {
1707
- var i,
1708
- singleByte,
1709
- l = string.length,
1710
- result = [];
1812
+ def unicode_normalize(form = undefined)
1813
+ `self.toString()`
1814
+ end
1711
1815
 
1712
- for (i = 0; i < l; i++) {
1713
- singleByte = string.charCodeAt(i);
1714
- result.push(singleByte);
1715
- }
1716
- return result;
1717
- }
1718
- }
1719
- case pattern
1720
- when "U*", "C*"
1721
- `stringToBytes(self);`
1722
- else
1723
- raise NotImplementedError
1724
- end
1816
+ def unicode_normalized?(form = undefined)
1817
+ true
1818
+ end
1819
+
1820
+ def unpack(format)
1821
+ raise "To use String#unpack, you must first require 'corelib/string/unpack'."
1822
+ end
1823
+
1824
+ def unpack1(format)
1825
+ raise "To use String#unpack1, you must first require 'corelib/string/unpack'."
1725
1826
  end
1726
1827
  end
1727
1828