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
@@ -0,0 +1,639 @@
|
|
1
|
+
// IMPORTANT NOTICE:
|
2
|
+
// Remember to update the browser version whenever this file is changed,
|
3
|
+
// to do so, `run bin/build-browser-source-map-support`
|
4
|
+
|
5
|
+
// The following is taken and adapted from the work of Evan Wallace
|
6
|
+
// https://github.com/evanw/node-source-map-support v0.5.12
|
7
|
+
|
8
|
+
// The MIT License (MIT)
|
9
|
+
//
|
10
|
+
// Copyright (c) 2014 Evan Wallace
|
11
|
+
//
|
12
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
13
|
+
// of this software and associated documentation files (the "Software"), to deal
|
14
|
+
// in the Software without restriction, including without limitation the rights
|
15
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
16
|
+
// copies of the Software, and to permit persons to whom the Software is
|
17
|
+
// furnished to do so, subject to the following conditions:
|
18
|
+
//
|
19
|
+
// The above copyright notice and this permission notice shall be included in all
|
20
|
+
// copies or substantial portions of the Software.
|
21
|
+
//
|
22
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
23
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
24
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
25
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
26
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
27
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
28
|
+
// SOFTWARE.
|
29
|
+
|
30
|
+
var SourceMapConsumer = require('source-map').SourceMapConsumer;
|
31
|
+
var path = require('path');
|
32
|
+
|
33
|
+
var fs;
|
34
|
+
try {
|
35
|
+
fs = require('fs');
|
36
|
+
if (!fs.existsSync || !fs.readFileSync) {
|
37
|
+
// fs doesn't have all methods we need
|
38
|
+
fs = null;
|
39
|
+
}
|
40
|
+
} catch (err) {
|
41
|
+
/* nop */
|
42
|
+
}
|
43
|
+
|
44
|
+
var bufferFrom = require('buffer-from');
|
45
|
+
|
46
|
+
// Only install once if called multiple times
|
47
|
+
var errorFormatterInstalled = false;
|
48
|
+
var uncaughtShimInstalled = false;
|
49
|
+
|
50
|
+
// If true, the caches are reset before a stack trace formatting operation
|
51
|
+
var emptyCacheBetweenOperations = false;
|
52
|
+
|
53
|
+
// Supports {browser, node, auto}
|
54
|
+
var environment = "auto";
|
55
|
+
|
56
|
+
// Maps a file path to a string containing the file contents
|
57
|
+
var fileContentsCache = {};
|
58
|
+
|
59
|
+
// Maps a file path to a source map for that file
|
60
|
+
var sourceMapCache = {};
|
61
|
+
|
62
|
+
// Regex for detecting source maps
|
63
|
+
var reSourceMap = /^data:application\/json[^,]+base64,/;
|
64
|
+
|
65
|
+
// Priority list of retrieve handlers
|
66
|
+
var retrieveFileHandlers = [];
|
67
|
+
var retrieveMapHandlers = [];
|
68
|
+
|
69
|
+
function isInBrowser() {
|
70
|
+
if (environment === "browser")
|
71
|
+
return true;
|
72
|
+
if (environment === "node")
|
73
|
+
return false;
|
74
|
+
return ((typeof window !== 'undefined') && (typeof XMLHttpRequest === 'function') && !(window.require && window.module && window.process && window.process.type === "renderer"));
|
75
|
+
}
|
76
|
+
|
77
|
+
function hasGlobalProcessEventEmitter() {
|
78
|
+
return ((typeof process === 'object') && (process !== null) && (typeof process.on === 'function'));
|
79
|
+
}
|
80
|
+
|
81
|
+
function handlerExec(list) {
|
82
|
+
return function(arg) {
|
83
|
+
for (var i = 0; i < list.length; i++) {
|
84
|
+
var ret = list[i](arg);
|
85
|
+
if (ret) {
|
86
|
+
return ret;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
return null;
|
90
|
+
};
|
91
|
+
}
|
92
|
+
|
93
|
+
var retrieveFile = handlerExec(retrieveFileHandlers);
|
94
|
+
|
95
|
+
retrieveFileHandlers.push(function(path) {
|
96
|
+
// Trim the path to make sure there is no extra whitespace.
|
97
|
+
path = path.trim();
|
98
|
+
if (/^file:/.test(path)) {
|
99
|
+
// existsSync/readFileSync can't handle file protocol, but once stripped, it works
|
100
|
+
path = path.replace(/file:\/\/\/(\w:)?/, function(protocol, drive) {
|
101
|
+
return drive ?
|
102
|
+
'' : // file:///C:/dir/file -> C:/dir/file
|
103
|
+
'/'; // file:///root-dir/file -> /root-dir/file
|
104
|
+
});
|
105
|
+
}
|
106
|
+
if (path in fileContentsCache) {
|
107
|
+
return fileContentsCache[path];
|
108
|
+
}
|
109
|
+
|
110
|
+
var contents = '';
|
111
|
+
try {
|
112
|
+
if (!fs) {
|
113
|
+
// Use SJAX if we are in the browser
|
114
|
+
var xhr = new XMLHttpRequest();
|
115
|
+
xhr.open('GET', path, /** async */ false);
|
116
|
+
xhr.send(null);
|
117
|
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
118
|
+
contents = xhr.responseText;
|
119
|
+
}
|
120
|
+
} else if (fs.existsSync(path)) {
|
121
|
+
// Otherwise, use the filesystem
|
122
|
+
contents = fs.readFileSync(path, 'utf8');
|
123
|
+
}
|
124
|
+
} catch (er) {
|
125
|
+
/* ignore any errors */
|
126
|
+
}
|
127
|
+
|
128
|
+
return fileContentsCache[path] = contents;
|
129
|
+
});
|
130
|
+
|
131
|
+
// Support URLs relative to a directory, but be careful about a protocol prefix
|
132
|
+
// in case we are in the browser (i.e. directories may start with "http://" or "file:///")
|
133
|
+
function supportRelativeURL(file, url) {
|
134
|
+
// Force file to null otherwise it will relativize locations to the current file
|
135
|
+
file = null
|
136
|
+
|
137
|
+
if (!file) return url;
|
138
|
+
var dir = path.dirname(file);
|
139
|
+
var match = /^\w+:\/\/[^\/]*/.exec(dir);
|
140
|
+
var protocol = match ? match[0] : '';
|
141
|
+
var startPath = dir.slice(protocol.length);
|
142
|
+
if (protocol && /^\/\w\:/.test(startPath)) {
|
143
|
+
// handle file:///C:/ paths
|
144
|
+
protocol += '/';
|
145
|
+
return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, '/');
|
146
|
+
}
|
147
|
+
return protocol + path.resolve(dir.slice(protocol.length), url);
|
148
|
+
}
|
149
|
+
|
150
|
+
function retrieveSourceMapURL(source) {
|
151
|
+
var fileData;
|
152
|
+
|
153
|
+
if (isInBrowser()) {
|
154
|
+
try {
|
155
|
+
var xhr = new XMLHttpRequest();
|
156
|
+
xhr.open('GET', source, false);
|
157
|
+
xhr.send(null);
|
158
|
+
fileData = xhr.readyState === 4 ? xhr.responseText : null;
|
159
|
+
|
160
|
+
// Support providing a sourceMappingURL via the SourceMap header
|
161
|
+
var sourceMapHeader = xhr.getResponseHeader("SourceMap") ||
|
162
|
+
xhr.getResponseHeader("X-SourceMap");
|
163
|
+
if (sourceMapHeader) {
|
164
|
+
return sourceMapHeader;
|
165
|
+
}
|
166
|
+
} catch (e) {
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
// Get the URL of the source map
|
171
|
+
fileData = retrieveFile(source);
|
172
|
+
var re = /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/)[ \t]*$)/mg;
|
173
|
+
// Keep executing the search to find the *last* sourceMappingURL to avoid
|
174
|
+
// picking up sourceMappingURLs from comments, strings, etc.
|
175
|
+
var lastMatch, match;
|
176
|
+
while (match = re.exec(fileData)) lastMatch = match;
|
177
|
+
if (!lastMatch) return null;
|
178
|
+
return lastMatch[1];
|
179
|
+
};
|
180
|
+
|
181
|
+
// Can be overridden by the retrieveSourceMap option to install. Takes a
|
182
|
+
// generated source filename; returns a {map, optional url} object, or null if
|
183
|
+
// there is no source map. The map field may be either a string or the parsed
|
184
|
+
// JSON object (ie, it must be a valid argument to the SourceMapConsumer
|
185
|
+
// constructor).
|
186
|
+
var retrieveSourceMap = handlerExec(retrieveMapHandlers);
|
187
|
+
retrieveMapHandlers.push(function(source) {
|
188
|
+
var sourceMappingURL = retrieveSourceMapURL(source);
|
189
|
+
if (!sourceMappingURL) return null;
|
190
|
+
|
191
|
+
// Read the contents of the source map
|
192
|
+
var sourceMapData;
|
193
|
+
if (reSourceMap.test(sourceMappingURL)) {
|
194
|
+
// Support source map URL as a data url
|
195
|
+
var rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(',') + 1);
|
196
|
+
sourceMapData = bufferFrom(rawData, "base64").toString();
|
197
|
+
sourceMappingURL = source;
|
198
|
+
} else {
|
199
|
+
// Support source map URLs relative to the source URL
|
200
|
+
sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
|
201
|
+
sourceMapData = retrieveFile(sourceMappingURL);
|
202
|
+
}
|
203
|
+
|
204
|
+
if (!sourceMapData) {
|
205
|
+
return null;
|
206
|
+
}
|
207
|
+
|
208
|
+
return {
|
209
|
+
url: sourceMappingURL,
|
210
|
+
map: sourceMapData
|
211
|
+
};
|
212
|
+
});
|
213
|
+
|
214
|
+
function mapSourcePosition(position) {
|
215
|
+
var sourceMap = sourceMapCache[position.source];
|
216
|
+
if (!sourceMap) {
|
217
|
+
// Call the (overrideable) retrieveSourceMap function to get the source map.
|
218
|
+
var urlAndMap = retrieveSourceMap(position.source);
|
219
|
+
if (urlAndMap) {
|
220
|
+
sourceMap = sourceMapCache[position.source] = {
|
221
|
+
url: urlAndMap.url,
|
222
|
+
map: new SourceMapConsumer(urlAndMap.map)
|
223
|
+
};
|
224
|
+
|
225
|
+
// Load all sources stored inline with the source map into the file cache
|
226
|
+
// to pretend like they are already loaded. They may not exist on disk.
|
227
|
+
if (sourceMap.map.sourcesContent) {
|
228
|
+
sourceMap.map.sources.forEach(function(source, i) {
|
229
|
+
var contents = sourceMap.map.sourcesContent[i];
|
230
|
+
if (contents) {
|
231
|
+
var url = supportRelativeURL(sourceMap.url, source);
|
232
|
+
fileContentsCache[url] = contents;
|
233
|
+
}
|
234
|
+
});
|
235
|
+
}
|
236
|
+
} else {
|
237
|
+
sourceMap = sourceMapCache[position.source] = {
|
238
|
+
url: null,
|
239
|
+
map: null
|
240
|
+
};
|
241
|
+
}
|
242
|
+
}
|
243
|
+
|
244
|
+
// Resolve the source URL relative to the URL of the source map
|
245
|
+
if (sourceMap && sourceMap.map && typeof sourceMap.map.originalPositionFor === 'function') {
|
246
|
+
var originalPosition = sourceMap.map.originalPositionFor(position);
|
247
|
+
|
248
|
+
// Only return the original position if a matching line was found. If no
|
249
|
+
// matching line is found then we return position instead, which will cause
|
250
|
+
// the stack trace to print the path and line for the compiled file. It is
|
251
|
+
// better to give a precise location in the compiled file than a vague
|
252
|
+
// location in the original file.
|
253
|
+
if (originalPosition.source !== null) {
|
254
|
+
originalPosition.source = supportRelativeURL(
|
255
|
+
sourceMap.url, originalPosition.source);
|
256
|
+
return originalPosition;
|
257
|
+
}
|
258
|
+
}
|
259
|
+
|
260
|
+
return position;
|
261
|
+
}
|
262
|
+
|
263
|
+
// Parses code generated by FormatEvalOrigin(), a function inside V8:
|
264
|
+
// https://code.google.com/p/v8/source/browse/trunk/src/messages.js
|
265
|
+
function mapEvalOrigin(origin) {
|
266
|
+
// Most eval() calls are in this format
|
267
|
+
var match = /^eval from ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(origin);
|
268
|
+
if (match) {
|
269
|
+
var position = mapSourcePosition({
|
270
|
+
source: match[2],
|
271
|
+
line: +match[3],
|
272
|
+
column: match[4] - 1
|
273
|
+
});
|
274
|
+
return 'eval from ' + match[1] + ' (' + position.source + ':' +
|
275
|
+
position.line + ':' + (position.column + 1) + ')';
|
276
|
+
}
|
277
|
+
|
278
|
+
// Parse nested eval() calls using recursion
|
279
|
+
match = /^eval from ([^(]+) \((.+)\)$/.exec(origin);
|
280
|
+
if (match) {
|
281
|
+
return 'eval from ' + match[1] + ' (' + mapEvalOrigin(match[2]) + ')';
|
282
|
+
}
|
283
|
+
|
284
|
+
// Make sure we still return useful information if we didn't find anything
|
285
|
+
return origin;
|
286
|
+
}
|
287
|
+
|
288
|
+
// This is copied almost verbatim from the V8 source code at
|
289
|
+
// https://code.google.com/p/v8/source/browse/trunk/src/messages.js. The
|
290
|
+
// implementation of wrapCallSite() used to just forward to the actual source
|
291
|
+
// code of CallSite.prototype.toString but unfortunately a new release of V8
|
292
|
+
// did something to the prototype chain and broke the shim. The only fix I
|
293
|
+
// could find was copy/paste.
|
294
|
+
function CallSiteToString() {
|
295
|
+
var fileName;
|
296
|
+
var fileLocation = "";
|
297
|
+
if (this.isNative()) {
|
298
|
+
fileLocation = "native";
|
299
|
+
} else {
|
300
|
+
fileName = this.getScriptNameOrSourceURL();
|
301
|
+
if (!fileName && this.isEval()) {
|
302
|
+
fileLocation = this.getEvalOrigin();
|
303
|
+
fileLocation += ", "; // Expecting source position to follow.
|
304
|
+
}
|
305
|
+
|
306
|
+
if (fileName) {
|
307
|
+
fileLocation += fileName;
|
308
|
+
} else {
|
309
|
+
// Source code does not originate from a file and is not native, but we
|
310
|
+
// can still get the source position inside the source string, e.g. in
|
311
|
+
// an eval string.
|
312
|
+
fileLocation += "<anonymous>";
|
313
|
+
}
|
314
|
+
|
315
|
+
if (fileLocation.startsWith("corelib/")) {
|
316
|
+
fileLocation = "<internal:" + fileLocation + ">";
|
317
|
+
} else if (fileLocation.endsWith(".js")) {
|
318
|
+
fileLocation = "<js:" + fileLocation + ">";
|
319
|
+
}
|
320
|
+
|
321
|
+
var lineNumber = this.getLineNumber();
|
322
|
+
if (lineNumber != null) {
|
323
|
+
fileLocation += ":" + lineNumber;
|
324
|
+
var columnNumber = this.getColumnNumber();
|
325
|
+
if (columnNumber) {
|
326
|
+
fileLocation += ":" + columnNumber;
|
327
|
+
}
|
328
|
+
}
|
329
|
+
}
|
330
|
+
|
331
|
+
var line = "";
|
332
|
+
var functionName = this.getFunctionName();
|
333
|
+
var addSuffix = true;
|
334
|
+
var isConstructor = this.isConstructor();
|
335
|
+
var isMethodCall = !(this.isToplevel() || isConstructor);
|
336
|
+
if (isMethodCall) {
|
337
|
+
var typeName = this.getTypeName();
|
338
|
+
// Fixes shim to be backward compatable with Node v0 to v4
|
339
|
+
if (typeName === "[object Object]") {
|
340
|
+
typeName = "null";
|
341
|
+
}
|
342
|
+
var methodName = this.getMethodName();
|
343
|
+
if (functionName) {
|
344
|
+
if (functionName.startsWith("$")) {
|
345
|
+
functionName = functionName.slice(1);
|
346
|
+
}
|
347
|
+
if (typeName && functionName.indexOf(typeName) != 0) {
|
348
|
+
line += typeName + ".";
|
349
|
+
}
|
350
|
+
line += functionName;
|
351
|
+
if (methodName && functionName.indexOf("." + methodName) != functionName.length - methodName.length - 1) {
|
352
|
+
line += " [as " + methodName + "]";
|
353
|
+
}
|
354
|
+
} else {
|
355
|
+
line += typeName + "." + (methodName || "<anonymous>");
|
356
|
+
}
|
357
|
+
} else if (isConstructor) {
|
358
|
+
line += "new " + (functionName || "<anonymous>");
|
359
|
+
} else if (functionName) {
|
360
|
+
line += functionName;
|
361
|
+
} else {
|
362
|
+
line += fileLocation;
|
363
|
+
addSuffix = false;
|
364
|
+
}
|
365
|
+
if (addSuffix) {
|
366
|
+
line += " (" + fileLocation + ")";
|
367
|
+
}
|
368
|
+
line = fileLocation + ":in `" + (functionName || methodName) + "'"
|
369
|
+
return line;
|
370
|
+
}
|
371
|
+
|
372
|
+
function cloneCallSite(frame) {
|
373
|
+
var object = {};
|
374
|
+
Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach(function(name) {
|
375
|
+
object[name] = /^(?:is|get)/.test(name) ? function() { return frame[name].call(frame); } : frame[name];
|
376
|
+
});
|
377
|
+
object.toString = CallSiteToString;
|
378
|
+
return object;
|
379
|
+
}
|
380
|
+
|
381
|
+
function wrapCallSite(frame) {
|
382
|
+
if(frame.isNative()) {
|
383
|
+
return frame;
|
384
|
+
}
|
385
|
+
|
386
|
+
// Most call sites will return the source file from getFileName(), but code
|
387
|
+
// passed to eval() ending in "//# sourceURL=..." will return the source file
|
388
|
+
// from getScriptNameOrSourceURL() instead
|
389
|
+
var source = frame.getFileName() || frame.getScriptNameOrSourceURL();
|
390
|
+
if (source) {
|
391
|
+
var line = frame.getLineNumber();
|
392
|
+
var column = frame.getColumnNumber() - 1;
|
393
|
+
|
394
|
+
// Fix position in Node where some (internal) code is prepended.
|
395
|
+
// See https://github.com/evanw/node-source-map-support/issues/36
|
396
|
+
var headerLength = 62;
|
397
|
+
if (line === 1 && column > headerLength && !isInBrowser() && !frame.isEval()) {
|
398
|
+
column -= headerLength;
|
399
|
+
}
|
400
|
+
|
401
|
+
var position = mapSourcePosition({
|
402
|
+
source: source,
|
403
|
+
line: line,
|
404
|
+
column: column
|
405
|
+
});
|
406
|
+
frame = cloneCallSite(frame);
|
407
|
+
var originalFunctionName = frame.getFunctionName;
|
408
|
+
frame.getFunctionName = function() { return position.name || originalFunctionName(); };
|
409
|
+
frame.getFileName = function() { return position.source; };
|
410
|
+
frame.getLineNumber = function() { return position.line; };
|
411
|
+
frame.getColumnNumber = function() { return position.column + 1; };
|
412
|
+
frame.getScriptNameOrSourceURL = function() { return position.source; };
|
413
|
+
return frame;
|
414
|
+
}
|
415
|
+
|
416
|
+
// Code called using eval() needs special handling
|
417
|
+
var origin = frame.isEval() && frame.getEvalOrigin();
|
418
|
+
if (origin) {
|
419
|
+
origin = mapEvalOrigin(origin);
|
420
|
+
frame = cloneCallSite(frame);
|
421
|
+
frame.getEvalOrigin = function() { return origin; };
|
422
|
+
return frame;
|
423
|
+
}
|
424
|
+
|
425
|
+
// If we get here then we were unable to change the source position
|
426
|
+
return frame;
|
427
|
+
}
|
428
|
+
|
429
|
+
// This function is part of the V8 stack trace API, for more info see:
|
430
|
+
// https://v8.dev/docs/stack-trace-api
|
431
|
+
function prepareStackTrace(error, stack) {
|
432
|
+
if (emptyCacheBetweenOperations) {
|
433
|
+
fileContentsCache = {};
|
434
|
+
sourceMapCache = {};
|
435
|
+
}
|
436
|
+
|
437
|
+
var name = error.name || 'Error';
|
438
|
+
var message = error.message || '';
|
439
|
+
var errorString = name + ": " + message;
|
440
|
+
|
441
|
+
return errorString + stack.map(function(frame) {
|
442
|
+
return '\n from ' + wrapCallSite(frame);
|
443
|
+
}).join('');
|
444
|
+
}
|
445
|
+
|
446
|
+
// Generate position and snippet of original source with pointer
|
447
|
+
function getErrorSource(error) {
|
448
|
+
var match = /\n from [^(]+ \((.*):(\d+):(\d+)\)/.exec(error.stack);
|
449
|
+
if (match) {
|
450
|
+
var source = match[1];
|
451
|
+
var line = +match[2];
|
452
|
+
var column = +match[3];
|
453
|
+
|
454
|
+
// Support the inline sourceContents inside the source map
|
455
|
+
var contents = fileContentsCache[source];
|
456
|
+
|
457
|
+
// Support files on disk
|
458
|
+
if (!contents && fs && fs.existsSync(source)) {
|
459
|
+
try {
|
460
|
+
contents = fs.readFileSync(source, 'utf8');
|
461
|
+
} catch (er) {
|
462
|
+
contents = '';
|
463
|
+
}
|
464
|
+
}
|
465
|
+
|
466
|
+
// Format the line from the original source code like node does
|
467
|
+
if (contents) {
|
468
|
+
var code = contents.split(/(?:\r\n|\r|\n)/)[line - 1];
|
469
|
+
if (code) {
|
470
|
+
return source + ':' + line + '\n' + code + '\n' +
|
471
|
+
new Array(column).join(' ') + '^';
|
472
|
+
}
|
473
|
+
}
|
474
|
+
}
|
475
|
+
return null;
|
476
|
+
}
|
477
|
+
|
478
|
+
function printErrorAndExit (error) {
|
479
|
+
var source = getErrorSource(error);
|
480
|
+
|
481
|
+
// Ensure error is printed synchronously and not truncated
|
482
|
+
if (process.stderr._handle && process.stderr._handle.setBlocking) {
|
483
|
+
process.stderr._handle.setBlocking(true);
|
484
|
+
}
|
485
|
+
|
486
|
+
if (source) {
|
487
|
+
console.error();
|
488
|
+
console.error(source);
|
489
|
+
}
|
490
|
+
|
491
|
+
console.error(error.stack);
|
492
|
+
process.exit(1);
|
493
|
+
}
|
494
|
+
|
495
|
+
function shimEmitUncaughtException () {
|
496
|
+
var origEmit = process.emit;
|
497
|
+
|
498
|
+
process.emit = function (type) {
|
499
|
+
if (type === 'uncaughtException') {
|
500
|
+
var hasStack = (arguments[1] && arguments[1].stack);
|
501
|
+
var hasListeners = (this.listeners(type).length > 0);
|
502
|
+
|
503
|
+
if (hasStack && !hasListeners) {
|
504
|
+
return printErrorAndExit(arguments[1]);
|
505
|
+
}
|
506
|
+
}
|
507
|
+
|
508
|
+
return origEmit.apply(this, arguments);
|
509
|
+
};
|
510
|
+
}
|
511
|
+
|
512
|
+
var originalRetrieveFileHandlers = retrieveFileHandlers.slice(0);
|
513
|
+
var originalRetrieveMapHandlers = retrieveMapHandlers.slice(0);
|
514
|
+
|
515
|
+
exports.wrapCallSite = wrapCallSite;
|
516
|
+
exports.getErrorSource = getErrorSource;
|
517
|
+
exports.mapSourcePosition = mapSourcePosition;
|
518
|
+
exports.retrieveSourceMap = retrieveSourceMap;
|
519
|
+
|
520
|
+
exports.install = function(options) {
|
521
|
+
options = options || {};
|
522
|
+
|
523
|
+
if (options.environment) {
|
524
|
+
environment = options.environment;
|
525
|
+
if (["node", "browser", "auto"].indexOf(environment) === -1) {
|
526
|
+
throw new Error("environment " + environment + " was unknown. Available options are {auto, browser, node}")
|
527
|
+
}
|
528
|
+
}
|
529
|
+
|
530
|
+
// Allow sources to be found by methods other than reading the files
|
531
|
+
// directly from disk.
|
532
|
+
if (options.retrieveFile) {
|
533
|
+
if (options.overrideRetrieveFile) {
|
534
|
+
retrieveFileHandlers.length = 0;
|
535
|
+
}
|
536
|
+
|
537
|
+
retrieveFileHandlers.unshift(options.retrieveFile);
|
538
|
+
}
|
539
|
+
|
540
|
+
// Allow source maps to be found by methods other than reading the files
|
541
|
+
// directly from disk.
|
542
|
+
if (options.retrieveSourceMap) {
|
543
|
+
if (options.overrideRetrieveSourceMap) {
|
544
|
+
retrieveMapHandlers.length = 0;
|
545
|
+
}
|
546
|
+
|
547
|
+
retrieveMapHandlers.unshift(options.retrieveSourceMap);
|
548
|
+
}
|
549
|
+
|
550
|
+
// Support runtime transpilers that include inline source maps
|
551
|
+
if (options.hookRequire && !isInBrowser()) {
|
552
|
+
var Module;
|
553
|
+
try {
|
554
|
+
Module = require('module');
|
555
|
+
} catch (err) {
|
556
|
+
// NOP: Loading in catch block to convert webpack error to warning.
|
557
|
+
}
|
558
|
+
var $compile = Module.prototype._compile;
|
559
|
+
|
560
|
+
if (!$compile.__sourceMapSupport) {
|
561
|
+
Module.prototype._compile = function(content, filename) {
|
562
|
+
fileContentsCache[filename] = content;
|
563
|
+
sourceMapCache[filename] = undefined;
|
564
|
+
return $compile.call(this, content, filename);
|
565
|
+
};
|
566
|
+
|
567
|
+
Module.prototype._compile.__sourceMapSupport = true;
|
568
|
+
}
|
569
|
+
}
|
570
|
+
|
571
|
+
// Configure options
|
572
|
+
if (!emptyCacheBetweenOperations) {
|
573
|
+
emptyCacheBetweenOperations = 'emptyCacheBetweenOperations' in options ?
|
574
|
+
options.emptyCacheBetweenOperations : false;
|
575
|
+
}
|
576
|
+
|
577
|
+
// Install the error reformatter
|
578
|
+
if (!errorFormatterInstalled) {
|
579
|
+
errorFormatterInstalled = true;
|
580
|
+
Error.prepareStackTrace = prepareStackTrace;
|
581
|
+
}
|
582
|
+
|
583
|
+
if (!uncaughtShimInstalled) {
|
584
|
+
var installHandler = 'handleUncaughtExceptions' in options ?
|
585
|
+
options.handleUncaughtExceptions : true;
|
586
|
+
|
587
|
+
// Provide the option to not install the uncaught exception handler. This is
|
588
|
+
// to support other uncaught exception handlers (in test frameworks, for
|
589
|
+
// example). If this handler is not installed and there are no other uncaught
|
590
|
+
// exception handlers, uncaught exceptions will be caught by node's built-in
|
591
|
+
// exception handler and the process will still be terminated. However, the
|
592
|
+
// generated JavaScript code will be shown above the stack trace instead of
|
593
|
+
// the original source code.
|
594
|
+
if (installHandler && hasGlobalProcessEventEmitter()) {
|
595
|
+
uncaughtShimInstalled = true;
|
596
|
+
shimEmitUncaughtException();
|
597
|
+
}
|
598
|
+
}
|
599
|
+
};
|
600
|
+
|
601
|
+
exports.resetRetrieveHandlers = function() {
|
602
|
+
retrieveFileHandlers.length = 0;
|
603
|
+
retrieveMapHandlers.length = 0;
|
604
|
+
|
605
|
+
retrieveFileHandlers = originalRetrieveFileHandlers.slice(0);
|
606
|
+
retrieveMapHandlers = originalRetrieveMapHandlers.slice(0);
|
607
|
+
|
608
|
+
retrieveSourceMap = handlerExec(retrieveMapHandlers);
|
609
|
+
retrieveFile = handlerExec(retrieveFileHandlers);
|
610
|
+
}
|
611
|
+
|
612
|
+
// Autoinstall.
|
613
|
+
exports.install();
|
614
|
+
|
615
|
+
// Regenerate the browser version with:
|
616
|
+
// browserify lib/opal/cli_runners/source-map-support.js -s sourceMapSupport | uglifyjs -c > lib/opal/cli_runners/source-map-support-browser.js
|
617
|
+
|
618
|
+
// = Stacktrace Examples:
|
619
|
+
//
|
620
|
+
// == Traditional Ruby stacktrace:
|
621
|
+
//
|
622
|
+
// /Users/elia/Code/opal/lib/opal/cli_runners/system_runner.rb:43:in `call': unhandled exception
|
623
|
+
// from /Users/elia/Code/opal/lib/opal/cli_runners/nodejs.rb:14:in `call'
|
624
|
+
// from /Users/elia/Code/opal/lib/opal/cli_runners.rb:50:in `block in register_runner'
|
625
|
+
// from /Users/elia/Code/opal/lib/opal/cli.rb:62:in `run'
|
626
|
+
// from /Users/elia/Code/opal/exe/opal:24:in `<top (required)>'
|
627
|
+
// from bin/opal:4:in `load'
|
628
|
+
// from bin/opal:4:in `<main>'
|
629
|
+
//
|
630
|
+
// == Traceback style:
|
631
|
+
//
|
632
|
+
// Traceback (most recent call last):
|
633
|
+
// 6: from bin/opal:4:in `<main>'
|
634
|
+
// 5: from bin/opal:4:in `load'
|
635
|
+
// 4: from /Users/elia/Code/opal/exe/opal:24:in `<top (required)>'
|
636
|
+
// 3: from /Users/elia/Code/opal/lib/opal/cli.rb:62:in `run'
|
637
|
+
// 2: from /Users/elia/Code/opal/lib/opal/cli_runners.rb:50:in `block in register_runner'
|
638
|
+
// 1: from /Users/elia/Code/opal/lib/opal/cli_runners/nodejs.rb:14:in `call'
|
639
|
+
// /Users/elia/Code/opal/lib/opal/cli_runners/system_runner.rb:43:in `call': unhandled exception
|