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/lib/opal/util.rb
CHANGED
@@ -6,66 +6,29 @@ module Opal
|
|
6
6
|
module Util
|
7
7
|
extend self
|
8
8
|
|
9
|
+
ExitStatusError = Class.new(StandardError)
|
10
|
+
|
9
11
|
# Used for uglifying source to minify.
|
10
12
|
#
|
11
13
|
# Opal::Util.uglify("javascript contents")
|
12
14
|
#
|
13
15
|
# @param str [String] string to minify
|
14
16
|
# @return [String]
|
15
|
-
def uglify(
|
16
|
-
|
17
|
-
uglifyjs.digest(str)
|
17
|
+
def uglify(source)
|
18
|
+
sh 'bin/yarn -s run uglifyjs -c', data: source
|
18
19
|
end
|
19
20
|
|
20
21
|
# Gzip code to check file size.
|
21
|
-
def gzip(
|
22
|
-
|
23
|
-
gzip.digest(str)
|
22
|
+
def gzip(source)
|
23
|
+
sh 'gzip -f', data: source
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
def initialize(command, options, message = nil)
|
28
|
-
@command, @options, @message = command, options, message
|
29
|
-
return unless command_installed? command, message
|
30
|
-
end
|
31
|
-
attr_reader :command, :options, :message
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def hide_stderr
|
36
|
-
if (/mswin|mingw/ =~ RUBY_PLATFORM).nil?
|
37
|
-
'2> /dev/null'
|
38
|
-
else
|
39
|
-
'2> nul'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Code from http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
|
44
|
-
def which(cmd)
|
45
|
-
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
46
|
-
ENV['PATH'].split(File::PATH_SEPARATOR).find do |path|
|
47
|
-
exts.find do |ext|
|
48
|
-
exe = File.join(path, "#{cmd}#{ext}")
|
49
|
-
exe if File.executable? exe
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
INSTALLED = {}
|
55
|
-
def command_installed?(cmd, install_comment)
|
56
|
-
command_installed = Command::INSTALLED[cmd.to_s] ||= which(cmd)
|
57
|
-
$stderr.puts %{"#{cmd}" command not found#{install_comment}} unless command_installed
|
58
|
-
command_installed
|
59
|
-
end
|
60
|
-
end
|
26
|
+
private
|
61
27
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
raise ExitStatusError, "exited with status #{status.exitstatus}" unless status.success?
|
67
|
-
out
|
68
|
-
end
|
28
|
+
def sh(command, data:)
|
29
|
+
out, _err, status = Open3.capture3(command, stdin_data: data)
|
30
|
+
raise ExitStatusError, "exited with status #{status.exitstatus}" unless status.success?
|
31
|
+
out
|
69
32
|
end
|
70
33
|
end
|
71
34
|
end
|
data/lib/opal/version.rb
CHANGED
data/opal.gemspec
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require 'opal/version'
|
1
|
+
require_relative 'lib/opal/version'
|
4
2
|
|
5
3
|
Gem::Specification.new do |spec|
|
6
4
|
spec.name = 'opal'
|
@@ -13,40 +11,42 @@ Gem::Specification.new do |spec|
|
|
13
11
|
spec.homepage = 'https://opalrb.com'
|
14
12
|
spec.license = 'MIT'
|
15
13
|
|
16
|
-
spec.metadata
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
14
|
+
spec.metadata["homepage_uri"] = "https://opalrb.com/"
|
15
|
+
spec.metadata["bug_tracker_uri"] = "https://github.com/opal/opal/issues"
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/opal/opal/blob/v#{spec.version}/CHANGELOG.md"
|
17
|
+
spec.metadata["readme_uri"] = "https://github.com/opal/opal/blob/v#{spec.version}/README.md"
|
18
|
+
spec.metadata["api_documentation_uri"] = "http://opalrb.com/docs/api/v#{spec.version}/index.html"
|
19
|
+
spec.metadata["guides_uri"] = "http://opalrb.com/docs/guides/v#{spec.version}/index.html"
|
20
|
+
spec.metadata["chat_uri"] = "https://gitter.im/opal/opal"
|
21
|
+
spec.metadata["source_code_uri"] = "https://github.com/opal/opal"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
# Remove symlinks because Windows doesn't always support them.
|
26
|
+
files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }.reject(&File.method(:symlink?))
|
27
|
+
|
28
|
+
spec.files = files.grep(%r{^(test|spec|features)/})
|
29
|
+
spec.test_files = files.grep_v(%r{^(test|spec|features)/})
|
30
|
+
spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
31
|
spec.bindir = 'exe'
|
33
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
32
|
spec.require_paths = ['lib']
|
35
33
|
|
36
34
|
spec.required_ruby_version = '>= 2.3'
|
37
35
|
|
38
36
|
spec.add_dependency 'ast', '>= 2.3.0'
|
39
|
-
spec.add_dependency 'parser', '~>
|
37
|
+
spec.add_dependency 'parser', '~> 3.0'
|
40
38
|
|
41
39
|
spec.add_development_dependency 'sourcemap', '~> 0.1.0'
|
42
|
-
spec.add_development_dependency 'rake', '~>
|
43
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
40
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
41
|
+
spec.add_development_dependency 'rspec', '~> 3.9'
|
44
42
|
spec.add_development_dependency 'octokit', '~> 4.9'
|
45
43
|
spec.add_development_dependency 'bundler'
|
46
44
|
spec.add_development_dependency 'rack-test'
|
47
|
-
spec.add_development_dependency 'opal-minitest'
|
48
45
|
spec.add_development_dependency 'selenium-webdriver'
|
49
|
-
spec.add_development_dependency 'benchmark-ips'
|
46
|
+
spec.add_development_dependency 'benchmark-ips', '< 2.8'
|
50
47
|
spec.add_development_dependency 'sinatra'
|
51
|
-
spec.add_development_dependency 'rubocop', '
|
48
|
+
spec.add_development_dependency 'rubocop', '~> 0.67.0'
|
49
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.1.0'
|
50
|
+
spec.add_development_dependency 'rack'
|
51
|
+
spec.add_development_dependency 'webrick'
|
52
52
|
end
|
data/opal/corelib/array.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# helpers: truthy, falsy, hash_ids, yield1, hash_get, hash_put, hash_delete, coerce_to, respond_to
|
2
|
+
|
1
3
|
require 'corelib/enumerable'
|
2
4
|
require 'corelib/numeric'
|
3
5
|
|
@@ -8,6 +10,29 @@ class Array < `Array`
|
|
8
10
|
`Opal.defineProperty(self.$$prototype, '$$is_array', true)`
|
9
11
|
|
10
12
|
%x{
|
13
|
+
// Recent versions of V8 (> 7.1) only use an optimized implementation when Array.prototype is unmodified.
|
14
|
+
// For instance, "array-splice.tq" has a "fast path" (ExtractFastJSArray, defined in "src/codegen/code-stub-assembler.cc")
|
15
|
+
// but it's only enabled when "IsPrototypeInitialArrayPrototype()" is true.
|
16
|
+
//
|
17
|
+
// Older versions of V8 were using relatively fast JS-with-extensions code even when Array.prototype is modified:
|
18
|
+
// https://github.com/v8/v8/blob/7.0.1/src/js/array.js#L599-L642
|
19
|
+
//
|
20
|
+
// In short, Array operations are slow in recent versions of V8 when the Array.prototype has been tampered.
|
21
|
+
// So, when possible, we are using faster open-coded version to boost the performance.
|
22
|
+
|
23
|
+
// As of V8 8.4, depending on the size of the array, this is up to ~25x times faster than Array#shift()
|
24
|
+
// Implementation is heavily inspired by: https://github.com/nodejs/node/blob/ba684805b6c0eded76e5cd89ee00328ac7a59365/lib/internal/util.js#L341-L347
|
25
|
+
function shiftNoArg(list) {
|
26
|
+
var r = list[0];
|
27
|
+
var index = 1;
|
28
|
+
var length = list.length;
|
29
|
+
for (; index < length; index++) {
|
30
|
+
list[index - 1] = list[index];
|
31
|
+
}
|
32
|
+
list.pop();
|
33
|
+
return r;
|
34
|
+
}
|
35
|
+
|
11
36
|
function toArraySubclass(obj, klass) {
|
12
37
|
if (klass.$$name === Opal.Array) {
|
13
38
|
return obj;
|
@@ -15,6 +40,34 @@ class Array < `Array`
|
|
15
40
|
return klass.$allocate().$replace(#{`obj`.to_a});
|
16
41
|
}
|
17
42
|
}
|
43
|
+
|
44
|
+
// A helper for keep_if and delete_if, filter is either Opal.truthy
|
45
|
+
// or Opal.falsy.
|
46
|
+
function filterIf(self, filter, block) {
|
47
|
+
var value, raised = null, updated = new Array(self.length);
|
48
|
+
|
49
|
+
for (var i = 0, i2 = 0, length = self.length; i < length; i++) {
|
50
|
+
if (!raised) {
|
51
|
+
try {
|
52
|
+
value = $yield1(block, self[i])
|
53
|
+
} catch(error) {
|
54
|
+
raised = error;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
if (raised || filter(value)) {
|
59
|
+
updated[i2] = self[i]
|
60
|
+
i2 += 1;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
if (i2 !== i) {
|
65
|
+
self.splice.apply(self, [0, updated.length].concat(updated));
|
66
|
+
self.splice(i2, updated.length);
|
67
|
+
}
|
68
|
+
|
69
|
+
if (raised) throw raised;
|
70
|
+
}
|
18
71
|
}
|
19
72
|
|
20
73
|
def self.[](*objects)
|
@@ -50,7 +103,7 @@ class Array < `Array`
|
|
50
103
|
}
|
51
104
|
}
|
52
105
|
|
53
|
-
size =
|
106
|
+
size = $coerce_to(size, #{Integer}, 'to_int');
|
54
107
|
|
55
108
|
if (size < 0) {
|
56
109
|
#{raise ArgumentError, 'negative array size'}
|
@@ -83,19 +136,19 @@ class Array < `Array`
|
|
83
136
|
other = if Array === other
|
84
137
|
other.to_a
|
85
138
|
else
|
86
|
-
|
139
|
+
`$coerce_to(other, #{Array}, 'to_ary')`.to_a
|
87
140
|
end
|
88
141
|
|
89
142
|
%x{
|
90
143
|
var result = [], hash = #{{}}, i, length, item;
|
91
144
|
|
92
145
|
for (i = 0, length = other.length; i < length; i++) {
|
93
|
-
|
146
|
+
$hash_put(hash, other[i], true);
|
94
147
|
}
|
95
148
|
|
96
149
|
for (i = 0, length = self.length; i < length; i++) {
|
97
150
|
item = self[i];
|
98
|
-
if (
|
151
|
+
if ($hash_delete(hash, item) !== undefined) {
|
99
152
|
result.push(item);
|
100
153
|
}
|
101
154
|
}
|
@@ -108,18 +161,18 @@ class Array < `Array`
|
|
108
161
|
other = if Array === other
|
109
162
|
other.to_a
|
110
163
|
else
|
111
|
-
|
164
|
+
`$coerce_to(other, #{Array}, 'to_ary')`.to_a
|
112
165
|
end
|
113
166
|
|
114
167
|
%x{
|
115
168
|
var hash = #{{}}, i, length, item;
|
116
169
|
|
117
170
|
for (i = 0, length = self.length; i < length; i++) {
|
118
|
-
|
171
|
+
$hash_put(hash, self[i], true);
|
119
172
|
}
|
120
173
|
|
121
174
|
for (i = 0, length = other.length; i < length; i++) {
|
122
|
-
|
175
|
+
$hash_put(hash, other[i], true);
|
123
176
|
}
|
124
177
|
|
125
178
|
return hash.$keys();
|
@@ -129,7 +182,7 @@ class Array < `Array`
|
|
129
182
|
def *(other)
|
130
183
|
return join(other.to_str) if other.respond_to? :to_str
|
131
184
|
|
132
|
-
other =
|
185
|
+
other = `$coerce_to(other, #{Integer}, 'to_int')`
|
133
186
|
|
134
187
|
if `other < 0`
|
135
188
|
raise ArgumentError, 'negative argument'
|
@@ -151,7 +204,7 @@ class Array < `Array`
|
|
151
204
|
other = if Array === other
|
152
205
|
other.to_a
|
153
206
|
else
|
154
|
-
|
207
|
+
`$coerce_to(other, #{Array}, 'to_ary')`.to_a
|
155
208
|
end
|
156
209
|
|
157
210
|
`self.concat(other)`
|
@@ -161,7 +214,7 @@ class Array < `Array`
|
|
161
214
|
other = if Array === other
|
162
215
|
other.to_a
|
163
216
|
else
|
164
|
-
|
217
|
+
`$coerce_to(other, #{Array}, 'to_ary')`.to_a
|
165
218
|
end
|
166
219
|
|
167
220
|
return [] if `self.length === 0`
|
@@ -171,12 +224,12 @@ class Array < `Array`
|
|
171
224
|
var result = [], hash = #{{}}, i, length, item;
|
172
225
|
|
173
226
|
for (i = 0, length = other.length; i < length; i++) {
|
174
|
-
|
227
|
+
$hash_put(hash, other[i], true);
|
175
228
|
}
|
176
229
|
|
177
230
|
for (i = 0, length = self.length; i < length; i++) {
|
178
231
|
item = self[i];
|
179
|
-
if (
|
232
|
+
if ($hash_get(hash, item) === undefined) {
|
180
233
|
result.push(item);
|
181
234
|
}
|
182
235
|
}
|
@@ -230,7 +283,7 @@ class Array < `Array`
|
|
230
283
|
return true;
|
231
284
|
|
232
285
|
if (!other.$$is_array) {
|
233
|
-
if (
|
286
|
+
if ($respond_to(other, '$to_ary')) {
|
234
287
|
return #{`other` == `array`};
|
235
288
|
} else {
|
236
289
|
return false;
|
@@ -280,8 +333,8 @@ class Array < `Array`
|
|
280
333
|
exclude, from, to, result;
|
281
334
|
|
282
335
|
exclude = index.excl;
|
283
|
-
from =
|
284
|
-
to =
|
336
|
+
from = $coerce_to(index.begin, Opal.Integer, 'to_int');
|
337
|
+
to = $coerce_to(index.end, Opal.Integer, 'to_int');
|
285
338
|
|
286
339
|
if (from < 0) {
|
287
340
|
from += size;
|
@@ -315,7 +368,7 @@ class Array < `Array`
|
|
315
368
|
var size = self.length,
|
316
369
|
exclude, from, to, result;
|
317
370
|
|
318
|
-
index =
|
371
|
+
index = $coerce_to(index, Opal.Integer, 'to_int');
|
319
372
|
|
320
373
|
if (index < 0) {
|
321
374
|
index += size;
|
@@ -333,7 +386,7 @@ class Array < `Array`
|
|
333
386
|
return self[index];
|
334
387
|
}
|
335
388
|
else {
|
336
|
-
length =
|
389
|
+
length = $coerce_to(length, Opal.Integer, 'to_int');
|
337
390
|
|
338
391
|
if (length < 0 || index > size || index < 0) {
|
339
392
|
return nil;
|
@@ -372,8 +425,8 @@ class Array < `Array`
|
|
372
425
|
|
373
426
|
%x{
|
374
427
|
var exclude = index.excl,
|
375
|
-
from =
|
376
|
-
to =
|
428
|
+
from = $coerce_to(index.begin, #{Integer}, 'to_int'),
|
429
|
+
to = $coerce_to(index.end, #{Integer}, 'to_int');
|
377
430
|
|
378
431
|
if (from < 0) {
|
379
432
|
from += size;
|
@@ -425,8 +478,8 @@ class Array < `Array`
|
|
425
478
|
%x{
|
426
479
|
var old;
|
427
480
|
|
428
|
-
index =
|
429
|
-
length =
|
481
|
+
index = $coerce_to(index, #{Integer}, 'to_int');
|
482
|
+
length = $coerce_to(length, #{Integer}, 'to_int');
|
430
483
|
|
431
484
|
if (index < 0) {
|
432
485
|
old = index;
|
@@ -477,9 +530,9 @@ class Array < `Array`
|
|
477
530
|
end
|
478
531
|
|
479
532
|
def at(index)
|
480
|
-
index = Opal.coerce_to index, Integer, :to_int
|
481
|
-
|
482
533
|
%x{
|
534
|
+
index = $coerce_to(index, #{Integer}, 'to_int')
|
535
|
+
|
483
536
|
if (index < 0) {
|
484
537
|
index += self.length;
|
485
538
|
}
|
@@ -507,7 +560,7 @@ class Array < `Array`
|
|
507
560
|
while (min < max) {
|
508
561
|
mid = min + Math.floor((max - min) / 2);
|
509
562
|
val = self[mid];
|
510
|
-
ret =
|
563
|
+
ret = $yield1(block, val);
|
511
564
|
|
512
565
|
if (ret === true) {
|
513
566
|
satisfied = mid;
|
@@ -565,7 +618,7 @@ class Array < `Array`
|
|
565
618
|
if (n === nil) {
|
566
619
|
while (true) {
|
567
620
|
for (i = 0, length = self.length; i < length; i++) {
|
568
|
-
value =
|
621
|
+
value = $yield1(block, self[i]);
|
569
622
|
}
|
570
623
|
}
|
571
624
|
}
|
@@ -577,7 +630,7 @@ class Array < `Array`
|
|
577
630
|
|
578
631
|
while (n > 0) {
|
579
632
|
for (i = 0, length = self.length; i < length; i++) {
|
580
|
-
value =
|
633
|
+
value = $yield1(block, self[i]);
|
581
634
|
}
|
582
635
|
|
583
636
|
n--;
|
@@ -613,7 +666,7 @@ class Array < `Array`
|
|
613
666
|
var result = [];
|
614
667
|
|
615
668
|
for (var i = 0, length = self.length; i < length; i++) {
|
616
|
-
var value =
|
669
|
+
var value = $yield1(block, self[i]);
|
617
670
|
result.push(value);
|
618
671
|
}
|
619
672
|
|
@@ -626,7 +679,7 @@ class Array < `Array`
|
|
626
679
|
|
627
680
|
%x{
|
628
681
|
for (var i = 0, length = self.length; i < length; i++) {
|
629
|
-
var value =
|
682
|
+
var value = $yield1(block, self[i]);
|
630
683
|
self[i] = value;
|
631
684
|
}
|
632
685
|
}
|
@@ -760,7 +813,7 @@ class Array < `Array`
|
|
760
813
|
other = if Array === other
|
761
814
|
other.to_a
|
762
815
|
else
|
763
|
-
|
816
|
+
`$coerce_to(other, #{Array}, 'to_ary')`.to_a
|
764
817
|
end
|
765
818
|
|
766
819
|
if other.equal?(self)
|
@@ -806,7 +859,7 @@ class Array < `Array`
|
|
806
859
|
|
807
860
|
def delete_at(index)
|
808
861
|
%x{
|
809
|
-
index =
|
862
|
+
index = $coerce_to(index, #{Integer}, 'to_int');
|
810
863
|
|
811
864
|
if (index < 0) {
|
812
865
|
index += self.length;
|
@@ -826,23 +879,12 @@ class Array < `Array`
|
|
826
879
|
|
827
880
|
def delete_if(&block)
|
828
881
|
return enum_for(:delete_if) { size } unless block_given?
|
829
|
-
|
830
|
-
%x{
|
831
|
-
for (var i = 0, length = self.length, value; i < length; i++) {
|
832
|
-
value = block(self[i]);
|
833
|
-
|
834
|
-
if (value !== false && value !== nil) {
|
835
|
-
self.splice(i, 1);
|
836
|
-
|
837
|
-
length--;
|
838
|
-
i--;
|
839
|
-
}
|
840
|
-
}
|
841
|
-
}
|
842
|
-
|
882
|
+
%x{filterIf(self, $falsy, block)}
|
843
883
|
self
|
844
884
|
end
|
845
885
|
|
886
|
+
alias difference -
|
887
|
+
|
846
888
|
def dig(idx, *idxs)
|
847
889
|
item = self[idx]
|
848
890
|
|
@@ -887,7 +929,7 @@ class Array < `Array`
|
|
887
929
|
|
888
930
|
%x{
|
889
931
|
for (var i = 0, length = self.length; i < length; i++) {
|
890
|
-
var value =
|
932
|
+
var value = $yield1(block, self[i]);
|
891
933
|
}
|
892
934
|
}
|
893
935
|
|
@@ -899,7 +941,7 @@ class Array < `Array`
|
|
899
941
|
|
900
942
|
%x{
|
901
943
|
for (var i = 0, length = self.length; i < length; i++) {
|
902
|
-
var value =
|
944
|
+
var value = $yield1(block, i);
|
903
945
|
}
|
904
946
|
}
|
905
947
|
|
@@ -959,7 +1001,7 @@ class Array < `Array`
|
|
959
1001
|
%x{
|
960
1002
|
var original = index;
|
961
1003
|
|
962
|
-
index =
|
1004
|
+
index = $coerce_to(index, #{Integer}, 'to_int');
|
963
1005
|
|
964
1006
|
if (index < 0) {
|
965
1007
|
index += self.length;
|
@@ -1014,22 +1056,22 @@ class Array < `Array`
|
|
1014
1056
|
if Range === one
|
1015
1057
|
raise TypeError, 'length invalid with range' if two
|
1016
1058
|
|
1017
|
-
left =
|
1059
|
+
left = `$coerce_to(one.begin, #{Integer}, 'to_int')`
|
1018
1060
|
`left += this.length` if `left < 0`
|
1019
1061
|
raise RangeError, "#{one.inspect} out of range" if `left < 0`
|
1020
1062
|
|
1021
|
-
right =
|
1063
|
+
right = `$coerce_to(one.end, #{Integer}, 'to_int')`
|
1022
1064
|
`right += this.length` if `right < 0`
|
1023
1065
|
`right += 1` unless one.exclude_end?
|
1024
1066
|
|
1025
1067
|
return self if `right <= left`
|
1026
1068
|
elsif one
|
1027
|
-
left =
|
1069
|
+
left = `$coerce_to(one, #{Integer}, 'to_int')`
|
1028
1070
|
`left += this.length` if `left < 0`
|
1029
1071
|
left = 0 if `left < 0`
|
1030
1072
|
|
1031
1073
|
if two
|
1032
|
-
right =
|
1074
|
+
right = `$coerce_to(two, #{Integer}, 'to_int')`
|
1033
1075
|
|
1034
1076
|
return self if `right == 0`
|
1035
1077
|
|
@@ -1078,7 +1120,7 @@ class Array < `Array`
|
|
1078
1120
|
return self.length === 0 ? nil : self[0];
|
1079
1121
|
}
|
1080
1122
|
|
1081
|
-
count =
|
1123
|
+
count = $coerce_to(count, #{Integer}, 'to_int');
|
1082
1124
|
|
1083
1125
|
if (count < 0) {
|
1084
1126
|
#{raise ArgumentError, 'negative array size'};
|
@@ -1100,7 +1142,7 @@ class Array < `Array`
|
|
1100
1142
|
for (i = 0, length = array.length; i < length; i++) {
|
1101
1143
|
item = array[i];
|
1102
1144
|
|
1103
|
-
if (
|
1145
|
+
if (!$respond_to(item, '$to_ary', true)) {
|
1104
1146
|
result.push(item);
|
1105
1147
|
continue;
|
1106
1148
|
}
|
@@ -1135,7 +1177,7 @@ class Array < `Array`
|
|
1135
1177
|
}
|
1136
1178
|
|
1137
1179
|
if (level !== undefined) {
|
1138
|
-
level =
|
1180
|
+
level = $coerce_to(level, #{Integer}, 'to_int');
|
1139
1181
|
}
|
1140
1182
|
|
1141
1183
|
return toArraySubclass(_flatten(self, level), #{self.class});
|
@@ -1166,29 +1208,29 @@ class Array < `Array`
|
|
1166
1208
|
|
1167
1209
|
def hash
|
1168
1210
|
%x{
|
1169
|
-
var top = (
|
1211
|
+
var top = ($hash_ids === undefined),
|
1170
1212
|
result = ['A'],
|
1171
1213
|
hash_id = self.$object_id(),
|
1172
1214
|
item, i, key;
|
1173
1215
|
|
1174
1216
|
try {
|
1175
1217
|
if (top) {
|
1176
|
-
|
1218
|
+
$hash_ids = Object.create(null);
|
1177
1219
|
}
|
1178
1220
|
|
1179
1221
|
// return early for recursive structures
|
1180
|
-
if (
|
1222
|
+
if ($hash_ids[hash_id]) {
|
1181
1223
|
return 'self';
|
1182
1224
|
}
|
1183
1225
|
|
1184
|
-
for (key in
|
1185
|
-
item =
|
1226
|
+
for (key in $hash_ids) {
|
1227
|
+
item = $hash_ids[key];
|
1186
1228
|
if (#{eql?(`item`)}) {
|
1187
1229
|
return 'self';
|
1188
1230
|
}
|
1189
1231
|
}
|
1190
1232
|
|
1191
|
-
|
1233
|
+
$hash_ids[hash_id] = self;
|
1192
1234
|
|
1193
1235
|
for (i = 0; i < self.length; i++) {
|
1194
1236
|
item = self[i];
|
@@ -1198,7 +1240,7 @@ class Array < `Array`
|
|
1198
1240
|
return result.join(',');
|
1199
1241
|
} finally {
|
1200
1242
|
if (top) {
|
1201
|
-
|
1243
|
+
$hash_ids = undefined;
|
1202
1244
|
}
|
1203
1245
|
}
|
1204
1246
|
}
|
@@ -1250,7 +1292,7 @@ class Array < `Array`
|
|
1250
1292
|
|
1251
1293
|
def insert(index, *objects)
|
1252
1294
|
%x{
|
1253
|
-
index =
|
1295
|
+
index = $coerce_to(index, #{Integer}, 'to_int');
|
1254
1296
|
|
1255
1297
|
if (objects.length > 0) {
|
1256
1298
|
if (index < 0) {
|
@@ -1293,6 +1335,8 @@ class Array < `Array`
|
|
1293
1335
|
}
|
1294
1336
|
end
|
1295
1337
|
|
1338
|
+
alias intersection &
|
1339
|
+
|
1296
1340
|
def join(sep = nil)
|
1297
1341
|
return '' if `self.length === 0`
|
1298
1342
|
|
@@ -1307,7 +1351,7 @@ class Array < `Array`
|
|
1307
1351
|
for (i = 0, length = self.length; i < length; i++) {
|
1308
1352
|
item = self[i];
|
1309
1353
|
|
1310
|
-
if (
|
1354
|
+
if ($respond_to(item, '$to_str')) {
|
1311
1355
|
tmp = #{`item`.to_str};
|
1312
1356
|
|
1313
1357
|
if (tmp !== nil) {
|
@@ -1317,7 +1361,7 @@ class Array < `Array`
|
|
1317
1361
|
}
|
1318
1362
|
}
|
1319
1363
|
|
1320
|
-
if (
|
1364
|
+
if ($respond_to(item, '$to_ary')) {
|
1321
1365
|
tmp = #{`item`.to_ary};
|
1322
1366
|
|
1323
1367
|
if (tmp === self) {
|
@@ -1331,7 +1375,7 @@ class Array < `Array`
|
|
1331
1375
|
}
|
1332
1376
|
}
|
1333
1377
|
|
1334
|
-
if (
|
1378
|
+
if ($respond_to(item, '$to_s')) {
|
1335
1379
|
tmp = #{`item`.to_s};
|
1336
1380
|
|
1337
1381
|
if (tmp !== nil) {
|
@@ -1355,20 +1399,7 @@ class Array < `Array`
|
|
1355
1399
|
|
1356
1400
|
def keep_if(&block)
|
1357
1401
|
return enum_for(:keep_if) { size } unless block_given?
|
1358
|
-
|
1359
|
-
%x{
|
1360
|
-
for (var i = 0, length = self.length, value; i < length; i++) {
|
1361
|
-
value = block(self[i]);
|
1362
|
-
|
1363
|
-
if (value === false || value === nil) {
|
1364
|
-
self.splice(i, 1);
|
1365
|
-
|
1366
|
-
length--;
|
1367
|
-
i--;
|
1368
|
-
}
|
1369
|
-
}
|
1370
|
-
}
|
1371
|
-
|
1402
|
+
%x{filterIf(self, $truthy, block)}
|
1372
1403
|
self
|
1373
1404
|
end
|
1374
1405
|
|
@@ -1378,7 +1409,7 @@ class Array < `Array`
|
|
1378
1409
|
return self.length === 0 ? nil : self[self.length - 1];
|
1379
1410
|
}
|
1380
1411
|
|
1381
|
-
count =
|
1412
|
+
count = $coerce_to(count, #{Integer}, 'to_int');
|
1382
1413
|
|
1383
1414
|
if (count < 0) {
|
1384
1415
|
#{raise ArgumentError, 'negative array size'};
|
@@ -1435,7 +1466,7 @@ class Array < `Array`
|
|
1435
1466
|
num = self.length;
|
1436
1467
|
}
|
1437
1468
|
else {
|
1438
|
-
num =
|
1469
|
+
num = $coerce_to(num, #{Integer}, 'to_int');
|
1439
1470
|
}
|
1440
1471
|
|
1441
1472
|
if (num < 0 || self.length < num) {
|
@@ -1471,7 +1502,7 @@ class Array < `Array`
|
|
1471
1502
|
for (var j = 0; j < perm.length; j++) {
|
1472
1503
|
output.push(self[perm[j]]);
|
1473
1504
|
}
|
1474
|
-
|
1505
|
+
$yield1(blk, output);
|
1475
1506
|
}
|
1476
1507
|
}
|
1477
1508
|
}
|
@@ -1521,7 +1552,7 @@ class Array < `Array`
|
|
1521
1552
|
return `self.pop()`
|
1522
1553
|
end
|
1523
1554
|
|
1524
|
-
count =
|
1555
|
+
count = `$coerce_to(count, #{Integer}, 'to_int')`
|
1525
1556
|
|
1526
1557
|
if `count < 0`
|
1527
1558
|
raise ArgumentError, 'negative array size'
|
@@ -1529,7 +1560,9 @@ class Array < `Array`
|
|
1529
1560
|
|
1530
1561
|
return [] if `self.length === 0`
|
1531
1562
|
|
1532
|
-
if `count
|
1563
|
+
if `count === 1`
|
1564
|
+
`[self.pop()]`
|
1565
|
+
elsif `count > self.length`
|
1533
1566
|
`self.splice(0, self.length)`
|
1534
1567
|
else
|
1535
1568
|
`self.splice(self.length - count, self.length)`
|
@@ -1547,7 +1580,7 @@ class Array < `Array`
|
|
1547
1580
|
|
1548
1581
|
arrays[0] = self;
|
1549
1582
|
for (i = 1; i < n; i++) {
|
1550
|
-
arrays[i] =
|
1583
|
+
arrays[i] = $coerce_to(args[i - 1], #{Array}, 'to_ary');
|
1551
1584
|
}
|
1552
1585
|
|
1553
1586
|
for (i = 0; i < n; i++) {
|
@@ -1646,7 +1679,7 @@ class Array < `Array`
|
|
1646
1679
|
other = if Array === other
|
1647
1680
|
other.to_a
|
1648
1681
|
else
|
1649
|
-
|
1682
|
+
`$coerce_to(other, #{Array}, 'to_ary')`.to_a
|
1650
1683
|
end
|
1651
1684
|
|
1652
1685
|
%x{
|
@@ -1712,10 +1745,11 @@ class Array < `Array`
|
|
1712
1745
|
end
|
1713
1746
|
|
1714
1747
|
def rotate(n = 1)
|
1715
|
-
n = Opal.coerce_to n, Integer, :to_int
|
1716
1748
|
%x{
|
1717
1749
|
var ary, idx, firstPart, lastPart;
|
1718
1750
|
|
1751
|
+
n = $coerce_to(n, #{Integer}, 'to_int')
|
1752
|
+
|
1719
1753
|
if (self.length === 1) {
|
1720
1754
|
return self.slice();
|
1721
1755
|
}
|
@@ -1737,8 +1771,8 @@ class Array < `Array`
|
|
1737
1771
|
if (self.length === 0 || self.length === 1) {
|
1738
1772
|
return self;
|
1739
1773
|
}
|
1774
|
+
cnt = $coerce_to(cnt, #{Integer}, 'to_int');
|
1740
1775
|
}
|
1741
|
-
cnt = Opal.coerce_to cnt, Integer, :to_int
|
1742
1776
|
ary = rotate(cnt)
|
1743
1777
|
replace ary
|
1744
1778
|
end
|
@@ -1749,7 +1783,7 @@ class Array < `Array`
|
|
1749
1783
|
end
|
1750
1784
|
|
1751
1785
|
def rand(size)
|
1752
|
-
random =
|
1786
|
+
random = `$coerce_to(#{@rng.rand(size)}, #{Integer}, 'to_int')`
|
1753
1787
|
raise RangeError, 'random value must be >= 0' if `random < 0`
|
1754
1788
|
raise RangeError, 'random value must be less than Array size' unless `random < size`
|
1755
1789
|
|
@@ -1766,11 +1800,11 @@ class Array < `Array`
|
|
1766
1800
|
count = nil
|
1767
1801
|
else
|
1768
1802
|
options = nil
|
1769
|
-
count =
|
1803
|
+
count = `$coerce_to(count, #{Integer}, 'to_int')`
|
1770
1804
|
end
|
1771
1805
|
else
|
1772
|
-
count =
|
1773
|
-
options =
|
1806
|
+
count = `$coerce_to(count, #{Integer}, 'to_int')`
|
1807
|
+
options = `$coerce_to(options, #{Hash}, 'to_hash')`
|
1774
1808
|
end
|
1775
1809
|
|
1776
1810
|
if count && `count < 0`
|
@@ -1877,9 +1911,9 @@ class Array < `Array`
|
|
1877
1911
|
for (var i = 0, length = self.length, item, value; i < length; i++) {
|
1878
1912
|
item = self[i];
|
1879
1913
|
|
1880
|
-
value =
|
1914
|
+
value = $yield1(block, item);
|
1881
1915
|
|
1882
|
-
if (
|
1916
|
+
if ($truthy(value)) {
|
1883
1917
|
result.push(item);
|
1884
1918
|
}
|
1885
1919
|
}
|
@@ -1898,13 +1932,16 @@ class Array < `Array`
|
|
1898
1932
|
}
|
1899
1933
|
end
|
1900
1934
|
|
1935
|
+
alias filter select
|
1936
|
+
alias filter! select!
|
1937
|
+
|
1901
1938
|
def shift(count = undefined)
|
1902
1939
|
if `count === undefined`
|
1903
1940
|
return if `self.length === 0`
|
1904
|
-
return `self
|
1941
|
+
return `shiftNoArg(self)`
|
1905
1942
|
end
|
1906
1943
|
|
1907
|
-
count =
|
1944
|
+
count = `$coerce_to(count, #{Integer}, 'to_int')`
|
1908
1945
|
|
1909
1946
|
if `count < 0`
|
1910
1947
|
raise ArgumentError, 'negative array size'
|
@@ -1972,8 +2009,8 @@ class Array < `Array`
|
|
1972
2009
|
range = index
|
1973
2010
|
result = self[range]
|
1974
2011
|
|
1975
|
-
range_start =
|
1976
|
-
range_end =
|
2012
|
+
range_start = `$coerce_to(range.begin, #{Integer}, 'to_int')`
|
2013
|
+
range_end = `$coerce_to(range.end, #{Integer}, 'to_int')`
|
1977
2014
|
|
1978
2015
|
%x{
|
1979
2016
|
if (range_start < 0) {
|
@@ -2001,7 +2038,7 @@ class Array < `Array`
|
|
2001
2038
|
}
|
2002
2039
|
}
|
2003
2040
|
else
|
2004
|
-
start =
|
2041
|
+
start = `$coerce_to(index, #{Integer}, 'to_int')`
|
2005
2042
|
%x{
|
2006
2043
|
if (start < 0) {
|
2007
2044
|
start += self.length;
|
@@ -2021,8 +2058,8 @@ class Array < `Array`
|
|
2021
2058
|
}
|
2022
2059
|
end
|
2023
2060
|
else
|
2024
|
-
start =
|
2025
|
-
length =
|
2061
|
+
start = `$coerce_to(index, #{Integer}, 'to_int')`
|
2062
|
+
length = `$coerce_to(length, #{Integer}, 'to_int')`
|
2026
2063
|
|
2027
2064
|
%x{
|
2028
2065
|
if (length < 0) {
|
@@ -2133,12 +2170,15 @@ class Array < `Array`
|
|
2133
2170
|
|
2134
2171
|
alias to_ary to_a
|
2135
2172
|
|
2136
|
-
def to_h
|
2173
|
+
def to_h(&block)
|
2174
|
+
array = self
|
2175
|
+
array = array.map(&block) if block_given?
|
2176
|
+
|
2137
2177
|
%x{
|
2138
|
-
var i, len =
|
2178
|
+
var i, len = array.length, ary, key, val, hash = #{{}};
|
2139
2179
|
|
2140
2180
|
for (i = 0; i < len; i++) {
|
2141
|
-
ary = #{Opal.coerce_to?(`
|
2181
|
+
ary = #{Opal.coerce_to?(`array[i]`, Array, :to_ary)};
|
2142
2182
|
if (!ary.$$is_array) {
|
2143
2183
|
#{raise TypeError, "wrong element type #{`ary`.class} at #{`i`} (expected array)"}
|
2144
2184
|
}
|
@@ -2147,7 +2187,7 @@ class Array < `Array`
|
|
2147
2187
|
}
|
2148
2188
|
key = ary[0];
|
2149
2189
|
val = ary[1];
|
2150
|
-
|
2190
|
+
$hash_put(hash, key, val);
|
2151
2191
|
}
|
2152
2192
|
|
2153
2193
|
return hash;
|
@@ -2166,7 +2206,7 @@ class Array < `Array`
|
|
2166
2206
|
row = if Array === row
|
2167
2207
|
row.to_a
|
2168
2208
|
else
|
2169
|
-
|
2209
|
+
`$coerce_to(row, #{Array}, 'to_ary')`.to_a
|
2170
2210
|
end
|
2171
2211
|
|
2172
2212
|
max ||= `row.length`
|
@@ -2184,6 +2224,8 @@ class Array < `Array`
|
|
2184
2224
|
result
|
2185
2225
|
end
|
2186
2226
|
|
2227
|
+
alias union |
|
2228
|
+
|
2187
2229
|
def uniq(&block)
|
2188
2230
|
%x{
|
2189
2231
|
var hash = #{{}}, i, length, item, key;
|
@@ -2191,17 +2233,17 @@ class Array < `Array`
|
|
2191
2233
|
if (block === nil) {
|
2192
2234
|
for (i = 0, length = self.length; i < length; i++) {
|
2193
2235
|
item = self[i];
|
2194
|
-
if (
|
2195
|
-
|
2236
|
+
if ($hash_get(hash, item) === undefined) {
|
2237
|
+
$hash_put(hash, item, item);
|
2196
2238
|
}
|
2197
2239
|
}
|
2198
2240
|
}
|
2199
2241
|
else {
|
2200
2242
|
for (i = 0, length = self.length; i < length; i++) {
|
2201
2243
|
item = self[i];
|
2202
|
-
key =
|
2203
|
-
if (
|
2204
|
-
|
2244
|
+
key = $yield1(block, item);
|
2245
|
+
if ($hash_get(hash, key) === undefined) {
|
2246
|
+
$hash_put(hash, key, item);
|
2205
2247
|
}
|
2206
2248
|
}
|
2207
2249
|
}
|
@@ -2216,10 +2258,10 @@ class Array < `Array`
|
|
2216
2258
|
|
2217
2259
|
for (i = 0, length = original_length; i < length; i++) {
|
2218
2260
|
item = self[i];
|
2219
|
-
key = (block === nil ? item :
|
2261
|
+
key = (block === nil ? item : $yield1(block, item));
|
2220
2262
|
|
2221
|
-
if (
|
2222
|
-
|
2263
|
+
if ($hash_get(hash, key) === undefined) {
|
2264
|
+
$hash_put(hash, key, item);
|
2223
2265
|
continue;
|
2224
2266
|
}
|
2225
2267
|
|
@@ -2249,8 +2291,8 @@ class Array < `Array`
|
|
2249
2291
|
|
2250
2292
|
args.each do |elem|
|
2251
2293
|
if elem.is_a? Range
|
2252
|
-
finish =
|
2253
|
-
start =
|
2294
|
+
finish = `$coerce_to(#{elem.last}, #{Integer}, 'to_int')`
|
2295
|
+
start = `$coerce_to(#{elem.first}, #{Integer}, 'to_int')`
|
2254
2296
|
|
2255
2297
|
%x{
|
2256
2298
|
if (start < 0) {
|
@@ -2273,7 +2315,7 @@ class Array < `Array`
|
|
2273
2315
|
|
2274
2316
|
start.upto(finish) { |i| out << at(i) }
|
2275
2317
|
else
|
2276
|
-
i =
|
2318
|
+
i = `$coerce_to(elem, #{Integer}, 'to_int')`
|
2277
2319
|
out << at(i)
|
2278
2320
|
end
|
2279
2321
|
end
|
@@ -2300,7 +2342,7 @@ class Array < `Array`
|
|
2300
2342
|
}
|
2301
2343
|
others[j] = #{(
|
2302
2344
|
Opal.coerce_to?(`o`, Array, :to_ary) ||
|
2303
|
-
Opal.coerce_to!(`o`, Enumerator, :each)
|
2345
|
+
Opal.coerce_to!(`o`, Enumerator, :to_enum, :each)
|
2304
2346
|
).to_a};
|
2305
2347
|
}
|
2306
2348
|
|