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/docs/sinatra.md
CHANGED
@@ -4,8 +4,11 @@ Add Opal-Sprockets to your Gemfile (or install using `gem`):
|
|
4
4
|
|
5
5
|
```ruby
|
6
6
|
# Gemfile
|
7
|
+
source 'https://rubygems.org'
|
8
|
+
|
7
9
|
gem 'sinatra'
|
8
10
|
gem 'opal-sprockets'
|
11
|
+
gem 'puma'
|
9
12
|
```
|
10
13
|
|
11
14
|
Opal-Sprockets uses `sprockets` as its default build system, so the asset-pipeline
|
@@ -22,17 +25,9 @@ require 'sinatra'
|
|
22
25
|
opal = Opal::Sprockets::Server.new {|s|
|
23
26
|
s.append_path 'app'
|
24
27
|
s.main = 'application'
|
28
|
+
s.debug = ENV['RACK_ENV'] != 'production'
|
25
29
|
}
|
26
30
|
|
27
|
-
maps_prefix = Opal::Sprockets::Server::SOURCE_MAPS_PREFIX_PATH
|
28
|
-
maps_app = Opal::SourceMapServer.new(opal.sprockets, maps_prefix)
|
29
|
-
|
30
|
-
map maps_prefix do
|
31
|
-
use Rack::ConditionalGet
|
32
|
-
use Rack::ETag
|
33
|
-
run maps_app
|
34
|
-
end
|
35
|
-
|
36
31
|
map '/assets' do
|
37
32
|
run opal.sprockets
|
38
33
|
end
|
@@ -42,9 +37,7 @@ get '/' do
|
|
42
37
|
<!doctype html>
|
43
38
|
<html>
|
44
39
|
<head>
|
45
|
-
|
46
|
-
<script src="/assets/application.self.js"></script>
|
47
|
-
<script type="text/javascript">Opal.load("application")</script>
|
40
|
+
#{ Opal::Sprockets.javascript_include_tag('application', debug: opal.debug, sprockets: opal.sprockets, prefix: 'assets/' ) }
|
48
41
|
</head>
|
49
42
|
</html>
|
50
43
|
HTML
|
data/examples/rack/Gemfile
CHANGED
data/examples/rack/config.ru
CHANGED
@@ -2,19 +2,20 @@ require 'bundler'
|
|
2
2
|
Bundler.require
|
3
3
|
|
4
4
|
# Instructions: bundle in this directory
|
5
|
-
# then run bundle exec rackup to start the server
|
6
|
-
# and browse to localhost:9292
|
5
|
+
# then run `bundle exec rackup` to start the server
|
6
|
+
# and browse to http://localhost:9292
|
7
7
|
|
8
8
|
# a very small application that just tries to authenticate a user and fails
|
9
9
|
# it just writes to the console in the browser (no visible html)
|
10
10
|
|
11
11
|
# with gems like opal-jquery or opal-browser you could manipulate the dom directly
|
12
12
|
|
13
|
+
# the directory where the code is (add to opal load path )
|
14
|
+
Opal.append_path 'app'
|
15
|
+
|
13
16
|
run Opal::SimpleServer.new { |s|
|
14
17
|
# the name of the ruby file to load. To use more files they must be required from here (see app)
|
15
18
|
s.main = 'application'
|
16
|
-
# the directory where the code is (add to opal load path )
|
17
|
-
s.append_path 'app'
|
18
19
|
# need to set the index explicitly for opal server to pick it up
|
19
20
|
s.index_path = 'index.html.erb'
|
20
21
|
}
|
data/exe/opal-repl
CHANGED
@@ -1,86 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'opal'
|
3
|
+
require 'opal/repl'
|
4
4
|
|
5
|
-
|
6
|
-
class V8Context
|
7
|
-
def initialize
|
8
|
-
@builder = Opal::Builder.new
|
9
|
-
@history_path = File.expand_path('~/.opal-repl-history')
|
10
|
-
@history = File.exist?(@history_path)
|
11
|
-
end
|
12
|
-
|
13
|
-
def run(filename = nil)
|
14
|
-
return if @v8
|
15
|
-
|
16
|
-
begin
|
17
|
-
require 'mini_racer'
|
18
|
-
rescue LoadError
|
19
|
-
abort 'opal-repl depends on mini_racer gem, which is not currently installed'
|
20
|
-
end
|
21
|
-
|
22
|
-
@v8 = MiniRacer::Context.new
|
23
|
-
@v8.eval Opal::Builder.new.build('opal').to_s
|
24
|
-
|
25
|
-
if filename
|
26
|
-
if File.exist? filename
|
27
|
-
eval_ruby File.read(filename)
|
28
|
-
else
|
29
|
-
fail "file does not exist: #{filename}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
run_repl
|
34
|
-
end
|
35
|
-
|
36
|
-
def log(*str)
|
37
|
-
puts(*str)
|
38
|
-
end
|
39
|
-
|
40
|
-
def run_repl
|
41
|
-
require 'readline'
|
42
|
-
load_history
|
43
|
-
|
44
|
-
loop do
|
45
|
-
# on SIGINT lets just return from the loop..
|
46
|
-
trap('SIGINT') { finish; return }
|
47
|
-
line = Readline.readline '>> ', true
|
48
|
-
|
49
|
-
# if we type exit, then we need to close down context
|
50
|
-
if line == 'exit' or line.nil?
|
51
|
-
break
|
52
|
-
end
|
53
|
-
|
54
|
-
puts "=> #{eval_ruby line}"
|
55
|
-
end
|
56
|
-
|
57
|
-
finish
|
58
|
-
end
|
59
|
-
|
60
|
-
def eval_ruby(str)
|
61
|
-
code = Opal::Builder.new.build_str(str, '(irb)', :irb => true, :const_missing => true)
|
62
|
-
code.processed[0...-1].each { |c| @v8.eval(c.to_s) }
|
63
|
-
@v8.eval "var $_result = #{code.processed.last.to_s} ($_result == null ? 'nil' : $_result.$inspect());"
|
64
|
-
rescue Exception => e
|
65
|
-
puts "#{e.message}\n\t#{e.backtrace.join("\n\t")}"
|
66
|
-
end
|
67
|
-
|
68
|
-
def load_history
|
69
|
-
return unless @history
|
70
|
-
File.read(@history_path).lines.each { |line| Readline::HISTORY.push line.strip }
|
71
|
-
end
|
72
|
-
|
73
|
-
def dump_history
|
74
|
-
return unless @history
|
75
|
-
length = (Readline::HISTORY.size > 1000) ? 1000 : Readline::HISTORY.size
|
76
|
-
File.write(@history_path, Readline::HISTORY.to_a[-length..-1].join("\n"))
|
77
|
-
end
|
78
|
-
|
79
|
-
def finish
|
80
|
-
dump_history
|
81
|
-
@v8 = nil
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
Opal::V8Context.new.run ARGV.first
|
5
|
+
repl = Opal::REPL.new.run ARGV.first
|
data/lib/opal/ast/builder.rb
CHANGED
data/lib/opal/builder.rb
CHANGED
@@ -195,16 +195,8 @@ module Opal
|
|
195
195
|
|
196
196
|
source = stub?(rel_path) ? '' : read(rel_path)
|
197
197
|
|
198
|
-
|
199
|
-
|
200
|
-
case missing_require_severity
|
201
|
-
when :error then raise LoadError, message
|
202
|
-
when :warning then warn "can't find file: #{rel_path.inspect}"
|
203
|
-
when :ignore then # noop
|
204
|
-
end
|
205
|
-
|
206
|
-
return # the handling is delegated to the runtime
|
207
|
-
end
|
198
|
+
# The handling is delegated to the runtime
|
199
|
+
return if source.nil?
|
208
200
|
|
209
201
|
abs_path = expand_path(rel_path)
|
210
202
|
rel_path = expand_ext(rel_path)
|
@@ -24,7 +24,7 @@ module Opal
|
|
24
24
|
def handles(*extensions)
|
25
25
|
@extensions = extensions
|
26
26
|
matches = extensions.join('|')
|
27
|
-
matches = "(#{matches})"
|
27
|
+
matches = "(#{matches})" unless extensions.size == 1
|
28
28
|
@match_regexp = Regexp.new "\\.#{matches}#{REGEXP_END}"
|
29
29
|
|
30
30
|
::Opal::Builder.register_processor(self, extensions)
|
data/lib/opal/cli.rb
CHANGED
@@ -7,7 +7,7 @@ require 'opal/cli_runners'
|
|
7
7
|
module Opal
|
8
8
|
class CLI
|
9
9
|
attr_reader :options, :file, :compiler_options, :evals, :load_paths, :argv,
|
10
|
-
:output, :requires, :gems, :stubs, :verbose, :runner_options,
|
10
|
+
:output, :requires, :rbrequires, :gems, :stubs, :verbose, :runner_options,
|
11
11
|
:preload, :filename, :debug, :no_exit, :lib_only, :missing_require_severity
|
12
12
|
|
13
13
|
class << self
|
@@ -37,6 +37,7 @@ module Opal
|
|
37
37
|
@debug = options.delete(:debug) { false }
|
38
38
|
@filename = options.delete(:filename) { @file && @file.path }
|
39
39
|
@requires = options.delete(:requires) { [] }
|
40
|
+
@rbrequires = options.delete(:rbrequires) { [] }
|
40
41
|
|
41
42
|
@missing_require_severity = options.delete(:missing_require_severity) { Opal::Config.missing_require_severity }
|
42
43
|
|
@@ -79,6 +80,8 @@ module Opal
|
|
79
80
|
end
|
80
81
|
|
81
82
|
def create_builder
|
83
|
+
rbrequires.each(&Kernel.method(:require))
|
84
|
+
|
82
85
|
builder = Opal::Builder.new(
|
83
86
|
stubs: stubs,
|
84
87
|
compiler_options: compiler_options,
|
data/lib/opal/cli_options.rb
CHANGED
@@ -58,6 +58,13 @@ module Opal
|
|
58
58
|
options[:requires] << library
|
59
59
|
end
|
60
60
|
|
61
|
+
on('-q', '--rbrequire LIBRARY', String,
|
62
|
+
'Require the library in Ruby context before compiling'
|
63
|
+
) do |library|
|
64
|
+
options[:rbrequires] ||= []
|
65
|
+
options[:rbrequires] << library
|
66
|
+
end
|
67
|
+
|
61
68
|
on('-s', '--stub FILE', String, 'Stubbed files will be compiled as empty files') do |stub|
|
62
69
|
options[:stubs] ||= []
|
63
70
|
options[:stubs] << stub
|
@@ -105,11 +112,11 @@ module Opal
|
|
105
112
|
|
106
113
|
section 'Compilation Options:'
|
107
114
|
|
108
|
-
on('-M', '--no-method-missing', '
|
115
|
+
on('-M', '--no-method-missing', 'Disable method missing') do
|
109
116
|
options[:method_missing] = false
|
110
117
|
end
|
111
118
|
|
112
|
-
on('-O', '--no-opal', '
|
119
|
+
on('-O', '--no-opal', 'Disable implicit `require "opal"`') do
|
113
120
|
options[:skip_opal_require] = true
|
114
121
|
end
|
115
122
|
|
@@ -137,7 +144,8 @@ module Opal
|
|
137
144
|
options[:missing_require_severity] = level.to_sym
|
138
145
|
end
|
139
146
|
|
140
|
-
on('-P', '--map FILE', '
|
147
|
+
on('-P', '--map FILE', 'Output path to FILE') do |file|
|
148
|
+
options[:runner_options] ||= {}
|
141
149
|
options[:runner_options][:map_file] = file
|
142
150
|
end
|
143
151
|
|
data/lib/opal/cli_runners.rb
CHANGED
@@ -24,10 +24,13 @@ module Opal
|
|
24
24
|
@register[name.to_sym]
|
25
25
|
end
|
26
26
|
|
27
|
+
# @private
|
27
28
|
def self.[]=(name, runner)
|
28
29
|
warn "Overwriting Opal CLI runner: #{name}" if @register.key? name.to_sym
|
30
|
+
|
29
31
|
@register[name.to_sym] = runner
|
30
32
|
end
|
33
|
+
private_class_method :[]=
|
31
34
|
|
32
35
|
def self.to_h
|
33
36
|
@register
|
@@ -35,49 +38,36 @@ module Opal
|
|
35
38
|
|
36
39
|
# @param name [Symbol] the name at which the runner can be reached
|
37
40
|
# @param runner [#call] a callable object that will act as the "runner"
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
# The compiler runner will just output the compiled JavaScript
|
44
|
-
register_runner :compiler, ->(data) {
|
45
|
-
options = data[:options] || {}
|
46
|
-
builder = data.fetch(:builder)
|
47
|
-
map_file = options[:map_file]
|
48
|
-
output = data.fetch(:output)
|
41
|
+
# @param runner [Symbol] a constant name that once autoloaded will point to
|
42
|
+
# a callable.
|
43
|
+
# @param path [nil,String] a path for setting up autoload on the constant
|
44
|
+
def self.register_runner(name, runner, path = nil)
|
45
|
+
autoload runner, path if path
|
49
46
|
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
if runner.respond_to?(:call)
|
48
|
+
self[name] = runner
|
49
|
+
else
|
50
|
+
self[name] = ->(data) { const_get(runner).call(data) }
|
51
|
+
end
|
53
52
|
|
54
|
-
|
55
|
-
|
53
|
+
nil
|
54
|
+
end
|
56
55
|
|
57
|
-
#
|
56
|
+
# Alias a runner name
|
57
|
+
def self.alias_runner(new_name, old_name)
|
58
|
+
self[new_name.to_sym] = self[old_name.to_sym]
|
58
59
|
|
59
|
-
|
60
|
-
runner = ->(data) {
|
61
|
-
klass = const_get(klass_name)
|
62
|
-
runner = klass.new((data[:options] || {}).merge(output: data[:output]))
|
63
|
-
builder = data[:builder]
|
64
|
-
compiled_source = builder.to_s + "\n" + builder.source_map.to_data_uri_comment
|
65
|
-
runner.run(compiled_source, data[:argv])
|
66
|
-
runner.exit_status
|
67
|
-
}
|
68
|
-
names.each { |name| self[name] = runner }
|
60
|
+
nil
|
69
61
|
end
|
70
62
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
63
|
+
register_runner :applescript, :Applescript, 'opal/cli_runners/applescript'
|
64
|
+
register_runner :chrome, :Chrome, 'opal/cli_runners/chrome'
|
65
|
+
register_runner :compiler, :Compiler, 'opal/cli_runners/compiler'
|
66
|
+
register_runner :nashorn, :Nashorn, 'opal/cli_runners/nashorn'
|
67
|
+
register_runner :nodejs, :Nodejs, 'opal/cli_runners/nodejs'
|
68
|
+
register_runner :server, :Server, 'opal/cli_runners/server'
|
76
69
|
|
77
|
-
|
78
|
-
|
79
|
-
register_legacy_runner :Nashorn, :nashorn
|
80
|
-
register_legacy_runner :Nodejs, :nodejs, :node
|
81
|
-
register_legacy_runner :Server, :server
|
70
|
+
alias_runner :osascript, :applescript
|
71
|
+
alias_runner :node, :nodejs
|
82
72
|
end
|
83
73
|
end
|
@@ -3,58 +3,19 @@
|
|
3
3
|
module Opal
|
4
4
|
module CliRunners
|
5
5
|
class Applescript
|
6
|
-
def
|
6
|
+
def self.call(data)
|
7
7
|
unless system('which osalang > /dev/null')
|
8
8
|
raise MissingJavaScriptSupport, 'JavaScript Automation is only supported by OS X Yosemite and above.'
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def puts(*args)
|
16
|
-
output.puts(*args)
|
17
|
-
end
|
18
|
-
|
19
|
-
def run(code, argv)
|
20
|
-
require 'tempfile'
|
21
|
-
tempfile = Tempfile.new('opal-applescript-runner-')
|
22
|
-
# tempfile = File.new('opal-applescript-runner.js', 'w') # for debugging
|
23
|
-
tempfile.puts code
|
24
|
-
tempfile.puts "'';" # OSAScript will output the last thing
|
25
|
-
tempfile.close
|
26
|
-
_successful = system_with_output('osascript', '-l', 'JavaScript', tempfile.path, *argv)
|
11
|
+
SystemRunner.call(data) do |tempfile|
|
12
|
+
tempfile.puts "'';" # OSAScript will output the last thing
|
13
|
+
['osascript', '-l', 'JavaScript', tempfile.path, *data[:argv]]
|
14
|
+
end
|
27
15
|
rescue Errno::ENOENT
|
28
16
|
raise MissingAppleScript, 'AppleScript is only available on Mac OS X.'
|
29
17
|
end
|
30
18
|
|
31
|
-
# Let's support fake IO objects like StringIO
|
32
|
-
def system_with_output(env, *cmd)
|
33
|
-
if (_io_output = IO.try_convert(output))
|
34
|
-
system(env, *cmd)
|
35
|
-
@exit_status = $?.exitstatus
|
36
|
-
return
|
37
|
-
end
|
38
|
-
|
39
|
-
if RUBY_PLATFORM == 'java'
|
40
|
-
# JRuby has issues in dealing with subprocesses (at least up to 1.7.15)
|
41
|
-
# @headius told me it's mostly fixed on master, but while we wait for it
|
42
|
-
# to ship here's a tempfile workaround.
|
43
|
-
require 'tempfile'
|
44
|
-
require 'shellwords'
|
45
|
-
tempfile = Tempfile.new('opal-applescript-output')
|
46
|
-
system(env, cmd.shelljoin + " > #{tempfile.path}")
|
47
|
-
@exit_status = $?.exitstatus
|
48
|
-
captured_output = File.read tempfile.path
|
49
|
-
tempfile.close
|
50
|
-
else
|
51
|
-
require 'open3'
|
52
|
-
captured_output, status = Open3.capture2(env, *cmd)
|
53
|
-
@exit_status = status.exitstatus
|
54
|
-
end
|
55
|
-
output.write captured_output
|
56
|
-
end
|
57
|
-
|
58
19
|
class MissingJavaScriptSupport < RunnerError
|
59
20
|
end
|
60
21
|
|
@@ -3,22 +3,7 @@ var fs = require("fs");
|
|
3
3
|
|
4
4
|
// NOTE: the code above doesn't work on Windows
|
5
5
|
// and it doesn't support interactive stdin input (which is ok for our scenario)
|
6
|
-
var
|
7
|
-
|
8
|
-
// Chrome can't handle huge data passed to `addScriptToEvaluateOnLoad`
|
9
|
-
// https://groups.google.com/a/chromium.org/forum/#!topic/chromium-discuss/U5qyeX_ydBo
|
10
|
-
// The only way is to create temporary files and pass them to chrome.
|
11
|
-
fs.writeFileSync("/tmp/chrome-opal.js", opal_code);
|
12
|
-
fs.writeFileSync("/tmp/chrome-opal.html", "" +
|
13
|
-
"<html>" +
|
14
|
-
"<head>" +
|
15
|
-
"<meta charset='utf-8'>" +
|
16
|
-
"</head>" +
|
17
|
-
"<body>" +
|
18
|
-
"<script src='./chrome-opal.js'></script>" +
|
19
|
-
"</body>" +
|
20
|
-
"</html>"
|
21
|
-
);
|
6
|
+
var dir = fs.readFileSync("/dev/stdin").toString();
|
22
7
|
|
23
8
|
var options = {
|
24
9
|
host: process.env.CHROME_HOST || 'localhost',
|
@@ -89,31 +74,18 @@ CDP(options, function(client) {
|
|
89
74
|
});
|
90
75
|
|
91
76
|
Runtime.exceptionThrown(function(exception) {
|
92
|
-
var
|
93
|
-
|
94
|
-
stackTrace = exceptionDetails.stackTrace ? exceptionDetails.stackTrace.callFrames : [],
|
95
|
-
name, message, trace = [], i;
|
96
|
-
|
77
|
+
var properties = exception.exceptionDetails.exception.preview.properties,
|
78
|
+
stack, i;
|
97
79
|
|
98
80
|
for (i = 0; i < properties.length; i++) {
|
99
81
|
var property = properties[i];
|
100
82
|
|
101
|
-
if (property.name == "
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
if (property.name == "message") {
|
106
|
-
message = property.value;
|
83
|
+
if (property.name == "stack") {
|
84
|
+
stack = property.value;
|
107
85
|
}
|
108
86
|
}
|
109
87
|
|
110
|
-
console.log(
|
111
|
-
|
112
|
-
for (i = 0; i < stackTrace.length; i++) {
|
113
|
-
var raw = stackTrace[i];
|
114
|
-
|
115
|
-
console.log(" at " + raw.functionName + " (" + raw.url + ":" + raw.lineNumber + ":" + raw.columnNumber + ")")
|
116
|
-
}
|
88
|
+
console.log(stack);
|
117
89
|
|
118
90
|
process.exit(1);
|
119
91
|
})
|
@@ -130,6 +102,6 @@ CDP(options, function(client) {
|
|
130
102
|
})
|
131
103
|
});
|
132
104
|
|
133
|
-
Page.navigate({ url:
|
105
|
+
Page.navigate({ url: "file://"+dir+"/index.html" })
|
134
106
|
});
|
135
107
|
});
|