opal 1.0.4 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (399) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +13 -12
  3. data/.gitattributes +1 -1
  4. data/.github/workflows/build.yml +23 -10
  5. data/.jshintrc +1 -1
  6. data/.overcommit.yml +35 -0
  7. data/.rubocop.yml +44 -7
  8. data/{.rubocop_todo.yml → .rubocop/todo.yml} +4 -5
  9. data/CHANGELOG.md +138 -1
  10. data/Gemfile +1 -2
  11. data/HACKING.md +2 -9
  12. data/LICENSE +1 -1
  13. data/README.md +21 -18
  14. data/UNRELEASED.md +4 -2
  15. data/benchmark-ips/bm_array_pop_1.rb +8 -0
  16. data/benchmark-ips/bm_array_shift.rb +7 -0
  17. data/benchmark-ips/bm_js_symbols_vs_strings.rb +7 -2
  18. data/benchmark-ips/class_shovel_vs_singleton_class.rb +16 -0
  19. data/bin/build-browser-source-map-support +4 -0
  20. data/bin/format-filters +54 -0
  21. data/bin/remove-filters +39 -0
  22. data/docs/roda-sprockets.md +86 -0
  23. data/docs/sinatra.md +5 -12
  24. data/examples/rack/Gemfile +1 -0
  25. data/examples/rack/app/application.rb +3 -0
  26. data/examples/rack/config.ru +5 -4
  27. data/exe/opal-repl +2 -83
  28. data/lib/opal/ast/builder.rb +1 -1
  29. data/lib/opal/builder.rb +2 -10
  30. data/lib/opal/builder_processors.rb +1 -1
  31. data/lib/opal/cli.rb +4 -1
  32. data/lib/opal/cli_options.rb +10 -3
  33. data/lib/opal/cli_runners.rb +27 -37
  34. data/lib/opal/cli_runners/applescript.rb +5 -44
  35. data/lib/opal/cli_runners/chrome.js +7 -35
  36. data/lib/opal/cli_runners/chrome.rb +75 -17
  37. data/lib/opal/cli_runners/compiler.rb +17 -0
  38. data/lib/opal/cli_runners/nashorn.rb +9 -43
  39. data/lib/opal/cli_runners/nodejs.rb +18 -47
  40. data/lib/opal/cli_runners/server.rb +18 -6
  41. data/lib/opal/cli_runners/source-map-support-browser.js +6449 -0
  42. data/lib/opal/cli_runners/source-map-support-node.js +3704 -0
  43. data/lib/opal/cli_runners/source-map-support.js +639 -0
  44. data/lib/opal/cli_runners/system_runner.rb +45 -0
  45. data/lib/opal/compiler.rb +57 -29
  46. data/lib/opal/config.rb +0 -5
  47. data/lib/opal/erb.rb +1 -1
  48. data/lib/opal/magic_comments.rb +34 -0
  49. data/lib/opal/nodes/args/arity_check.rb +2 -1
  50. data/lib/opal/nodes/base.rb +1 -1
  51. data/lib/opal/nodes/call.rb +1 -4
  52. data/lib/opal/nodes/def.rb +2 -0
  53. data/lib/opal/nodes/iter.rb +1 -1
  54. data/lib/opal/nodes/literal.rb +19 -14
  55. data/lib/opal/nodes/logic.rb +5 -80
  56. data/lib/opal/nodes/masgn.rb +2 -0
  57. data/lib/opal/nodes/rescue.rb +1 -1
  58. data/lib/opal/nodes/super.rb +24 -10
  59. data/lib/opal/nodes/top.rb +5 -4
  60. data/lib/opal/parser/with_c_lexer.rb +2 -1
  61. data/lib/opal/parser/with_ruby_lexer.rb +1 -1
  62. data/lib/opal/path_reader.rb +2 -2
  63. data/lib/opal/paths.rb +8 -5
  64. data/lib/opal/repl.rb +103 -0
  65. data/lib/opal/rewriter.rb +4 -0
  66. data/lib/opal/rewriters/for_rewriter.rb +1 -1
  67. data/lib/opal/rewriters/js_reserved_words.rb +7 -7
  68. data/lib/opal/rewriters/numblocks.rb +31 -0
  69. data/lib/opal/rewriters/returnable_logic.rb +33 -0
  70. data/lib/opal/version.rb +1 -1
  71. data/opal.gemspec +26 -26
  72. data/opal/corelib/array.rb +160 -118
  73. data/opal/corelib/array/pack.rb +5 -3
  74. data/opal/corelib/basic_object.rb +4 -4
  75. data/opal/corelib/class.rb +2 -1
  76. data/opal/corelib/comparable.rb +49 -31
  77. data/opal/corelib/constants.rb +5 -5
  78. data/opal/corelib/enumerable.rb +108 -46
  79. data/opal/corelib/enumerator.rb +27 -12
  80. data/opal/corelib/file.rb +3 -1
  81. data/opal/corelib/hash.rb +6 -1
  82. data/opal/corelib/helpers.rb +8 -28
  83. data/opal/corelib/io.rb +12 -7
  84. data/opal/corelib/kernel.rb +45 -14
  85. data/opal/corelib/kernel/format.rb +3 -1
  86. data/opal/corelib/math.rb +8 -6
  87. data/opal/corelib/method.rb +8 -0
  88. data/opal/corelib/module.rb +17 -2
  89. data/opal/corelib/number.rb +3 -12
  90. data/opal/corelib/proc.rb +16 -0
  91. data/opal/corelib/random/mersenne_twister.rb +147 -0
  92. data/opal/corelib/range.rb +3 -13
  93. data/opal/corelib/regexp.rb +10 -6
  94. data/opal/corelib/runtime.js +208 -81
  95. data/opal/corelib/string.rb +55 -49
  96. data/opal/corelib/string/encoding.rb +109 -32
  97. data/opal/corelib/string/unpack.rb +2 -17
  98. data/opal/corelib/struct.rb +14 -1
  99. data/opal/corelib/time.rb +4 -0
  100. data/opal/opal.rb +1 -1
  101. data/opal/opal/mini.rb +1 -1
  102. data/package.json +2 -1
  103. data/spec/README.md +10 -0
  104. data/spec/filters/bugs/array.rb +76 -0
  105. data/spec/filters/bugs/base64.rb +10 -0
  106. data/spec/filters/bugs/basicobject.rb +12 -0
  107. data/spec/filters/bugs/bigdecimal.rb +248 -0
  108. data/spec/filters/bugs/class.rb +12 -0
  109. data/spec/filters/bugs/complex.rb +7 -0
  110. data/spec/filters/bugs/date.rb +104 -0
  111. data/spec/filters/bugs/encoding.rb +259 -0
  112. data/spec/filters/bugs/enumerable.rb +26 -0
  113. data/spec/filters/bugs/enumerator.rb +48 -0
  114. data/spec/filters/bugs/exception.rb +120 -0
  115. data/spec/filters/bugs/file.rb +48 -0
  116. data/spec/filters/bugs/float.rb +74 -0
  117. data/spec/filters/bugs/hash.rb +60 -0
  118. data/spec/filters/bugs/integer.rb +78 -0
  119. data/spec/filters/bugs/io.rb +9 -0
  120. data/spec/filters/bugs/kernel.rb +401 -0
  121. data/spec/filters/bugs/language.rb +451 -0
  122. data/spec/filters/bugs/marshal.rb +50 -0
  123. data/spec/filters/bugs/math.rb +4 -0
  124. data/spec/filters/bugs/method.rb +79 -0
  125. data/spec/filters/bugs/module.rb +281 -0
  126. data/spec/filters/bugs/nilclass.rb +4 -0
  127. data/spec/filters/bugs/numeric.rb +27 -0
  128. data/spec/filters/bugs/openstruct.rb +8 -0
  129. data/spec/filters/bugs/pack_unpack.rb +138 -0
  130. data/spec/filters/bugs/pathname.rb +9 -0
  131. data/spec/filters/bugs/proc.rb +80 -0
  132. data/spec/filters/bugs/random.rb +20 -0
  133. data/spec/filters/bugs/range.rb +139 -0
  134. data/spec/filters/bugs/rational.rb +12 -0
  135. data/spec/filters/bugs/regexp.rb +91 -0
  136. data/spec/filters/bugs/set.rb +51 -0
  137. data/spec/filters/bugs/singleton.rb +7 -0
  138. data/spec/filters/bugs/string.rb +341 -0
  139. data/spec/filters/bugs/stringscanner.rb +78 -0
  140. data/spec/filters/bugs/struct.rb +26 -0
  141. data/spec/filters/bugs/symbol.rb +7 -0
  142. data/spec/filters/bugs/time.rb +109 -0
  143. data/spec/filters/bugs/unboundmethod.rb +33 -0
  144. data/spec/filters/bugs/warnings.rb +30 -0
  145. data/spec/filters/unsupported/array.rb +168 -0
  146. data/spec/filters/unsupported/basicobject.rb +15 -0
  147. data/spec/filters/unsupported/bignum.rb +55 -0
  148. data/spec/filters/unsupported/class.rb +5 -0
  149. data/spec/filters/unsupported/delegator.rb +6 -0
  150. data/spec/filters/unsupported/enumerable.rb +12 -0
  151. data/spec/filters/unsupported/enumerator.rb +14 -0
  152. data/spec/filters/unsupported/file.rb +4 -0
  153. data/spec/filters/unsupported/fixnum.rb +15 -0
  154. data/spec/filters/unsupported/float.rb +47 -0
  155. data/spec/filters/unsupported/freeze.rb +259 -0
  156. data/spec/filters/unsupported/hash.rb +44 -0
  157. data/spec/filters/unsupported/integer.rb +101 -0
  158. data/spec/filters/unsupported/kernel.rb +35 -0
  159. data/spec/filters/unsupported/language.rb +25 -0
  160. data/spec/filters/unsupported/marshal.rb +44 -0
  161. data/spec/filters/unsupported/matchdata.rb +63 -0
  162. data/spec/filters/unsupported/math.rb +4 -0
  163. data/spec/filters/unsupported/pathname.rb +4 -0
  164. data/spec/filters/unsupported/privacy.rb +287 -0
  165. data/spec/filters/unsupported/proc.rb +4 -0
  166. data/spec/filters/unsupported/random.rb +5 -0
  167. data/spec/filters/unsupported/range.rb +8 -0
  168. data/spec/filters/unsupported/regexp.rb +70 -0
  169. data/spec/filters/unsupported/set.rb +5 -0
  170. data/spec/filters/unsupported/singleton.rb +7 -0
  171. data/spec/filters/unsupported/string.rb +687 -0
  172. data/spec/filters/unsupported/struct.rb +7 -0
  173. data/spec/filters/unsupported/symbol.rb +21 -0
  174. data/spec/filters/unsupported/taint.rb +162 -0
  175. data/spec/filters/unsupported/thread.rb +10 -0
  176. data/spec/filters/unsupported/time.rb +204 -0
  177. data/spec/filters/unsupported/usage_of_files.rb +262 -0
  178. data/spec/lib/builder_processors_spec.rb +44 -0
  179. data/spec/lib/builder_spec.rb +133 -0
  180. data/spec/lib/cli_runners/server_spec.rb +25 -0
  181. data/spec/lib/cli_runners_spec.rb +16 -0
  182. data/spec/lib/cli_spec.rb +256 -0
  183. data/spec/lib/compiler_spec.rb +693 -0
  184. data/spec/lib/config_spec.rb +112 -0
  185. data/spec/lib/dependency_resolver_spec.rb +43 -0
  186. data/spec/lib/deprecations_spec.rb +17 -0
  187. data/spec/lib/fixtures/complex_sprockets.js.rb.erb +4 -0
  188. data/spec/lib/fixtures/file_with_directives.js +2 -0
  189. data/spec/lib/fixtures/jst_file.js.jst +1 -0
  190. data/spec/lib/fixtures/no_requires.rb +1 -0
  191. data/spec/lib/fixtures/opal_file.rb +2 -0
  192. data/spec/lib/fixtures/require_tree_test.rb +3 -0
  193. data/spec/lib/fixtures/required_file.js +1 -0
  194. data/spec/lib/fixtures/required_tree_test/required_file1.rb +1 -0
  195. data/spec/lib/fixtures/required_tree_test/required_file2.rb +1 -0
  196. data/spec/lib/fixtures/requires.rb +7 -0
  197. data/spec/lib/fixtures/source_location_test.rb +7 -0
  198. data/spec/lib/fixtures/source_map.rb +1 -0
  199. data/spec/lib/fixtures/source_map/subfolder/other_file.rb +1 -0
  200. data/spec/lib/fixtures/sprockets_file.js.rb +3 -0
  201. data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
  202. data/spec/lib/path_reader_spec.rb +47 -0
  203. data/spec/lib/paths_spec.rb +18 -0
  204. data/spec/lib/repl_spec.rb +28 -0
  205. data/spec/lib/rewriters/base_spec.rb +68 -0
  206. data/spec/lib/rewriters/binary_operator_assignment_spec.rb +153 -0
  207. data/spec/lib/rewriters/block_to_iter_spec.rb +28 -0
  208. data/spec/lib/rewriters/dot_js_syntax_spec.rb +108 -0
  209. data/spec/lib/rewriters/explicit_writer_return_spec.rb +186 -0
  210. data/spec/lib/rewriters/for_rewriter_spec.rb +92 -0
  211. data/spec/lib/rewriters/hashes/key_duplicates_rewriter_spec.rb +47 -0
  212. data/spec/lib/rewriters/js_reserved_words_spec.rb +119 -0
  213. data/spec/lib/rewriters/logical_operator_assignment_spec.rb +202 -0
  214. data/spec/lib/rewriters/opal_engine_check_spec.rb +84 -0
  215. data/spec/lib/rewriters/returnable_logic_spec.rb +52 -0
  216. data/spec/lib/rewriters/rubyspec/filters_rewriter_spec.rb +59 -0
  217. data/spec/lib/simple_server_spec.rb +56 -0
  218. data/spec/lib/source_map/file_spec.rb +67 -0
  219. data/spec/lib/source_map/index_spec.rb +80 -0
  220. data/spec/lib/spec_helper.rb +105 -0
  221. data/spec/mspec-opal/formatters.rb +197 -0
  222. data/spec/mspec-opal/runner.rb +172 -0
  223. data/spec/opal/compiler/irb_spec.rb +44 -0
  224. data/spec/opal/compiler/unicode_spec.rb +10 -0
  225. data/spec/opal/core/array/dup_spec.rb +23 -0
  226. data/spec/opal/core/array/intersection_spec.rb +38 -0
  227. data/spec/opal/core/array/minus_spec.rb +38 -0
  228. data/spec/opal/core/array/union_spec.rb +38 -0
  229. data/spec/opal/core/array/uniq_spec.rb +49 -0
  230. data/spec/opal/core/class/inherited_spec.rb +18 -0
  231. data/spec/opal/core/enumerable/all_break_spec.rb +5 -0
  232. data/spec/opal/core/enumerable/any_break_spec.rb +5 -0
  233. data/spec/opal/core/enumerable/collect_break_spec.rb +13 -0
  234. data/spec/opal/core/enumerable/count_break_spec.rb +5 -0
  235. data/spec/opal/core/enumerable/detect_break_spec.rb +5 -0
  236. data/spec/opal/core/enumerable/drop_while_break_spec.rb +5 -0
  237. data/spec/opal/core/enumerable/each_slice_break_spec.rb +6 -0
  238. data/spec/opal/core/enumerable/each_with_index_break_spec.rb +5 -0
  239. data/spec/opal/core/enumerable/each_with_object_break_spec.rb +5 -0
  240. data/spec/opal/core/enumerable/find_all_break_spec.rb +5 -0
  241. data/spec/opal/core/enumerable/find_index_break_spec.rb +5 -0
  242. data/spec/opal/core/enumerable/grep_break_spec.rb +5 -0
  243. data/spec/opal/core/enumerable/max_break_spec.rb +5 -0
  244. data/spec/opal/core/enumerable/max_by_break_spec.rb +5 -0
  245. data/spec/opal/core/enumerable/min_break_spec.rb +5 -0
  246. data/spec/opal/core/enumerable/min_by_break_spec.rb +5 -0
  247. data/spec/opal/core/enumerable/none_break_spec.rb +5 -0
  248. data/spec/opal/core/enumerable/one_break_spec.rb +5 -0
  249. data/spec/opal/core/enumerable/reduce_break_spec.rb +5 -0
  250. data/spec/opal/core/enumerable/take_while_break_spec.rb +5 -0
  251. data/spec/opal/core/enumerator/with_index_spec.rb +6 -0
  252. data/spec/opal/core/exception_spec.rb +8 -0
  253. data/spec/opal/core/fixtures/require_tree_files/file 1.rb +1 -0
  254. data/spec/opal/core/fixtures/require_tree_files/file 2.rb +1 -0
  255. data/spec/opal/core/fixtures/require_tree_files/file 3.rb +1 -0
  256. data/spec/opal/core/fixtures/require_tree_files/file 4.rb +1 -0
  257. data/spec/opal/core/fixtures/require_tree_files/file 5.rb +1 -0
  258. data/spec/opal/core/fixtures/require_tree_files/nested/nested 1.rb +1 -0
  259. data/spec/opal/core/fixtures/require_tree_files/nested/nested 2.rb +1 -0
  260. data/spec/opal/core/fixtures/require_tree_files/other/other 1.rb +1 -0
  261. data/spec/opal/core/fixtures/require_tree_with_dot/file 1.rb +1 -0
  262. data/spec/opal/core/fixtures/require_tree_with_dot/file 2.rb +1 -0
  263. data/spec/opal/core/fixtures/require_tree_with_dot/file 3.rb +1 -0
  264. data/spec/opal/core/fixtures/require_tree_with_dot/index.rb +3 -0
  265. data/spec/opal/core/hash/internals_spec.rb +339 -0
  266. data/spec/opal/core/helpers_spec.rb +14 -0
  267. data/spec/opal/core/iterable_props_spec.rb +53 -0
  268. data/spec/opal/core/kernel/at_exit_spec.rb +70 -0
  269. data/spec/opal/core/kernel/freeze_spec.rb +15 -0
  270. data/spec/opal/core/kernel/instance_variables_spec.rb +110 -0
  271. data/spec/opal/core/kernel/methods_spec.rb +25 -0
  272. data/spec/opal/core/kernel/public_methods_spec.rb +25 -0
  273. data/spec/opal/core/kernel/require_tree_spec.rb +18 -0
  274. data/spec/opal/core/kernel/respond_to_spec.rb +15 -0
  275. data/spec/opal/core/language/DATA/characters_support_spec.rb +9 -0
  276. data/spec/opal/core/language/DATA/empty___END___spec.rb +7 -0
  277. data/spec/opal/core/language/DATA/multiple___END___spec.rb +10 -0
  278. data/spec/opal/core/language/arguments/mlhs_arg_spec.rb +18 -0
  279. data/spec/opal/core/language/keyword_arguments_spec.rb +9 -0
  280. data/spec/opal/core/language/numblocks_spec.rb +16 -0
  281. data/spec/opal/core/language/safe_navigator_spec.rb +7 -0
  282. data/spec/opal/core/language/while_spec.rb +31 -0
  283. data/spec/opal/core/language_spec.rb +29 -0
  284. data/spec/opal/core/marshal/dump_spec.rb +81 -0
  285. data/spec/opal/core/marshal/load_spec.rb +13 -0
  286. data/spec/opal/core/module_spec.rb +27 -0
  287. data/spec/opal/core/object_id_spec.rb +56 -0
  288. data/spec/opal/core/regexp/interpolation_spec.rb +40 -0
  289. data/spec/opal/core/regexp/match_spec.rb +78 -0
  290. data/spec/opal/core/runtime/bridged_classes_spec.rb +123 -0
  291. data/spec/opal/core/runtime/constants_spec.rb +16 -0
  292. data/spec/opal/core/runtime/eval_spec.rb +5 -0
  293. data/spec/opal/core/runtime/exit_spec.rb +29 -0
  294. data/spec/opal/core/runtime/is_a_spec.rb +48 -0
  295. data/spec/opal/core/runtime/loaded_spec.rb +20 -0
  296. data/spec/opal/core/runtime/main_methods_spec.rb +39 -0
  297. data/spec/opal/core/runtime/method_missing_spec.rb +68 -0
  298. data/spec/opal/core/runtime/rescue_spec.rb +37 -0
  299. data/spec/opal/core/runtime/string_spec.rb +25 -0
  300. data/spec/opal/core/runtime/truthy_spec.rb +61 -0
  301. data/spec/opal/core/runtime_spec.rb +58 -0
  302. data/spec/opal/core/string/each_byte_spec.rb +19 -0
  303. data/spec/opal/core/string/gsub_spec.rb +35 -0
  304. data/spec/opal/core/string/to_sym_spec.rb +9 -0
  305. data/spec/opal/core/string_spec.rb +28 -0
  306. data/spec/opal/core/struct/dup_spec.rb +11 -0
  307. data/spec/opal/core/time_spec.rb +68 -0
  308. data/spec/opal/stdlib/erb/erb_spec.rb +30 -0
  309. data/spec/opal/stdlib/erb/inline_block.opalerb +3 -0
  310. data/spec/opal/stdlib/erb/quoted.opalerb +1 -0
  311. data/spec/opal/stdlib/erb/simple.opalerb +1 -0
  312. data/spec/opal/stdlib/js_spec.rb +72 -0
  313. data/spec/opal/stdlib/json/ext_spec.rb +55 -0
  314. data/spec/opal/stdlib/json/parse_spec.rb +37 -0
  315. data/spec/opal/stdlib/logger/logger_spec.rb +308 -0
  316. data/spec/opal/stdlib/native/alias_native_spec.rb +27 -0
  317. data/spec/opal/stdlib/native/array_spec.rb +11 -0
  318. data/spec/opal/stdlib/native/date_spec.rb +12 -0
  319. data/spec/opal/stdlib/native/deprecated_include_spec.rb +8 -0
  320. data/spec/opal/stdlib/native/each_spec.rb +13 -0
  321. data/spec/opal/stdlib/native/element_reference_spec.rb +16 -0
  322. data/spec/opal/stdlib/native/exposure_spec.rb +33 -0
  323. data/spec/opal/stdlib/native/ext_spec.rb +19 -0
  324. data/spec/opal/stdlib/native/hash_spec.rb +67 -0
  325. data/spec/opal/stdlib/native/initialize_spec.rb +17 -0
  326. data/spec/opal/stdlib/native/method_missing_spec.rb +51 -0
  327. data/spec/opal/stdlib/native/native_alias_spec.rb +26 -0
  328. data/spec/opal/stdlib/native/native_class_spec.rb +18 -0
  329. data/spec/opal/stdlib/native/native_module_spec.rb +13 -0
  330. data/spec/opal/stdlib/native/native_reader_spec.rb +22 -0
  331. data/spec/opal/stdlib/native/native_writer_spec.rb +30 -0
  332. data/spec/opal/stdlib/native/new_spec.rb +92 -0
  333. data/spec/opal/stdlib/native/struct_spec.rb +12 -0
  334. data/spec/opal/stdlib/pp_spec.rb +5 -0
  335. data/spec/opal/stdlib/promise/always_spec.rb +49 -0
  336. data/spec/opal/stdlib/promise/error_spec.rb +15 -0
  337. data/spec/opal/stdlib/promise/rescue_spec.rb +53 -0
  338. data/spec/opal/stdlib/promise/then_spec.rb +79 -0
  339. data/spec/opal/stdlib/promise/trace_spec.rb +51 -0
  340. data/spec/opal/stdlib/promise/value_spec.rb +15 -0
  341. data/spec/opal/stdlib/promise/when_spec.rb +34 -0
  342. data/spec/opal/stdlib/source_map_spec.rb +8 -0
  343. data/spec/opal/stdlib/strscan/scan_spec.rb +11 -0
  344. data/spec/opal/stdlib/template/paths_spec.rb +10 -0
  345. data/spec/opal/stdlib/thread/mutex_spec.rb +40 -0
  346. data/spec/opal/stdlib/thread/thread_queue_spec.rb +32 -0
  347. data/spec/opal/stdlib/thread/thread_spec.rb +60 -0
  348. data/spec/ruby_specs +183 -0
  349. data/spec/spec_helper.rb +31 -0
  350. data/spec/support/guard_platform.rb +4 -0
  351. data/spec/support/match_helpers.rb +57 -0
  352. data/spec/support/mspec_rspec_adapter.rb +33 -0
  353. data/spec/support/rewriters_helper.rb +54 -0
  354. data/spec/support/source_map_helper.rb +190 -0
  355. data/stdlib/base64.rb +2 -2
  356. data/stdlib/bigdecimal.rb +15 -3
  357. data/stdlib/bigdecimal/bignumber.js.rb +1 -1
  358. data/stdlib/bigdecimal/util.rb +148 -0
  359. data/stdlib/delegate.rb +8 -0
  360. data/stdlib/nodejs/fileutils.rb +1 -1
  361. data/stdlib/nodejs/kernel.rb +0 -13
  362. data/stdlib/nodejs/stacktrace.rb +4 -179
  363. data/stdlib/ostruct.rb +5 -0
  364. data/stdlib/pp.rb +586 -19
  365. data/stdlib/prettyprint.rb +556 -0
  366. data/stdlib/rbconfig/sizeof.rb +2 -0
  367. data/stdlib/securerandom.rb +32 -0
  368. data/stdlib/set.rb +36 -0
  369. data/stdlib/strscan.rb +15 -0
  370. data/tasks/benchmarking.rake +1 -1
  371. data/tasks/releasing.rake +0 -3
  372. data/tasks/testing.rake +16 -11
  373. data/tasks/testing/mspec_special_calls.rb +1 -19
  374. data/test/nodejs/fixtures/cat.png +0 -0
  375. data/test/nodejs/fixtures/hello.rb +1 -0
  376. data/test/nodejs/fixtures/iso88591.txt +1 -0
  377. data/test/nodejs/fixtures/utf8.txt +1 -0
  378. data/test/nodejs/fixtures/win1258.txt +1 -0
  379. data/test/nodejs/test_dir.rb +39 -0
  380. data/test/nodejs/test_env.rb +62 -0
  381. data/test/nodejs/test_error.rb +29 -0
  382. data/test/nodejs/test_file.rb +206 -0
  383. data/test/nodejs/test_file_encoding.rb +20 -0
  384. data/test/nodejs/test_io.rb +18 -0
  385. data/test/nodejs/test_opal_builder.rb +12 -0
  386. data/test/nodejs/test_pathname.rb +16 -0
  387. data/test/opal/cat.png +0 -0
  388. data/test/opal/http_server.rb +52 -0
  389. data/test/opal/test_base64.rb +115 -0
  390. data/test/opal/test_keyword.rb +590 -0
  391. data/test/opal/test_matrix.rb +661 -0
  392. data/test/opal/test_openuri.rb +53 -0
  393. data/test/opal/unsupported_and_bugs.rb +39 -0
  394. data/yarn.lock +1114 -3
  395. metadata +893 -33
  396. data/lib/opal/nodes/runtime_helpers.rb +0 -51
  397. data/opal/corelib/random/MersenneTwister.js +0 -137
  398. data/opal/corelib/random/mersenne_twister.js.rb +0 -13
  399. data/stdlib/bigdecimal/kernel.rb +0 -5
