opal 1.0.3 → 1.1.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +13 -12
- data/.gitattributes +1 -1
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/build.yml +90 -0
- data/.jshintrc +1 -1
- data/.overcommit.yml +35 -0
- data/.rubocop.yml +44 -7
- data/{.rubocop_todo.yml → .rubocop/todo.yml} +4 -5
- data/CHANGELOG.md +152 -1
- data/Gemfile +2 -3
- data/HACKING.md +2 -9
- data/LICENSE +1 -1
- data/README.md +21 -18
- data/UNRELEASED.md +4 -2
- data/benchmark-ips/bm_array_pop_1.rb +8 -0
- data/benchmark-ips/bm_array_shift.rb +7 -0
- data/benchmark-ips/bm_js_symbols_vs_strings.rb +7 -2
- data/benchmark-ips/class_shovel_vs_singleton_class.rb +16 -0
- data/bin/build-browser-source-map-support +4 -0
- data/bin/format-filters +54 -0
- data/bin/git-submodule-fast-install +49 -0
- data/bin/remove-filters +39 -0
- data/bin/setup +4 -0
- data/bin/yarn +11 -0
- data/docs/releasing.md +18 -0
- data/docs/roda-sprockets.md +86 -0
- data/docs/sinatra.md +5 -12
- data/examples/rack/Gemfile +1 -0
- data/examples/rack/app/application.rb +3 -0
- data/examples/rack/config.ru +5 -4
- data/exe/opal-repl +2 -83
- data/lib/opal/ast/builder.rb +1 -1
- data/lib/opal/builder.rb +2 -10
- data/lib/opal/builder_processors.rb +1 -1
- data/lib/opal/cli.rb +4 -1
- data/lib/opal/cli_options.rb +11 -3
- data/lib/opal/cli_runners.rb +27 -37
- data/lib/opal/cli_runners/applescript.rb +5 -44
- data/lib/opal/cli_runners/chrome.js +7 -35
- data/lib/opal/cli_runners/chrome.rb +75 -17
- data/lib/opal/cli_runners/compiler.rb +17 -0
- data/lib/opal/cli_runners/nashorn.rb +9 -43
- data/lib/opal/cli_runners/nodejs.rb +18 -47
- data/lib/opal/cli_runners/server.rb +18 -6
- data/lib/opal/cli_runners/source-map-support-browser.js +6449 -0
- data/lib/opal/cli_runners/source-map-support-node.js +3704 -0
- data/lib/opal/cli_runners/source-map-support.js +639 -0
- data/lib/opal/cli_runners/system_runner.rb +45 -0
- data/lib/opal/compiler.rb +57 -29
- data/lib/opal/config.rb +0 -5
- data/lib/opal/erb.rb +1 -1
- data/lib/opal/magic_comments.rb +34 -0
- data/lib/opal/nodes/args/arity_check.rb +2 -1
- data/lib/opal/nodes/base.rb +1 -1
- data/lib/opal/nodes/call.rb +1 -4
- data/lib/opal/nodes/def.rb +2 -0
- data/lib/opal/nodes/iter.rb +1 -1
- data/lib/opal/nodes/literal.rb +19 -14
- data/lib/opal/nodes/logic.rb +5 -80
- data/lib/opal/nodes/masgn.rb +2 -0
- data/lib/opal/nodes/rescue.rb +1 -1
- data/lib/opal/nodes/super.rb +24 -10
- data/lib/opal/nodes/top.rb +5 -4
- data/lib/opal/parser/with_c_lexer.rb +2 -1
- data/lib/opal/parser/with_ruby_lexer.rb +1 -1
- data/lib/opal/path_reader.rb +2 -2
- data/lib/opal/paths.rb +8 -5
- data/lib/opal/repl.rb +103 -0
- data/lib/opal/rewriter.rb +4 -0
- data/lib/opal/rewriters/for_rewriter.rb +1 -1
- data/lib/opal/rewriters/js_reserved_words.rb +7 -7
- data/lib/opal/rewriters/numblocks.rb +31 -0
- data/lib/opal/rewriters/returnable_logic.rb +33 -0
- data/lib/opal/util.rb +11 -48
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +26 -26
- data/opal/corelib/array.rb +160 -118
- data/opal/corelib/array/pack.rb +5 -3
- data/opal/corelib/basic_object.rb +4 -4
- data/opal/corelib/class.rb +2 -1
- data/opal/corelib/comparable.rb +49 -31
- data/opal/corelib/constants.rb +5 -5
- data/opal/corelib/enumerable.rb +108 -46
- data/opal/corelib/enumerator.rb +27 -12
- data/opal/corelib/file.rb +3 -1
- data/opal/corelib/hash.rb +6 -1
- data/opal/corelib/helpers.rb +8 -28
- data/opal/corelib/io.rb +12 -7
- data/opal/corelib/kernel.rb +45 -14
- data/opal/corelib/kernel/format.rb +3 -1
- data/opal/corelib/math.rb +8 -6
- data/opal/corelib/method.rb +8 -0
- data/opal/corelib/module.rb +17 -2
- data/opal/corelib/number.rb +3 -12
- data/opal/corelib/proc.rb +16 -0
- data/opal/corelib/random/mersenne_twister.rb +147 -0
- data/opal/corelib/range.rb +3 -13
- data/opal/corelib/regexp.rb +10 -6
- data/opal/corelib/runtime.js +208 -81
- data/opal/corelib/string.rb +55 -49
- data/opal/corelib/string/encoding.rb +109 -32
- data/opal/corelib/string/unpack.rb +2 -17
- data/opal/corelib/struct.rb +14 -1
- data/opal/corelib/time.rb +4 -0
- data/opal/opal.rb +1 -1
- data/opal/opal/mini.rb +1 -1
- data/package.json +16 -0
- data/spec/README.md +10 -0
- data/spec/filters/bugs/array.rb +76 -0
- data/spec/filters/bugs/base64.rb +10 -0
- data/spec/filters/bugs/basicobject.rb +12 -0
- data/spec/filters/bugs/bigdecimal.rb +248 -0
- data/spec/filters/bugs/class.rb +12 -0
- data/spec/filters/bugs/complex.rb +7 -0
- data/spec/filters/bugs/date.rb +104 -0
- data/spec/filters/bugs/encoding.rb +259 -0
- data/spec/filters/bugs/enumerable.rb +26 -0
- data/spec/filters/bugs/enumerator.rb +48 -0
- data/spec/filters/bugs/exception.rb +120 -0
- data/spec/filters/bugs/file.rb +48 -0
- data/spec/filters/bugs/float.rb +74 -0
- data/spec/filters/bugs/hash.rb +60 -0
- data/spec/filters/bugs/integer.rb +78 -0
- data/spec/filters/bugs/io.rb +9 -0
- data/spec/filters/bugs/kernel.rb +401 -0
- data/spec/filters/bugs/language.rb +451 -0
- data/spec/filters/bugs/marshal.rb +50 -0
- data/spec/filters/bugs/math.rb +4 -0
- data/spec/filters/bugs/method.rb +79 -0
- data/spec/filters/bugs/module.rb +281 -0
- data/spec/filters/bugs/nilclass.rb +4 -0
- data/spec/filters/bugs/numeric.rb +27 -0
- data/spec/filters/bugs/openstruct.rb +8 -0
- data/spec/filters/bugs/pack_unpack.rb +138 -0
- data/spec/filters/bugs/pathname.rb +9 -0
- data/spec/filters/bugs/proc.rb +80 -0
- data/spec/filters/bugs/random.rb +20 -0
- data/spec/filters/bugs/range.rb +139 -0
- data/spec/filters/bugs/rational.rb +12 -0
- data/spec/filters/bugs/regexp.rb +91 -0
- data/spec/filters/bugs/set.rb +51 -0
- data/spec/filters/bugs/singleton.rb +7 -0
- data/spec/filters/bugs/string.rb +341 -0
- data/spec/filters/bugs/stringscanner.rb +78 -0
- data/spec/filters/bugs/struct.rb +26 -0
- data/spec/filters/bugs/symbol.rb +7 -0
- data/spec/filters/bugs/time.rb +109 -0
- data/spec/filters/bugs/unboundmethod.rb +33 -0
- data/spec/filters/bugs/warnings.rb +30 -0
- data/spec/filters/unsupported/array.rb +168 -0
- data/spec/filters/unsupported/basicobject.rb +15 -0
- data/spec/filters/unsupported/bignum.rb +55 -0
- data/spec/filters/unsupported/class.rb +5 -0
- data/spec/filters/unsupported/delegator.rb +6 -0
- data/spec/filters/unsupported/enumerable.rb +12 -0
- data/spec/filters/unsupported/enumerator.rb +14 -0
- data/spec/filters/unsupported/file.rb +4 -0
- data/spec/filters/unsupported/fixnum.rb +15 -0
- data/spec/filters/unsupported/float.rb +47 -0
- data/spec/filters/unsupported/freeze.rb +259 -0
- data/spec/filters/unsupported/hash.rb +44 -0
- data/spec/filters/unsupported/integer.rb +101 -0
- data/spec/filters/unsupported/kernel.rb +35 -0
- data/spec/filters/unsupported/language.rb +25 -0
- data/spec/filters/unsupported/marshal.rb +44 -0
- data/spec/filters/unsupported/matchdata.rb +63 -0
- data/spec/filters/unsupported/math.rb +4 -0
- data/spec/filters/unsupported/pathname.rb +4 -0
- data/spec/filters/unsupported/privacy.rb +287 -0
- data/spec/filters/unsupported/proc.rb +4 -0
- data/spec/filters/unsupported/random.rb +5 -0
- data/spec/filters/unsupported/range.rb +8 -0
- data/spec/filters/unsupported/regexp.rb +70 -0
- data/spec/filters/unsupported/set.rb +5 -0
- data/spec/filters/unsupported/singleton.rb +7 -0
- data/spec/filters/unsupported/string.rb +687 -0
- data/spec/filters/unsupported/struct.rb +7 -0
- data/spec/filters/unsupported/symbol.rb +21 -0
- data/spec/filters/unsupported/taint.rb +162 -0
- data/spec/filters/unsupported/thread.rb +10 -0
- data/spec/filters/unsupported/time.rb +204 -0
- data/spec/filters/unsupported/usage_of_files.rb +262 -0
- data/spec/lib/builder_processors_spec.rb +44 -0
- data/spec/lib/builder_spec.rb +133 -0
- data/spec/lib/cli_runners/server_spec.rb +25 -0
- data/spec/lib/cli_runners_spec.rb +16 -0
- data/spec/lib/cli_spec.rb +256 -0
- data/spec/lib/compiler_spec.rb +693 -0
- data/spec/lib/config_spec.rb +112 -0
- data/spec/lib/dependency_resolver_spec.rb +43 -0
- data/spec/lib/deprecations_spec.rb +17 -0
- data/spec/lib/fixtures/complex_sprockets.js.rb.erb +4 -0
- data/spec/lib/fixtures/file_with_directives.js +2 -0
- data/spec/lib/fixtures/jst_file.js.jst +1 -0
- data/spec/lib/fixtures/no_requires.rb +1 -0
- data/spec/lib/fixtures/opal_file.rb +2 -0
- data/spec/lib/fixtures/require_tree_test.rb +3 -0
- data/spec/lib/fixtures/required_file.js +1 -0
- data/spec/lib/fixtures/required_tree_test/required_file1.rb +1 -0
- data/spec/lib/fixtures/required_tree_test/required_file2.rb +1 -0
- data/spec/lib/fixtures/requires.rb +7 -0
- data/spec/lib/fixtures/source_location_test.rb +7 -0
- data/spec/lib/fixtures/source_map.rb +1 -0
- data/spec/lib/fixtures/source_map/subfolder/other_file.rb +1 -0
- data/spec/lib/fixtures/sprockets_file.js.rb +3 -0
- data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
- data/spec/lib/path_reader_spec.rb +47 -0
- data/spec/lib/paths_spec.rb +18 -0
- data/spec/lib/repl_spec.rb +28 -0
- data/spec/lib/rewriters/base_spec.rb +68 -0
- data/spec/lib/rewriters/binary_operator_assignment_spec.rb +153 -0
- data/spec/lib/rewriters/block_to_iter_spec.rb +28 -0
- data/spec/lib/rewriters/dot_js_syntax_spec.rb +108 -0
- data/spec/lib/rewriters/explicit_writer_return_spec.rb +186 -0
- data/spec/lib/rewriters/for_rewriter_spec.rb +92 -0
- data/spec/lib/rewriters/hashes/key_duplicates_rewriter_spec.rb +47 -0
- data/spec/lib/rewriters/js_reserved_words_spec.rb +119 -0
- data/spec/lib/rewriters/logical_operator_assignment_spec.rb +202 -0
- data/spec/lib/rewriters/opal_engine_check_spec.rb +84 -0
- data/spec/lib/rewriters/returnable_logic_spec.rb +52 -0
- data/spec/lib/rewriters/rubyspec/filters_rewriter_spec.rb +59 -0
- data/spec/lib/simple_server_spec.rb +56 -0
- data/spec/lib/source_map/file_spec.rb +67 -0
- data/spec/lib/source_map/index_spec.rb +80 -0
- data/spec/lib/spec_helper.rb +105 -0
- data/spec/mspec-opal/formatters.rb +197 -0
- data/spec/mspec-opal/runner.rb +172 -0
- data/spec/opal/compiler/irb_spec.rb +44 -0
- data/spec/opal/compiler/unicode_spec.rb +10 -0
- data/spec/opal/core/array/dup_spec.rb +23 -0
- data/spec/opal/core/array/intersection_spec.rb +38 -0
- data/spec/opal/core/array/minus_spec.rb +38 -0
- data/spec/opal/core/array/union_spec.rb +38 -0
- data/spec/opal/core/array/uniq_spec.rb +49 -0
- data/spec/opal/core/class/inherited_spec.rb +18 -0
- data/spec/opal/core/enumerable/all_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/any_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/collect_break_spec.rb +13 -0
- data/spec/opal/core/enumerable/count_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/detect_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/drop_while_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/each_slice_break_spec.rb +6 -0
- data/spec/opal/core/enumerable/each_with_index_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/each_with_object_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/find_all_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/find_index_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/grep_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/max_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/max_by_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/min_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/min_by_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/none_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/one_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/reduce_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/take_while_break_spec.rb +5 -0
- data/spec/opal/core/enumerator/with_index_spec.rb +6 -0
- data/spec/opal/core/exception_spec.rb +8 -0
- data/spec/opal/core/fixtures/require_tree_files/file 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 3.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 4.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 5.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/nested/nested 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/nested/nested 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/other/other 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 3.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/index.rb +3 -0
- data/spec/opal/core/hash/internals_spec.rb +339 -0
- data/spec/opal/core/helpers_spec.rb +14 -0
- data/spec/opal/core/iterable_props_spec.rb +53 -0
- data/spec/opal/core/kernel/at_exit_spec.rb +70 -0
- data/spec/opal/core/kernel/freeze_spec.rb +15 -0
- data/spec/opal/core/kernel/instance_variables_spec.rb +110 -0
- data/spec/opal/core/kernel/methods_spec.rb +25 -0
- data/spec/opal/core/kernel/public_methods_spec.rb +25 -0
- data/spec/opal/core/kernel/require_tree_spec.rb +18 -0
- data/spec/opal/core/kernel/respond_to_spec.rb +15 -0
- data/spec/opal/core/language/DATA/characters_support_spec.rb +9 -0
- data/spec/opal/core/language/DATA/empty___END___spec.rb +7 -0
- data/spec/opal/core/language/DATA/multiple___END___spec.rb +10 -0
- data/spec/opal/core/language/arguments/mlhs_arg_spec.rb +18 -0
- data/spec/opal/core/language/keyword_arguments_spec.rb +9 -0
- data/spec/opal/core/language/numblocks_spec.rb +16 -0
- data/spec/opal/core/language/safe_navigator_spec.rb +7 -0
- data/spec/opal/core/language/while_spec.rb +31 -0
- data/spec/opal/core/language_spec.rb +29 -0
- data/spec/opal/core/marshal/dump_spec.rb +81 -0
- data/spec/opal/core/marshal/load_spec.rb +13 -0
- data/spec/opal/core/module_spec.rb +27 -0
- data/spec/opal/core/object_id_spec.rb +56 -0
- data/spec/opal/core/regexp/interpolation_spec.rb +40 -0
- data/spec/opal/core/regexp/match_spec.rb +78 -0
- data/spec/opal/core/runtime/bridged_classes_spec.rb +123 -0
- data/spec/opal/core/runtime/constants_spec.rb +16 -0
- data/spec/opal/core/runtime/eval_spec.rb +5 -0
- data/spec/opal/core/runtime/exit_spec.rb +29 -0
- data/spec/opal/core/runtime/is_a_spec.rb +48 -0
- data/spec/opal/core/runtime/loaded_spec.rb +20 -0
- data/spec/opal/core/runtime/main_methods_spec.rb +39 -0
- data/spec/opal/core/runtime/method_missing_spec.rb +68 -0
- data/spec/opal/core/runtime/rescue_spec.rb +37 -0
- data/spec/opal/core/runtime/string_spec.rb +25 -0
- data/spec/opal/core/runtime/truthy_spec.rb +61 -0
- data/spec/opal/core/runtime_spec.rb +58 -0
- data/spec/opal/core/string/each_byte_spec.rb +19 -0
- data/spec/opal/core/string/gsub_spec.rb +35 -0
- data/spec/opal/core/string/to_sym_spec.rb +9 -0
- data/spec/opal/core/string_spec.rb +28 -0
- data/spec/opal/core/struct/dup_spec.rb +11 -0
- data/spec/opal/core/time_spec.rb +68 -0
- data/spec/opal/stdlib/erb/erb_spec.rb +30 -0
- data/spec/opal/stdlib/erb/inline_block.opalerb +3 -0
- data/spec/opal/stdlib/erb/quoted.opalerb +1 -0
- data/spec/opal/stdlib/erb/simple.opalerb +1 -0
- data/spec/opal/stdlib/js_spec.rb +72 -0
- data/spec/opal/stdlib/json/ext_spec.rb +55 -0
- data/spec/opal/stdlib/json/parse_spec.rb +37 -0
- data/spec/opal/stdlib/logger/logger_spec.rb +308 -0
- data/spec/opal/stdlib/native/alias_native_spec.rb +27 -0
- data/spec/opal/stdlib/native/array_spec.rb +11 -0
- data/spec/opal/stdlib/native/date_spec.rb +12 -0
- data/spec/opal/stdlib/native/deprecated_include_spec.rb +8 -0
- data/spec/opal/stdlib/native/each_spec.rb +13 -0
- data/spec/opal/stdlib/native/element_reference_spec.rb +16 -0
- data/spec/opal/stdlib/native/exposure_spec.rb +33 -0
- data/spec/opal/stdlib/native/ext_spec.rb +19 -0
- data/spec/opal/stdlib/native/hash_spec.rb +67 -0
- data/spec/opal/stdlib/native/initialize_spec.rb +17 -0
- data/spec/opal/stdlib/native/method_missing_spec.rb +51 -0
- data/spec/opal/stdlib/native/native_alias_spec.rb +26 -0
- data/spec/opal/stdlib/native/native_class_spec.rb +18 -0
- data/spec/opal/stdlib/native/native_module_spec.rb +13 -0
- data/spec/opal/stdlib/native/native_reader_spec.rb +22 -0
- data/spec/opal/stdlib/native/native_writer_spec.rb +30 -0
- data/spec/opal/stdlib/native/new_spec.rb +92 -0
- data/spec/opal/stdlib/native/struct_spec.rb +12 -0
- data/spec/opal/stdlib/pp_spec.rb +5 -0
- data/spec/opal/stdlib/promise/always_spec.rb +49 -0
- data/spec/opal/stdlib/promise/error_spec.rb +15 -0
- data/spec/opal/stdlib/promise/rescue_spec.rb +53 -0
- data/spec/opal/stdlib/promise/then_spec.rb +79 -0
- data/spec/opal/stdlib/promise/trace_spec.rb +51 -0
- data/spec/opal/stdlib/promise/value_spec.rb +15 -0
- data/spec/opal/stdlib/promise/when_spec.rb +34 -0
- data/spec/opal/stdlib/source_map_spec.rb +8 -0
- data/spec/opal/stdlib/strscan/scan_spec.rb +11 -0
- data/spec/opal/stdlib/template/paths_spec.rb +10 -0
- data/spec/opal/stdlib/thread/mutex_spec.rb +40 -0
- data/spec/opal/stdlib/thread/thread_queue_spec.rb +32 -0
- data/spec/opal/stdlib/thread/thread_spec.rb +60 -0
- data/spec/ruby_specs +183 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/guard_platform.rb +4 -0
- data/spec/support/match_helpers.rb +57 -0
- data/spec/support/mspec_rspec_adapter.rb +33 -0
- data/spec/support/rewriters_helper.rb +54 -0
- data/spec/support/source_map_helper.rb +190 -0
- data/stdlib/base64.rb +2 -2
- data/stdlib/bigdecimal.rb +15 -3
- data/stdlib/bigdecimal/bignumber.js.rb +1 -1
- data/stdlib/bigdecimal/util.rb +148 -0
- data/stdlib/delegate.rb +8 -0
- data/stdlib/nodejs/fileutils.rb +1 -1
- data/stdlib/nodejs/kernel.rb +0 -13
- data/stdlib/nodejs/stacktrace.rb +4 -179
- data/stdlib/ostruct.rb +5 -0
- data/stdlib/pp.rb +586 -19
- data/stdlib/prettyprint.rb +556 -0
- data/stdlib/rbconfig/sizeof.rb +2 -0
- data/stdlib/securerandom.rb +32 -0
- data/stdlib/set.rb +36 -0
- data/stdlib/strscan.rb +15 -0
- data/tasks/benchmarking.rake +1 -1
- data/tasks/linting.rake +3 -5
- data/tasks/releasing.rake +2 -5
- data/tasks/testing.rake +16 -11
- data/tasks/testing/mspec_special_calls.rb +1 -19
- data/test/nodejs/fixtures/cat.png +0 -0
- data/test/nodejs/fixtures/hello.rb +1 -0
- data/test/nodejs/fixtures/iso88591.txt +1 -0
- data/test/nodejs/fixtures/utf8.txt +1 -0
- data/test/nodejs/fixtures/win1258.txt +1 -0
- data/test/nodejs/test_dir.rb +39 -0
- data/test/nodejs/test_env.rb +62 -0
- data/test/nodejs/test_error.rb +29 -0
- data/test/nodejs/test_file.rb +206 -0
- data/test/nodejs/test_file_encoding.rb +20 -0
- data/test/nodejs/test_io.rb +18 -0
- data/test/nodejs/test_opal_builder.rb +12 -0
- data/test/nodejs/test_pathname.rb +16 -0
- data/test/opal/cat.png +0 -0
- data/test/opal/http_server.rb +52 -0
- data/test/opal/test_base64.rb +115 -0
- data/test/opal/test_keyword.rb +590 -0
- data/test/opal/test_matrix.rb +661 -0
- data/test/opal/test_openuri.rb +53 -0
- data/test/opal/unsupported_and_bugs.rb +39 -0
- data/yarn.lock +1355 -0
- metadata +905 -40
- data/.travis.yml +0 -109
- data/appveyor.yml +0 -35
- data/lib/opal/nodes/runtime_helpers.rb +0 -51
- data/opal/corelib/random/MersenneTwister.js +0 -137
- data/opal/corelib/random/mersenne_twister.js.rb +0 -13
- data/stdlib/bigdecimal/kernel.rb +0 -5
data/opal/corelib/array/pack.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# helpers: coerce_to
|
2
|
+
|
1
3
|
require 'corelib/pack_unpack/format_string_parser'
|
2
4
|
|
3
5
|
class Array
|
@@ -91,7 +93,7 @@ class Array
|
|
91
93
|
var buffer = callback(data);
|
92
94
|
|
93
95
|
return buffer.map(function(item) {
|
94
|
-
return
|
96
|
+
return $coerce_to(item, #{Integer}, 'to_int')
|
95
97
|
});
|
96
98
|
}
|
97
99
|
}
|
@@ -101,7 +103,7 @@ class Array
|
|
101
103
|
var buffer = callback(data);
|
102
104
|
|
103
105
|
return buffer.map(function(item) {
|
104
|
-
return
|
106
|
+
return $coerce_to(item, #{String}, 'to_str')
|
105
107
|
});
|
106
108
|
}
|
107
109
|
}
|
@@ -225,7 +227,7 @@ class Array
|
|
225
227
|
} else if (source === undefined) {
|
226
228
|
#{raise ArgumentError, 'too few arguments'};
|
227
229
|
} else {
|
228
|
-
source =
|
230
|
+
source = $coerce_to(source, #{String}, 'to_str');
|
229
231
|
}
|
230
232
|
|
231
233
|
buffer = buffer.slice(1, buffer.length);
|
@@ -134,10 +134,6 @@ class BasicObject
|
|
134
134
|
def singleton_method_undefined(*)
|
135
135
|
end
|
136
136
|
|
137
|
-
def class
|
138
|
-
`self.$$class`
|
139
|
-
end
|
140
|
-
|
141
137
|
def method_missing(symbol, *args, &block)
|
142
138
|
message = if `self.$inspect && !self.$inspect.$$stub`
|
143
139
|
"undefined method `#{symbol}' for #{inspect}:#{`self.$$class`}"
|
@@ -147,4 +143,8 @@ class BasicObject
|
|
147
143
|
|
148
144
|
::Kernel.raise ::NoMethodError.new(message, symbol)
|
149
145
|
end
|
146
|
+
|
147
|
+
def respond_to_missing?(method_name, include_all = false)
|
148
|
+
false
|
149
|
+
end
|
150
150
|
end
|
data/opal/corelib/class.rb
CHANGED
@@ -49,13 +49,14 @@ class Class
|
|
49
49
|
%x{
|
50
50
|
var singleton_of = self.$$singleton_of;
|
51
51
|
|
52
|
-
if (singleton_of &&
|
52
|
+
if (singleton_of && singleton_of.$$is_a_module) {
|
53
53
|
return #{"#<Class:#{`singleton_of`.name}>"};
|
54
54
|
}
|
55
55
|
else if (singleton_of) {
|
56
56
|
// a singleton class created from an object
|
57
57
|
return #{"#<Class:#<#{`singleton_of.$$class`.name}:0x#{`Opal.id(singleton_of)`.to_s(16)}>>"};
|
58
58
|
}
|
59
|
+
|
59
60
|
return #{super()};
|
60
61
|
}
|
61
62
|
end
|
data/opal/corelib/comparable.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# helpers: falsy
|
2
|
+
|
1
3
|
module Comparable
|
2
4
|
%x{
|
3
5
|
function normalize(what) {
|
@@ -20,6 +22,12 @@ module Comparable
|
|
20
22
|
}
|
21
23
|
#{raise ArgumentError, "comparison of #{`lhs`.class} with #{`class_name`} failed"}
|
22
24
|
}
|
25
|
+
|
26
|
+
function cmp_or_fail(lhs, rhs) {
|
27
|
+
var cmp = #{`lhs` <=> `rhs`};
|
28
|
+
if ($falsy(cmp)) fail_comparison(lhs, rhs);
|
29
|
+
return normalize(cmp);
|
30
|
+
}
|
23
31
|
}
|
24
32
|
|
25
33
|
def ==(other)
|
@@ -43,35 +51,19 @@ module Comparable
|
|
43
51
|
end
|
44
52
|
|
45
53
|
def >(other)
|
46
|
-
|
47
|
-
`fail_comparison(self, other)`
|
48
|
-
end
|
49
|
-
|
50
|
-
`normalize(cmp) > 0`
|
54
|
+
`cmp_or_fail(self, other) > 0`
|
51
55
|
end
|
52
56
|
|
53
57
|
def >=(other)
|
54
|
-
|
55
|
-
`fail_comparison(self, other)`
|
56
|
-
end
|
57
|
-
|
58
|
-
`normalize(cmp) >= 0`
|
58
|
+
`cmp_or_fail(self, other) >= 0`
|
59
59
|
end
|
60
60
|
|
61
61
|
def <(other)
|
62
|
-
|
63
|
-
`fail_comparison(self, other)`
|
64
|
-
end
|
65
|
-
|
66
|
-
`normalize(cmp) < 0`
|
62
|
+
`cmp_or_fail(self, other) < 0`
|
67
63
|
end
|
68
64
|
|
69
65
|
def <=(other)
|
70
|
-
|
71
|
-
`fail_comparison(self, other)`
|
72
|
-
end
|
73
|
-
|
74
|
-
`normalize(cmp) <= 0`
|
66
|
+
`cmp_or_fail(self, other) <= 0`
|
75
67
|
end
|
76
68
|
|
77
69
|
def between?(min, max)
|
@@ -80,19 +72,45 @@ module Comparable
|
|
80
72
|
true
|
81
73
|
end
|
82
74
|
|
83
|
-
def clamp(min, max)
|
84
|
-
|
75
|
+
def clamp(min, max = nil)
|
76
|
+
%x{
|
77
|
+
var c, excl;
|
78
|
+
|
79
|
+
if (max === nil) {
|
80
|
+
// We are dealing with a new Ruby 2.7 behaviour that we are able to
|
81
|
+
// provide a single Range argument instead of 2 Comparables.
|
82
|
+
|
83
|
+
if (!Opal.is_a(min, Opal.Range)) {
|
84
|
+
#{raise TypeError, "wrong argument type #{min.class} (expected Range)"}
|
85
|
+
}
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
87
|
+
excl = min.excl;
|
88
|
+
max = min.end;
|
89
|
+
min = min.begin;
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
91
|
+
if (max !== nil && excl) {
|
92
|
+
#{raise ArgumentError, 'cannot clamp with an exclusive range'}
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
if (min !== nil && max !== nil && cmp_or_fail(min, max) > 0) {
|
97
|
+
#{raise ArgumentError, 'min argument must be smaller than max argument'}
|
98
|
+
}
|
99
|
+
|
100
|
+
if (min !== nil) {
|
101
|
+
c = cmp_or_fail(self, min);
|
102
|
+
|
103
|
+
if (c == 0) return self;
|
104
|
+
if (c < 0) return min;
|
105
|
+
}
|
106
|
+
|
107
|
+
if (max !== nil) {
|
108
|
+
c = cmp_or_fail(self, max);
|
93
109
|
|
94
|
-
|
95
|
-
|
96
|
-
|
110
|
+
if (c > 0) return max;
|
111
|
+
}
|
112
|
+
|
113
|
+
return self;
|
114
|
+
}
|
97
115
|
end
|
98
116
|
end
|
data/opal/corelib/constants.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
RUBY_PLATFORM = 'opal'
|
2
2
|
RUBY_ENGINE = 'opal'
|
3
|
-
RUBY_VERSION = '
|
4
|
-
RUBY_ENGINE_VERSION = '1.
|
5
|
-
RUBY_RELEASE_DATE = '
|
3
|
+
RUBY_VERSION = '3.0.0'
|
4
|
+
RUBY_ENGINE_VERSION = '1.1.1.rc1'
|
5
|
+
RUBY_RELEASE_DATE = '2021-02-22'
|
6
6
|
RUBY_PATCHLEVEL = 0
|
7
|
-
RUBY_REVISION = 0
|
8
|
-
RUBY_COPYRIGHT = 'opal - Copyright (C) 2013-
|
7
|
+
RUBY_REVISION = '0'
|
8
|
+
RUBY_COPYRIGHT = 'opal - Copyright (C) 2013-2021 Adam Beynon and the Opal contributors'
|
9
9
|
RUBY_DESCRIPTION = "opal #{RUBY_ENGINE_VERSION} (#{RUBY_RELEASE_DATE} revision #{RUBY_REVISION})"
|
data/opal/corelib/enumerable.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# helpers: falsy, truthy, coerce_to
|
2
|
+
|
1
3
|
module Enumerable
|
2
4
|
%x{
|
3
5
|
function comparableForPattern(value) {
|
@@ -172,8 +174,7 @@ module Enumerable
|
|
172
174
|
end
|
173
175
|
|
174
176
|
%x{
|
175
|
-
var
|
176
|
-
all = [], i, length, value;
|
177
|
+
var all = [], i, length, value;
|
177
178
|
|
178
179
|
self.$each.$$p = function() {
|
179
180
|
var param = #{Opal.destructure(`arguments`)},
|
@@ -184,10 +185,6 @@ module Enumerable
|
|
184
185
|
|
185
186
|
self.$each();
|
186
187
|
|
187
|
-
if (result !== undefined) {
|
188
|
-
return result;
|
189
|
-
}
|
190
|
-
|
191
188
|
if (all.length === 0) {
|
192
189
|
return nil;
|
193
190
|
}
|
@@ -235,7 +232,7 @@ module Enumerable
|
|
235
232
|
end
|
236
233
|
|
237
234
|
def drop(number)
|
238
|
-
number =
|
235
|
+
number = `$coerce_to(number, #{Integer}, 'to_int')`
|
239
236
|
|
240
237
|
if `number < 0`
|
241
238
|
raise ArgumentError, 'attempt to drop negative size'
|
@@ -272,7 +269,7 @@ module Enumerable
|
|
272
269
|
if (dropping) {
|
273
270
|
var value = Opal.yield1(block, param);
|
274
271
|
|
275
|
-
if (
|
272
|
+
if ($falsy(value)) {
|
276
273
|
dropping = false;
|
277
274
|
result.push(param);
|
278
275
|
}
|
@@ -313,7 +310,7 @@ module Enumerable
|
|
313
310
|
end
|
314
311
|
|
315
312
|
%x{
|
316
|
-
var buffer = []
|
313
|
+
var buffer = [];
|
317
314
|
|
318
315
|
self.$each.$$p = function() {
|
319
316
|
var element = #{Opal.destructure(`arguments`)};
|
@@ -328,7 +325,7 @@ module Enumerable
|
|
328
325
|
|
329
326
|
self.$each();
|
330
327
|
|
331
|
-
return
|
328
|
+
return nil;
|
332
329
|
}
|
333
330
|
end
|
334
331
|
|
@@ -351,7 +348,7 @@ module Enumerable
|
|
351
348
|
end
|
352
349
|
|
353
350
|
def each_slice(n, &block)
|
354
|
-
n =
|
351
|
+
n = `$coerce_to(#{n}, #{Integer}, 'to_int')`
|
355
352
|
|
356
353
|
if `n <= 0`
|
357
354
|
raise ArgumentError, 'invalid slice size'
|
@@ -360,8 +357,7 @@ module Enumerable
|
|
360
357
|
return enum_for(:each_slice, n) { respond_to?(:size) ? (size / n).ceil : nil } unless block_given?
|
361
358
|
|
362
359
|
%x{
|
363
|
-
var
|
364
|
-
slice = []
|
360
|
+
var slice = []
|
365
361
|
|
366
362
|
self.$each.$$p = function() {
|
367
363
|
var param = #{Opal.destructure(`arguments`)};
|
@@ -376,10 +372,6 @@ module Enumerable
|
|
376
372
|
|
377
373
|
self.$each();
|
378
374
|
|
379
|
-
if (result !== undefined) {
|
380
|
-
return result;
|
381
|
-
}
|
382
|
-
|
383
375
|
// our "last" group, if smaller than n then won't have been yielded
|
384
376
|
if (slice.length > 0) {
|
385
377
|
Opal.yield1(block, slice);
|
@@ -393,8 +385,7 @@ module Enumerable
|
|
393
385
|
return enum_for(:each_with_index, *args) { enumerator_size } unless block_given?
|
394
386
|
|
395
387
|
%x{
|
396
|
-
var
|
397
|
-
index = 0;
|
388
|
+
var index = 0;
|
398
389
|
|
399
390
|
self.$each.$$p = function() {
|
400
391
|
var param = #{Opal.destructure(`arguments`)};
|
@@ -405,10 +396,6 @@ module Enumerable
|
|
405
396
|
};
|
406
397
|
|
407
398
|
self.$each.apply(self, args);
|
408
|
-
|
409
|
-
if (result !== undefined) {
|
410
|
-
return result;
|
411
|
-
}
|
412
399
|
}
|
413
400
|
|
414
401
|
self
|
@@ -418,8 +405,6 @@ module Enumerable
|
|
418
405
|
return enum_for(:each_with_object, object) { enumerator_size } unless block_given?
|
419
406
|
|
420
407
|
%x{
|
421
|
-
var result;
|
422
|
-
|
423
408
|
self.$each.$$p = function() {
|
424
409
|
var param = #{Opal.destructure(`arguments`)};
|
425
410
|
|
@@ -427,10 +412,6 @@ module Enumerable
|
|
427
412
|
};
|
428
413
|
|
429
414
|
self.$each();
|
430
|
-
|
431
|
-
if (result !== undefined) {
|
432
|
-
return result;
|
433
|
-
}
|
434
415
|
}
|
435
416
|
|
436
417
|
object
|
@@ -450,6 +431,12 @@ module Enumerable
|
|
450
431
|
}
|
451
432
|
end
|
452
433
|
|
434
|
+
def filter_map(&block)
|
435
|
+
return enum_for(:filter_map) { enumerator_size } unless block_given?
|
436
|
+
|
437
|
+
map(&block).select(&:itself)
|
438
|
+
end
|
439
|
+
|
453
440
|
alias find detect
|
454
441
|
|
455
442
|
def find_all(&block)
|
@@ -462,7 +449,7 @@ module Enumerable
|
|
462
449
|
var param = #{Opal.destructure(`arguments`)},
|
463
450
|
value = Opal.yield1(block, param);
|
464
451
|
|
465
|
-
if (
|
452
|
+
if ($truthy(value)) {
|
466
453
|
result.push(param);
|
467
454
|
}
|
468
455
|
};
|
@@ -473,6 +460,8 @@ module Enumerable
|
|
473
460
|
}
|
474
461
|
end
|
475
462
|
|
463
|
+
alias filter find_all
|
464
|
+
|
476
465
|
def find_index(object = undefined, &block)
|
477
466
|
return enum_for :find_index if `object === undefined && block === nil`
|
478
467
|
|
@@ -512,7 +501,7 @@ module Enumerable
|
|
512
501
|
end
|
513
502
|
else
|
514
503
|
result = []
|
515
|
-
number =
|
504
|
+
number = `$coerce_to(number, #{Integer}, 'to_int')`
|
516
505
|
|
517
506
|
if `number < 0`
|
518
507
|
raise ArgumentError, 'attempt to take negative size'
|
@@ -705,15 +694,19 @@ module Enumerable
|
|
705
694
|
return result;
|
706
695
|
}
|
707
696
|
}
|
708
|
-
}
|
709
697
|
|
710
|
-
|
698
|
+
n = $coerce_to(n, #{Integer}, 'to_int');
|
699
|
+
}
|
711
700
|
|
712
701
|
sort(&block).reverse.first(n)
|
713
702
|
end
|
714
703
|
|
715
|
-
def max_by(&block)
|
716
|
-
return enum_for(:max_by) { enumerator_size } unless block
|
704
|
+
def max_by(n = nil, &block)
|
705
|
+
return enum_for(:max_by, n) { enumerator_size } unless block
|
706
|
+
|
707
|
+
unless n.nil?
|
708
|
+
return sort_by(&block).reverse.take n
|
709
|
+
end
|
717
710
|
|
718
711
|
%x{
|
719
712
|
var result,
|
@@ -743,7 +736,15 @@ module Enumerable
|
|
743
736
|
|
744
737
|
alias member? include?
|
745
738
|
|
746
|
-
def min(&block)
|
739
|
+
def min(n = nil, &block)
|
740
|
+
unless n.nil?
|
741
|
+
if block_given?
|
742
|
+
return sort { |a, b| yield a, b }.take n
|
743
|
+
else
|
744
|
+
return sort.take n
|
745
|
+
end
|
746
|
+
end
|
747
|
+
|
747
748
|
%x{
|
748
749
|
var result;
|
749
750
|
|
@@ -788,8 +789,12 @@ module Enumerable
|
|
788
789
|
}
|
789
790
|
end
|
790
791
|
|
791
|
-
def min_by(&block)
|
792
|
-
return enum_for(:min_by) { enumerator_size } unless block
|
792
|
+
def min_by(n = nil, &block)
|
793
|
+
return enum_for(:min_by, n) { enumerator_size } unless block
|
794
|
+
|
795
|
+
unless n.nil?
|
796
|
+
return sort_by(&block).take n
|
797
|
+
end
|
793
798
|
|
794
799
|
%x{
|
795
800
|
var result,
|
@@ -854,7 +859,33 @@ module Enumerable
|
|
854
859
|
end
|
855
860
|
|
856
861
|
def minmax_by(&block)
|
857
|
-
|
862
|
+
return enum_for(:minmax_by) { enumerator_size } unless block
|
863
|
+
|
864
|
+
%x{
|
865
|
+
var min_result = nil,
|
866
|
+
max_result = nil,
|
867
|
+
min_by,
|
868
|
+
max_by;
|
869
|
+
|
870
|
+
self.$each.$$p = function() {
|
871
|
+
var param = #{Opal.destructure(`arguments`)},
|
872
|
+
value = Opal.yield1(block, param);
|
873
|
+
|
874
|
+
if ((min_by === undefined) || #{`value` <=> `min_by`} < 0) {
|
875
|
+
min_result = param;
|
876
|
+
min_by = value;
|
877
|
+
}
|
878
|
+
|
879
|
+
if ((max_by === undefined) || #{`value` <=> `max_by`} > 0) {
|
880
|
+
max_result = param;
|
881
|
+
max_by = value;
|
882
|
+
}
|
883
|
+
};
|
884
|
+
|
885
|
+
self.$each();
|
886
|
+
|
887
|
+
return [min_result, max_result];
|
888
|
+
}
|
858
889
|
end
|
859
890
|
|
860
891
|
def none?(pattern = undefined, &block)
|
@@ -922,7 +953,7 @@ module Enumerable
|
|
922
953
|
var param = #{Opal.destructure(`arguments`)},
|
923
954
|
value = Opal.yield1(block, param);
|
924
955
|
|
925
|
-
if (
|
956
|
+
if ($truthy(value)) {
|
926
957
|
truthy.push(param);
|
927
958
|
}
|
928
959
|
else {
|
@@ -948,7 +979,7 @@ module Enumerable
|
|
948
979
|
var param = #{Opal.destructure(`arguments`)},
|
949
980
|
value = Opal.yield1(block, param);
|
950
981
|
|
951
|
-
if (
|
982
|
+
if ($falsy(value)) {
|
952
983
|
result.push(param);
|
953
984
|
}
|
954
985
|
};
|
@@ -1000,7 +1031,7 @@ module Enumerable
|
|
1000
1031
|
var param = #{Opal.destructure(`arguments`)},
|
1001
1032
|
value = Opal.yield1(block, param);
|
1002
1033
|
|
1003
|
-
if (
|
1034
|
+
if ($truthy(value) && slice.length > 0) {
|
1004
1035
|
#{e << `slice`};
|
1005
1036
|
slice = [];
|
1006
1037
|
}
|
@@ -1013,7 +1044,7 @@ module Enumerable
|
|
1013
1044
|
var param = #{Opal.destructure(`arguments`)},
|
1014
1045
|
value = block(param, #{pattern.dup});
|
1015
1046
|
|
1016
|
-
if (
|
1047
|
+
if ($truthy(value) && slice.length > 0) {
|
1017
1048
|
#{e << `slice`};
|
1018
1049
|
slice = [];
|
1019
1050
|
}
|
@@ -1027,7 +1058,7 @@ module Enumerable
|
|
1027
1058
|
var param = #{Opal.destructure(`arguments`)},
|
1028
1059
|
value = #{pattern === `param`};
|
1029
1060
|
|
1030
|
-
if (
|
1061
|
+
if ($truthy(value) && slice.length > 0) {
|
1031
1062
|
#{e << `slice`};
|
1032
1063
|
slice = [];
|
1033
1064
|
}
|
@@ -1070,7 +1101,7 @@ module Enumerable
|
|
1070
1101
|
accumulate = [];
|
1071
1102
|
}
|
1072
1103
|
|
1073
|
-
if (
|
1104
|
+
if ($truthy(end_chunk)) {
|
1074
1105
|
accumulate.push(element);
|
1075
1106
|
#{yielder.yield(`accumulate`)};
|
1076
1107
|
accumulate = null;
|
@@ -1107,7 +1138,7 @@ module Enumerable
|
|
1107
1138
|
slice = [];
|
1108
1139
|
}
|
1109
1140
|
|
1110
|
-
if (
|
1141
|
+
if ($truthy(match)) {
|
1111
1142
|
slice.push(before);
|
1112
1143
|
#{yielder.yield(`slice`)};
|
1113
1144
|
slice = [];
|
@@ -1198,8 +1229,39 @@ module Enumerable
|
|
1198
1229
|
hash.values
|
1199
1230
|
end
|
1200
1231
|
|
1232
|
+
def tally
|
1233
|
+
group_by(&:itself).transform_values(&:count)
|
1234
|
+
end
|
1235
|
+
|
1201
1236
|
alias to_a entries
|
1202
1237
|
|
1238
|
+
def to_h(*args, &block)
|
1239
|
+
return map(&block).to_h(*args) if block_given?
|
1240
|
+
|
1241
|
+
%x{
|
1242
|
+
var hash = #{{}};
|
1243
|
+
|
1244
|
+
self.$each.$$p = function() {
|
1245
|
+
var param = #{Opal.destructure(`arguments`)};
|
1246
|
+
var ary = #{Opal.coerce_to?(`param`, Array, :to_ary)}, key, val;
|
1247
|
+
if (!ary.$$is_array) {
|
1248
|
+
#{raise TypeError, "wrong element type #{`ary`.class} (expected array)"}
|
1249
|
+
}
|
1250
|
+
if (ary.length !== 2) {
|
1251
|
+
#{raise ArgumentError, "wrong array length (expected 2, was #{`ary`.length})"}
|
1252
|
+
}
|
1253
|
+
key = ary[0];
|
1254
|
+
val = ary[1];
|
1255
|
+
|
1256
|
+
Opal.hash_put(hash, key, val);
|
1257
|
+
};
|
1258
|
+
|
1259
|
+
self.$each.apply(self, args);
|
1260
|
+
|
1261
|
+
return hash;
|
1262
|
+
}
|
1263
|
+
end
|
1264
|
+
|
1203
1265
|
def zip(*others, &block)
|
1204
1266
|
to_a.zip(*others)
|
1205
1267
|
end
|