@@ -0,0 +1,27 @@
1
+ require 'native'
2
+
3
+ describe "Native.alias_native" do
4
+ it "refers to an attribute on @native" do
5
+ Class.new {
6
+ include Native::Wrapper
7
+
8
+ alias_native :a, :a
9
+ }.new(`{ a: 2 }`).a.should == 2
10
+ end
11
+
12
+ it "refers to an attribute on @native and calls it if it's a function" do
13
+ Class.new {
14
+ include Native::Wrapper
15
+
16
+ alias_native :a, :a
17
+ }.new(`{ a: function() { return 42; } }`).a.should == 42
18
+ end
19
+
20
+ it "defaults old to new" do
21
+ Class.new {
22
+ include Native::Wrapper
23
+
24
+ alias_native :a
25
+ }.new(`{ a: 42 }`).a.should == 42
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ require 'native'
2
+
3
+ describe Array do
4
+ describe '#to_n' do
5
+ it 'converts an array with native objects to a JS array' do
6
+ obj = [`{ key: 1 }`]
7
+ native = obj.to_n
8
+ `#{native}[0].key`.should == 1
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'native'
2
+ require 'date'
3
+
4
+ describe Date do
5
+ describe '#to_n' do
6
+ it 'returns native JS date object' do
7
+ date = Date.new(1984, 1, 24)
8
+ native = date.to_n
9
+ expect(`#{native}.toDateString()`).to eq 'Tue Jan 24 1984'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ require 'native'
2
+
3
+ describe "Native inclusion" do
4
+ it "is deprecated" do
5
+ Native.should_receive(:warn).with("Including ::Native is deprecated. Please include Native::Wrapper instead.")
6
+ Class.new { include Native }
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ require 'native'
2
+
3
+ describe "Native::Object#each" do
4
+ it "enumerates on object properties" do
5
+ Native(`{ a: 2, b: 3 }`).each {|name, value|
6
+ ((name == :a && value == 2) || (name == :b && value == 3)).should be_true
7
+ }
8
+ end
9
+
10
+ it "accesses the native when no block is given" do
11
+ Native(`{ a: 2, b: 3, each: function() { return 42; } }`).each.should == 42
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ require 'native'
2
+
3
+ describe "Native::Object#[]" do
4
+ it "should return the same value for bridged classes" do
5
+ Native(`2`).should === 2
6
+ Native(`"lol"`).should === "lol"
7
+ end
8
+
9
+ it "should return functions as is" do
10
+ Native(`{ a: function(){} }`)[:a].should be_kind_of Proc
11
+ end
12
+
13
+ it "should wrap natives into a Native object" do
14
+ Native(`{ a: { b: 2 } }`)[:a][:b].should == 2
15
+ end
16
+ end
@@ -0,0 +1,33 @@
1
+ require 'native'
2
+
3
+ describe 'Native exposure' do
4
+ describe Class do
5
+ describe '#native_alias' do
6
+ it 'exposes a method to javascript' do
7
+ c = Class.new do
8
+ def ruby_method
9
+ :ruby
10
+ end
11
+
12
+ native_alias :rubyMethod, :ruby_method
13
+ end
14
+
15
+ `#{c.new}.rubyMethod()`.should == :ruby
16
+ end
17
+ end
18
+
19
+ describe '#native_class' do
20
+ it 'exposes a Class on the JS global object' do
21
+ c = Class.new do
22
+ def self.name
23
+ 'Pippo'
24
+ end
25
+
26
+ native_class
27
+ end
28
+
29
+ `Pippo`.should == c
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ require 'native'
2
+
3
+ describe Hash do
4
+ describe '#initialize' do
5
+ it "returns a hash with a nil value" do
6
+ h = Hash.new(`{a: null}`)
7
+ h[:a].should == nil
8
+ end
9
+ end
10
+
11
+ describe '#to_n' do
12
+ it "should return a js object representing hash" do
13
+ Hash.new({:a => 100, :b => 200}.to_n).should == {:a => 100, :b => 200}
14
+ end
15
+ end
16
+ end
17
+
18
+ describe "Hash#to_n" do
19
+ end
@@ -0,0 +1,67 @@
1
+ require 'native'
2
+
3
+ describe Hash do
4
+ it 'turns a native JS object into a hash' do
5
+ obj = %x{
6
+ {
7
+ a: 1,
8
+ b: "two",
9
+ c: {
10
+ d: 1,
11
+ },
12
+ e: [
13
+ {
14
+ f: 'g',
15
+ h: [null],
16
+ },
17
+ ],
18
+ }
19
+ }
20
+
21
+ h = Hash.new(obj)
22
+ expected_hash = {
23
+ a: 1,
24
+ b: "two",
25
+ c: {
26
+ d: 1,
27
+ },
28
+ e: [
29
+ {
30
+ f: 'g',
31
+ h: [nil],
32
+ },
33
+ ],
34
+ }
35
+
36
+ expect(h).to eq(expected_hash)
37
+ end
38
+
39
+ it 'turns Object.create(null) JS objects into a hash' do
40
+ %x{
41
+ var obj = Object.create(null);
42
+ var foo = Object.create(null);
43
+ var bar = Object.create(null);
44
+ obj.foo = foo;
45
+ foo.bar = bar;
46
+ bar.baz = 'baz';
47
+ }
48
+ hash = Hash.new(`obj`)
49
+
50
+ expect(hash).to eq({ foo: { bar: { baz: 'baz' } } })
51
+ end
52
+
53
+ describe '#to_n' do
54
+ it 'converts a hash with native objects as values' do
55
+ obj = { 'a_key' => `{ key: 1 }` }
56
+ native = obj.to_n
57
+ `#{native}.a_key.key`.should == 1
58
+ end
59
+
60
+ it 'passes Ruby objects that cannot be converted' do
61
+ object = Object.new
62
+ hash = { foo: object }
63
+ native = hash.to_n
64
+ expect(`#{native}.foo`).to eq object
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,17 @@
1
+ require 'native'
2
+
3
+ describe "Native#initialize" do
4
+ it "works when Native is included in a BasicObject" do
5
+ basic_class = Class.new(BasicObject)
6
+ basic_object = basic_class.new
7
+ lambda { basic_object.native? }.should raise_error(NoMethodError)
8
+
9
+ basic_class.send :include, Native
10
+ lambda { basic_class.new(`{}`) }.should_not raise_error
11
+ end
12
+
13
+ it "detects a non native object" do
14
+ object = Object.new
15
+ lambda { Native::Object.new(object) }.should raise_error(ArgumentError)
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ require 'native'
2
+
3
+ describe "Native::Object#method_missing" do
4
+ it "should return values" do
5
+ Native(`{ a: 23 }`).a.should == 23
6
+ Native(`{ a: { b: 42 } }`).a.b.should == 42
7
+ end
8
+
9
+ it "should call functions" do
10
+ Native(`{ a: function() { return 42 } }`).a.should == 42
11
+ end
12
+
13
+ it "should pass the proper this to functions" do
14
+ %x{
15
+ function foo() {
16
+ this.baz = 42;
17
+ }
18
+
19
+ foo.prototype.bar = function () {
20
+ return this.baz;
21
+ }
22
+ }
23
+
24
+ obj = `new foo()`
25
+ Native(obj).bar.should == 42
26
+ Native(obj).baz = 23
27
+ Native(obj).bar.should == 23
28
+ end
29
+
30
+ it "should set values" do
31
+ var = `{}`
32
+
33
+ Native(var).a = 42
34
+ `#{var}.a`.should == 42
35
+ Native(var).a.should == 42
36
+ end
37
+
38
+ it "should pass the block as function" do
39
+ Native(`{ a: function(func) { return func(); } }`).a { 42 }.should == 42
40
+ end
41
+
42
+ it "should unwrap arguments" do
43
+ x = `{}`
44
+
45
+ Native(`{ a: function(a, b) { return a === b } }`).a(Native(x), x).should == true
46
+ end
47
+
48
+ it "should wrap result" do
49
+ Native(`{ a: function() { return {}; } }`).a.class.should == Native::Object
50
+ end
51
+ end
@@ -0,0 +1,26 @@
1
+ require 'native'
2
+
3
+ describe "Class#native_alias" do
4
+ it "exposes a method to javascript without the '$' prefix" do
5
+ klass = Class.new {
6
+ def a
7
+ 2
8
+ end
9
+
10
+ native_alias :a, :a
11
+ }
12
+ instance = klass.new
13
+ `instance.a()`.should == 2
14
+ end
15
+
16
+ it "raises if the aliased method isn't defined" do
17
+ Class.new do
18
+ lambda {
19
+ native_alias :a, :not_a_method
20
+ }.should raise_error(
21
+ NameError,
22
+ %r{undefined method `not_a_method' for class `#<Class:0x\w+>'}
23
+ )
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ require 'native'
2
+
3
+ describe "Class#native_class" do
4
+ class SomeClass
5
+ end
6
+
7
+ after {`delete Opal.global.SomeClass`}
8
+
9
+ it "adds current constant to the global JS object" do
10
+ SomeClass.native_class
11
+ `Opal.global.SomeClass`.should == SomeClass
12
+ end
13
+
14
+ it 'aliases Class#new to the unprefixed new method in JS world' do
15
+ SomeClass.native_class
16
+ `Opal.global.SomeClass["new"]()`.is_a?(SomeClass).should == true
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ require 'native'
2
+
3
+ describe "Module#native_module" do
4
+ module SomeModule
5
+ end
6
+
7
+ after {`delete Opal.global.SomeModule`}
8
+
9
+ it "adds current constant to the global JS object" do
10
+ SomeModule.native_module
11
+ `Opal.global.SomeModule`.should == SomeModule
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ require 'native'
2
+
3
+ describe "Native.native_reader" do
4
+ it "refers to an attribute on @native" do
5
+ Class.new {
6
+ include Native::Wrapper
7
+
8
+ native_reader :a
9
+ }.new(`{ a: 2 }`).a.should == 2
10
+ end
11
+
12
+ it "uses multiple names" do
13
+ n = Class.new {
14
+ include Native::Wrapper
15
+
16
+ native_reader :a, :b
17
+ }.new(`{ a: 2, b: 3 }`)
18
+
19
+ n.a.should == 2
20
+ n.b.should == 3
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ require 'native'
2
+
3
+ describe "Native.native_writer" do
4
+ it "refers to an attribute on @native" do
5
+ n = Class.new {
6
+ include Native::Wrapper
7
+
8
+ native_reader :a
9
+ native_writer :a
10
+ }.new(`{ a: 2 }`)
11
+
12
+ n.a = 4
13
+ n.a.should == 4
14
+ end
15
+
16
+ it "supports multiple names" do
17
+ n = Class.new {
18
+ include Native::Wrapper
19
+
20
+ native_reader :a, :b
21
+ native_writer :a, :b
22
+ }.new(`{ a: 2, b: 3 }`)
23
+
24
+ n.a = 4
25
+ n.b = 5
26
+
27
+ n.a.should == 4
28
+ n.b.should == 5
29
+ end
30
+ end
@@ -0,0 +1,92 @@
1
+ require 'native'
2
+
3
+ describe "Native()" do
4
+ it "should return nil for null or undefined" do
5
+ Native(`null`).should be_nil
6
+ Native(`undefined`).should be_nil
7
+ end
8
+
9
+ it "should return String" do
10
+ Native(`""`).should be_an_instance_of String
11
+ end
12
+
13
+ it "should return Integer" do
14
+ Native(`0`).should be_an_instance_of Number
15
+ end
16
+
17
+ it "should return Float" do
18
+ Native(`0.01`).should be_an_instance_of Float
19
+ end
20
+
21
+ it "should return Array" do
22
+ Native(`[]`).should be_an_instance_of Array
23
+ end
24
+
25
+ it "should return Native::Object" do
26
+ Native(`{}`).instance_of?(Native::Object).should be_true
27
+ end
28
+
29
+ it "should return Array of String" do
30
+ Native(`[""]`).first.should be_an_instance_of String
31
+ end
32
+
33
+ it "should return Array of Integer" do
34
+ Native(`[0]`).first.should be_an_instance_of Number
35
+ end
36
+
37
+ it "should return Array of Float" do
38
+ Native(`[0.01]`).first.should be_an_instance_of Float
39
+ end
40
+
41
+ it "should return Array of Array" do
42
+ Native(`[[]]`).first.should be_an_instance_of Array
43
+ end
44
+
45
+ it "should return Array of Native::Object" do
46
+ Native(`[{}]`).first.instance_of?(Native::Object).should be_true
47
+ end
48
+
49
+ it "should return Object with String" do
50
+ Native(`{"key": ""}`)["key"].should be_an_instance_of String
51
+ end
52
+
53
+ it "should return Object with Integer" do
54
+ Native(`{"key": 0}`)["key"].should be_an_instance_of Number
55
+ end
56
+
57
+ it "should return Object with Float" do
58
+ Native(`{"key": 0.01}`)["key"].should be_an_instance_of Float
59
+ end
60
+
61
+ it "should return Object with Array" do
62
+ Native(`{"key": []}`)["key"].should be_an_instance_of Array
63
+ end
64
+
65
+ it "should return Native::Object with Native::Object" do
66
+ Native(`{"key": {}}`)["key"].instance_of?(Native::Object).should be_true
67
+ end
68
+
69
+ it "should return Proc" do
70
+ Native(`function(){}`).should be_an_instance_of Proc
71
+ end
72
+
73
+ it "should return Proc that return String" do
74
+ Native(`function(){return ""}`).call.should be_an_instance_of String
75
+ end
76
+
77
+ it "should return Proc that return Integer" do
78
+ Native(`function(){return 0}`).call.should be_an_instance_of Integer
79
+ end
80
+
81
+ it "should return Proc that return Float" do
82
+ Native(`function(){return 0.01}`).call.should be_an_instance_of Float
83
+ end
84
+
85
+ it "should return Proc that return Array" do
86
+ Native(`function(){return []}`).call.should be_an_instance_of Array
87
+ end
88
+
89
+ it "should return Proc that return Native::Object" do
90
+ Native(`function(){return {}}`).call.instance_of?(Native::Object).should be_true
91
+ end
92
+ end