opal-cj 0.7.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.gitmodules +27 -0
- data/.rspec +3 -0
- data/.spectator +2 -0
- data/.spectator-mspec +3 -0
- data/.travis.yml +45 -0
- data/CHANGELOG.md +406 -0
- data/CONTRIBUTING.md +41 -0
- data/Gemfile +27 -0
- data/Guardfile +77 -0
- data/LICENSE +19 -0
- data/README.md +178 -0
- data/Rakefile +116 -0
- data/benchmarks/operators.rb +11 -0
- data/bin/opal +22 -0
- data/bin/opal-build +77 -0
- data/bin/opal-mspec +10 -0
- data/bin/opal-repl +72 -0
- data/config.ru +14 -0
- data/examples/rack/Gemfile +3 -0
- data/examples/rack/app/application.rb +13 -0
- data/examples/rack/app/user.rb +21 -0
- data/examples/rack/config.ru +7 -0
- data/examples/rack/index.html.erb +10 -0
- data/examples/sinatra/Gemfile +4 -0
- data/examples/sinatra/app/application.rb +7 -0
- data/examples/sinatra/config.ru +28 -0
- data/lib/mspec/opal/main.rb.erb +9 -0
- data/lib/mspec/opal/rake_task.rb +278 -0
- data/lib/mspec/opal/runner.rb +206 -0
- data/lib/mspec/opal/sprockets.js +57 -0
- data/lib/opal.rb +11 -0
- data/lib/opal/builder.rb +135 -0
- data/lib/opal/builder_processors.rb +165 -0
- data/lib/opal/cli.rb +145 -0
- data/lib/opal/cli_options.rb +149 -0
- data/lib/opal/cli_runners.rb +10 -0
- data/lib/opal/cli_runners/nodejs.rb +56 -0
- data/lib/opal/cli_runners/phantom.js +35 -0
- data/lib/opal/cli_runners/phantomjs.rb +28 -0
- data/lib/opal/cli_runners/server.rb +54 -0
- data/lib/opal/compiler.rb +307 -0
- data/lib/opal/erb.rb +64 -0
- data/lib/opal/fragment.rb +41 -0
- data/lib/opal/hike_path_finder.rb +18 -0
- data/lib/opal/nodes.rb +26 -0
- data/lib/opal/nodes/arglist.rb +56 -0
- data/lib/opal/nodes/array.rb +54 -0
- data/lib/opal/nodes/base.rb +151 -0
- data/lib/opal/nodes/call.rb +283 -0
- data/lib/opal/nodes/call_special.rb +178 -0
- data/lib/opal/nodes/case.rb +96 -0
- data/lib/opal/nodes/class.rb +42 -0
- data/lib/opal/nodes/constants.rb +78 -0
- data/lib/opal/nodes/def.rb +157 -0
- data/lib/opal/nodes/defined.rb +113 -0
- data/lib/opal/nodes/definitions.rb +168 -0
- data/lib/opal/nodes/for.rb +35 -0
- data/lib/opal/nodes/hash.rb +67 -0
- data/lib/opal/nodes/helpers.rb +114 -0
- data/lib/opal/nodes/if.rb +67 -0
- data/lib/opal/nodes/iter.rb +131 -0
- data/lib/opal/nodes/literal.rb +230 -0
- data/lib/opal/nodes/logic.rb +217 -0
- data/lib/opal/nodes/masgn.rb +62 -0
- data/lib/opal/nodes/module.rb +46 -0
- data/lib/opal/nodes/rescue.rb +135 -0
- data/lib/opal/nodes/runtime_helpers.rb +45 -0
- data/lib/opal/nodes/scope.rb +293 -0
- data/lib/opal/nodes/singleton_class.rb +25 -0
- data/lib/opal/nodes/super.rb +97 -0
- data/lib/opal/nodes/top.rb +101 -0
- data/lib/opal/nodes/variables.rb +158 -0
- data/lib/opal/nodes/while.rb +65 -0
- data/lib/opal/nodes/yield.rb +95 -0
- data/lib/opal/parser.rb +658 -0
- data/lib/opal/parser/grammar.rb +5452 -0
- data/lib/opal/parser/grammar.y +1684 -0
- data/lib/opal/parser/keywords.rb +66 -0
- data/lib/opal/parser/lexer.rb +1208 -0
- data/lib/opal/parser/parser_scope.rb +25 -0
- data/lib/opal/parser/sexp.rb +75 -0
- data/lib/opal/path_reader.rb +28 -0
- data/lib/opal/paths.rb +38 -0
- data/lib/opal/source_map.rb +70 -0
- data/lib/opal/sprockets.rb +4 -0
- data/lib/opal/sprockets/cache_key_fix.rb +17 -0
- data/lib/opal/sprockets/environment.rb +37 -0
- data/lib/opal/sprockets/erb.rb +37 -0
- data/lib/opal/sprockets/path_reader.rb +34 -0
- data/lib/opal/sprockets/processor.rb +124 -0
- data/lib/opal/sprockets/server.rb +180 -0
- data/lib/opal/util.rb +64 -0
- data/lib/opal/version.rb +3 -0
- data/opal.gemspec +36 -0
- data/opal/README.md +6 -0
- data/opal/corelib/array.rb +1556 -0
- data/opal/corelib/array/inheritance.rb +113 -0
- data/opal/corelib/basic_object.rb +73 -0
- data/opal/corelib/boolean.rb +41 -0
- data/opal/corelib/class.rb +55 -0
- data/opal/corelib/comparable.rb +56 -0
- data/opal/corelib/complex.rb +3 -0
- data/opal/corelib/dir.rb +20 -0
- data/opal/corelib/enumerable.rb +1132 -0
- data/opal/corelib/enumerator.rb +422 -0
- data/opal/corelib/error.rb +63 -0
- data/opal/corelib/file.rb +56 -0
- data/opal/corelib/hash.rb +728 -0
- data/opal/corelib/helpers.rb +102 -0
- data/opal/corelib/io.rb +59 -0
- data/opal/corelib/kernel.rb +569 -0
- data/opal/corelib/main.rb +7 -0
- data/opal/corelib/match_data.rb +114 -0
- data/opal/corelib/method.rb +58 -0
- data/opal/corelib/module.rb +462 -0
- data/opal/corelib/nil_class.rb +62 -0
- data/opal/corelib/numeric.rb +532 -0
- data/opal/corelib/proc.rb +52 -0
- data/opal/corelib/range.rb +116 -0
- data/opal/corelib/rational.rb +3 -0
- data/opal/corelib/regexp.rb +133 -0
- data/opal/corelib/runtime.js +1240 -0
- data/opal/corelib/string.rb +1212 -0
- data/opal/corelib/string/inheritance.rb +78 -0
- data/opal/corelib/struct.rb +141 -0
- data/opal/corelib/time.rb +584 -0
- data/opal/corelib/variables.rb +24 -0
- data/opal/opal.rb +32 -0
- data/package.json +9 -0
- data/spec/filters/bugs/array.rb +232 -0
- data/spec/filters/bugs/basic_object.rb +14 -0
- data/spec/filters/bugs/class.rb +21 -0
- data/spec/filters/bugs/enumerable.rb +69 -0
- data/spec/filters/bugs/enumerator.rb +3 -0
- data/spec/filters/bugs/hash.rb +128 -0
- data/spec/filters/bugs/kernel.rb +10 -0
- data/spec/filters/bugs/language.rb +415 -0
- data/spec/filters/bugs/math.rb +95 -0
- data/spec/filters/bugs/module.rb +14 -0
- data/spec/filters/bugs/nil.rb +7 -0
- data/spec/filters/bugs/numeric.rb +20 -0
- data/spec/filters/bugs/opal.rb +14 -0
- data/spec/filters/bugs/regexp.rb +11 -0
- data/spec/filters/bugs/set.rb +7 -0
- data/spec/filters/bugs/singleton.rb +6 -0
- data/spec/filters/bugs/string.rb +360 -0
- data/spec/filters/bugs/stringscanner.rb +22 -0
- data/spec/filters/bugs/struct.rb +45 -0
- data/spec/filters/bugs/time.rb +177 -0
- data/spec/filters/bugs/unknown.rb +11 -0
- data/spec/filters/unsupported/encoding.rb +95 -0
- data/spec/filters/unsupported/enumerator.rb +14 -0
- data/spec/filters/unsupported/float.rb +5 -0
- data/spec/filters/unsupported/frozen.rb +90 -0
- data/spec/filters/unsupported/hash_compare_by_identity.rb +16 -0
- data/spec/filters/unsupported/integer_size.rb +7 -0
- data/spec/filters/unsupported/method_added.rb +10 -0
- data/spec/filters/unsupported/mutable_strings.rb +361 -0
- data/spec/filters/unsupported/private_constants.rb +30 -0
- data/spec/filters/unsupported/private_methods.rb +44 -0
- data/spec/filters/unsupported/random.rb +4 -0
- data/spec/filters/unsupported/ruby_exe.rb +5 -0
- data/spec/filters/unsupported/tainted.rb +155 -0
- data/spec/filters/unsupported/time.rb +21 -0
- data/spec/filters/unsupported/trusted.rb +80 -0
- data/spec/lib/builder_processors_spec.rb +27 -0
- data/spec/lib/builder_spec.rb +66 -0
- data/spec/lib/cli_spec.rb +134 -0
- data/spec/lib/compiler_spec.rb +197 -0
- data/spec/lib/dependency_resolver_spec.rb +40 -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_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/sprockets_file.js.rb +3 -0
- data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
- data/spec/lib/hike_path_finder_spec.rb +23 -0
- data/spec/lib/lexer_spec.rb +110 -0
- data/spec/lib/parser/alias_spec.rb +26 -0
- data/spec/lib/parser/and_spec.rb +13 -0
- data/spec/lib/parser/attrasgn_spec.rb +28 -0
- data/spec/lib/parser/begin_spec.rb +42 -0
- data/spec/lib/parser/block_spec.rb +12 -0
- data/spec/lib/parser/break_spec.rb +17 -0
- data/spec/lib/parser/call_spec.rb +139 -0
- data/spec/lib/parser/class_spec.rb +35 -0
- data/spec/lib/parser/comments_spec.rb +11 -0
- data/spec/lib/parser/def_spec.rb +61 -0
- data/spec/lib/parser/if_spec.rb +26 -0
- data/spec/lib/parser/iter_spec.rb +59 -0
- data/spec/lib/parser/lambda_spec.rb +64 -0
- data/spec/lib/parser/literal_spec.rb +118 -0
- data/spec/lib/parser/masgn_spec.rb +37 -0
- data/spec/lib/parser/module_spec.rb +27 -0
- data/spec/lib/parser/not_spec.rb +27 -0
- data/spec/lib/parser/op_asgn1_spec.rb +23 -0
- data/spec/lib/parser/op_asgn2_spec.rb +23 -0
- data/spec/lib/parser/or_spec.rb +13 -0
- data/spec/lib/parser/return_spec.rb +17 -0
- data/spec/lib/parser/sclass_spec.rb +21 -0
- data/spec/lib/parser/string_spec.rb +276 -0
- data/spec/lib/parser/super_spec.rb +20 -0
- data/spec/lib/parser/unary_spec.rb +48 -0
- data/spec/lib/parser/undef_spec.rb +15 -0
- data/spec/lib/parser/unless_spec.rb +13 -0
- data/spec/lib/parser/variables_spec.rb +92 -0
- data/spec/lib/parser/while_spec.rb +15 -0
- data/spec/lib/parser/yield_spec.rb +20 -0
- data/spec/lib/path_reader_spec.rb +24 -0
- data/spec/lib/shared/path_finder_shared.rb +19 -0
- data/spec/lib/shared/path_reader_shared.rb +31 -0
- data/spec/lib/spec_helper.rb +9 -0
- data/spec/lib/sprockets/environment_spec.rb +30 -0
- data/spec/lib/sprockets/erb_spec.rb +25 -0
- data/spec/lib/sprockets/path_reader_spec.rb +25 -0
- data/spec/lib/sprockets/processor_spec.rb +35 -0
- data/spec/lib/sprockets/server_spec.rb +20 -0
- data/spec/opal/compiler/irb_spec.rb +44 -0
- data/spec/opal/core/array/select_spec.rb +14 -0
- data/spec/opal/core/array/set_range_to_array_spec.rb +7 -0
- data/spec/opal/core/date_spec.rb +122 -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.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/fixtures/class.rb +124 -0
- data/spec/opal/core/fixtures/class_variables.rb +0 -0
- data/spec/opal/core/fixtures/constants.rb +33 -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/kernel/Array_spec.rb +10 -0
- data/spec/opal/core/kernel/block_given_spec.rb +30 -0
- data/spec/opal/core/kernel/class_spec.rb +6 -0
- data/spec/opal/core/kernel/define_singleton_method_spec.rb +21 -0
- data/spec/opal/core/kernel/equal_value_spec.rb +12 -0
- data/spec/opal/core/kernel/extend_spec.rb +21 -0
- data/spec/opal/core/kernel/format_spec.rb +122 -0
- data/spec/opal/core/kernel/freeze_spec.rb +15 -0
- data/spec/opal/core/kernel/instance_eval_spec.rb +28 -0
- data/spec/opal/core/kernel/instance_variable_defined_spec.rb +15 -0
- data/spec/opal/core/kernel/instance_variable_get_spec.rb +14 -0
- data/spec/opal/core/kernel/instance_variable_set_spec.rb +10 -0
- data/spec/opal/core/kernel/loop_spec.rb +23 -0
- data/spec/opal/core/kernel/match_spec.rb +5 -0
- data/spec/opal/core/kernel/method_spec.rb +31 -0
- data/spec/opal/core/kernel/methods_spec.rb +25 -0
- data/spec/opal/core/kernel/nil_spec.rb +7 -0
- data/spec/opal/core/kernel/p_spec.rb +15 -0
- data/spec/opal/core/kernel/printf_spec.rb +11 -0
- data/spec/opal/core/kernel/proc_spec.rb +13 -0
- data/spec/opal/core/kernel/rand_spec.rb +23 -0
- data/spec/opal/core/kernel/require_tree_spec.rb +7 -0
- data/spec/opal/core/kernel/respond_to_spec.rb +41 -0
- data/spec/opal/core/kernel/send_spec.rb +56 -0
- data/spec/opal/core/kernel/sprintf_spec.rb +5 -0
- data/spec/opal/core/language/block_spec.rb +538 -0
- data/spec/opal/core/language/fixtures/array.rb +11 -0
- data/spec/opal/core/language/fixtures/block.rb +57 -0
- data/spec/opal/core/language/fixtures/break.rb +240 -0
- data/spec/opal/core/language/fixtures/ensure.rb +72 -0
- data/spec/opal/core/language/fixtures/literal_lambda.rb +7 -0
- data/spec/opal/core/language/fixtures/metaclass.rb +33 -0
- data/spec/opal/core/language/fixtures/module.rb +24 -0
- data/spec/opal/core/language/fixtures/next.rb +128 -0
- data/spec/opal/core/language/fixtures/return.rb +118 -0
- data/spec/opal/core/language/fixtures/send.rb +110 -0
- data/spec/opal/core/language/fixtures/send_1.9.rb +22 -0
- data/spec/opal/core/language/fixtures/super.rb +308 -0
- data/spec/opal/core/language/fixtures/variables.rb +58 -0
- data/spec/opal/core/language/fixtures/yield.rb +28 -0
- data/spec/opal/core/language/predefined_spec.rb +85 -0
- data/spec/opal/core/language/proc_spec.rb +263 -0
- data/spec/opal/core/language/regexp_spec.rb +20 -0
- data/spec/opal/core/language/send_spec.rb +225 -0
- data/spec/opal/core/language/string_spec.rb +44 -0
- data/spec/opal/core/language/symbol_spec.rb +40 -0
- data/spec/opal/core/language/variables_spec.rb +1366 -0
- data/spec/opal/core/language/versions/array_1.9.rb +39 -0
- data/spec/opal/core/language/versions/block_1.9.rb +0 -0
- data/spec/opal/core/language/versions/break_1.9.rb +0 -0
- data/spec/opal/core/language/versions/case_1.9.rb +20 -0
- data/spec/opal/core/language/versions/hash_1.9.rb +18 -0
- data/spec/opal/core/language/versions/literal_lambda_1.9.rb +143 -0
- data/spec/opal/core/language/versions/not_1.9.rb +22 -0
- data/spec/opal/core/language/versions/send_1.9.rb +241 -0
- data/spec/opal/core/language/versions/symbol_1.9.rb +15 -0
- data/spec/opal/core/language/versions/variables_1.9.rb +8 -0
- data/spec/opal/core/module/alias_method_spec.rb +28 -0
- data/spec/opal/core/module/ancestors_spec.rb +11 -0
- data/spec/opal/core/module/append_features_spec.rb +14 -0
- data/spec/opal/core/module/attr_accessor_spec.rb +26 -0
- data/spec/opal/core/module/const_defined_spec.rb +85 -0
- data/spec/opal/core/module/const_get_spec.rb +85 -0
- data/spec/opal/core/module/const_missing_spec.rb +17 -0
- data/spec/opal/core/module/const_set_spec.rb +64 -0
- data/spec/opal/core/module/constants_spec.rb +49 -0
- data/spec/opal/core/module/fixtures/classes.rb +434 -0
- data/spec/opal/core/module/method_defined_spec.rb +48 -0
- data/spec/opal/core/module/module_function_spec.rb +25 -0
- data/spec/opal/core/module/name_spec.rb +52 -0
- data/spec/opal/core/module/public_method_defined_spec.rb +18 -0
- data/spec/opal/core/module/remove_const_spec.rb +22 -0
- data/spec/opal/core/module/undef_method_spec.rb +66 -0
- data/spec/opal/core/numeric/bit_and_spec.rb +7 -0
- data/spec/opal/core/numeric/bit_or_spec.rb +8 -0
- data/spec/opal/core/numeric/bit_xor_spec.rb +6 -0
- data/spec/opal/core/numeric/ceil_spec.rb +8 -0
- data/spec/opal/core/numeric/chr_spec.rb +8 -0
- data/spec/opal/core/numeric/comparison_spec.rb +24 -0
- data/spec/opal/core/numeric/complement_spec.rb +8 -0
- data/spec/opal/core/numeric/divide_spec.rb +10 -0
- data/spec/opal/core/numeric/eql_spec.rb +9 -0
- data/spec/opal/core/numeric/exponent_spec.rb +33 -0
- data/spec/opal/core/numeric/floor_spec.rb +8 -0
- data/spec/opal/core/numeric/gt_spec.rb +11 -0
- data/spec/opal/core/numeric/gte_spec.rb +12 -0
- data/spec/opal/core/numeric/integer_spec.rb +9 -0
- data/spec/opal/core/numeric/left_shift_spec.rb +21 -0
- data/spec/opal/core/numeric/lt_spec.rb +11 -0
- data/spec/opal/core/numeric/lte_spec.rb +12 -0
- data/spec/opal/core/numeric/minus_spec.rb +8 -0
- data/spec/opal/core/numeric/modulo_spec.rb +19 -0
- data/spec/opal/core/numeric/multiply_spec.rb +9 -0
- data/spec/opal/core/numeric/next_spec.rb +9 -0
- data/spec/opal/core/numeric/ord_spec.rb +9 -0
- data/spec/opal/core/numeric/plus_spec.rb +8 -0
- data/spec/opal/core/numeric/pred_spec.rb +7 -0
- data/spec/opal/core/numeric/right_shift_spec.rb +25 -0
- data/spec/opal/core/numeric/step_spec.rb +11 -0
- data/spec/opal/core/numeric/succ_spec.rb +9 -0
- data/spec/opal/core/numeric/times_spec.rb +36 -0
- data/spec/opal/core/numeric/to_f_spec.rb +7 -0
- data/spec/opal/core/numeric/to_i_spec.rb +7 -0
- data/spec/opal/core/numeric/to_json_spec.rb +8 -0
- data/spec/opal/core/numeric/to_s_spec.rb +26 -0
- data/spec/opal/core/numeric/uminus_spec.rb +9 -0
- data/spec/opal/core/numeric/upto_spec.rb +19 -0
- data/spec/opal/core/numeric/zero_spec.rb +7 -0
- data/spec/opal/core/proc/call_spec.rb +21 -0
- data/spec/opal/core/proc/element_reference_spec.rb +21 -0
- data/spec/opal/core/proc/proc_tricks_spec.rb +7 -0
- data/spec/opal/core/runtime/begin_spec.rb +39 -0
- data/spec/opal/core/runtime/block_send_spec.rb +28 -0
- data/spec/opal/core/runtime/block_spec.rb +23 -0
- data/spec/opal/core/runtime/bridged_classes_spec.rb +64 -0
- data/spec/opal/core/runtime/constants_spec.rb +13 -0
- data/spec/opal/core/runtime/eval_spec.rb +5 -0
- data/spec/opal/core/runtime/main_methods_spec.rb +27 -0
- data/spec/opal/core/runtime/method_missing_spec.rb +62 -0
- data/spec/opal/core/runtime/method_spec.rb +31 -0
- data/spec/opal/core/runtime/operator_call_spec.rb +13 -0
- data/spec/opal/core/runtime/paren_spec.rb +14 -0
- data/spec/opal/core/runtime/rescue_spec.rb +38 -0
- data/spec/opal/core/runtime/return_spec.rb +38 -0
- data/spec/opal/core/runtime/send_spec.rb +34 -0
- data/spec/opal/core/runtime/singleton_class_spec.rb +13 -0
- data/spec/opal/core/runtime/super_spec.rb +212 -0
- data/spec/opal/core/runtime/truthy_spec.rb +23 -0
- data/spec/opal/core/runtime/variables_spec.rb +20 -0
- data/spec/opal/core/source_map_spec.rb +15 -0
- data/spec/opal/core/string_spec.rb +11 -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/json/ext_spec.rb +48 -0
- data/spec/opal/stdlib/json/parse_spec.rb +33 -0
- data/spec/opal/stdlib/native/alias_native_spec.rb +27 -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/initialize_spec.rb +17 -0
- data/spec/opal/stdlib/native/method_missing_spec.rb +51 -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 +8 -0
- data/spec/opal/stdlib/promise/error_spec.rb +15 -0
- data/spec/opal/stdlib/promise/rescue_spec.rb +35 -0
- data/spec/opal/stdlib/promise/then_spec.rb +54 -0
- data/spec/opal/stdlib/promise/trace_spec.rb +35 -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/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/rubyspecs +329 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/support/mspec_rspec_adapter.rb +33 -0
- data/spec/support/parser_helpers.rb +37 -0
- data/stdlib/README.md +3 -0
- data/stdlib/base64.rb +152 -0
- data/stdlib/benchmark.rb +10 -0
- data/stdlib/buffer.rb +40 -0
- data/stdlib/buffer/array.rb +66 -0
- data/stdlib/buffer/view.rb +70 -0
- data/stdlib/date.rb +170 -0
- data/stdlib/delegate.rb +29 -0
- data/stdlib/dir.rb +1 -0
- data/stdlib/encoding.rb +166 -0
- data/stdlib/enumerator.rb +1 -0
- data/stdlib/erb.rb +16 -0
- data/stdlib/file.rb +1 -0
- data/stdlib/forwardable.rb +71 -0
- data/stdlib/json.rb +182 -0
- data/stdlib/math.rb +370 -0
- data/stdlib/native.rb +530 -0
- data/stdlib/nodejs.rb +5 -0
- data/stdlib/nodejs/dir.rb +13 -0
- data/stdlib/nodejs/file.rb +98 -0
- data/stdlib/nodejs/fileutils.rb +26 -0
- data/stdlib/nodejs/io.rb +2 -0
- data/stdlib/nodejs/irb.rb +45 -0
- data/stdlib/nodejs/process.rb +16 -0
- data/stdlib/nodejs/require.rb +32 -0
- data/stdlib/nodejs/rubygems.rb +68 -0
- data/stdlib/nodejs/runtime.rb +25 -0
- data/stdlib/nodejs/yaml.rb +11 -0
- data/stdlib/observer.rb +202 -0
- data/stdlib/opal-parser.rb +53 -0
- data/stdlib/opal-source-maps.rb +2 -0
- data/stdlib/ostruct.rb +69 -0
- data/stdlib/pathname.rb +31 -0
- data/stdlib/phantomjs.rb +8 -0
- data/stdlib/pp.rb +12 -0
- data/stdlib/process.rb +10 -0
- data/stdlib/promise.rb +300 -0
- data/stdlib/racc/parser.rb +215 -0
- data/stdlib/rbconfig.rb +20 -0
- data/stdlib/securerandom.rb +12 -0
- data/stdlib/set.rb +116 -0
- data/stdlib/singleton.rb +40 -0
- data/stdlib/source_map.rb +5 -0
- data/stdlib/source_map/map.rb +220 -0
- data/stdlib/source_map/mapping.rb +26 -0
- data/stdlib/source_map/offset.rb +88 -0
- data/stdlib/source_map/version.rb +3 -0
- data/stdlib/source_map/vlq.rb +98 -0
- data/stdlib/sourcemap.rb +1 -0
- data/stdlib/stringio.rb +181 -0
- data/stdlib/strscan.rb +155 -0
- data/stdlib/template.rb +46 -0
- data/stdlib/thread.rb +160 -0
- data/stdlib/time.rb +9 -0
- data/tasks/github.rake +19 -0
- metadata +690 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
class Proc
|
|
2
|
+
`def.$$is_proc = true`
|
|
3
|
+
`def.$$is_lambda = false`
|
|
4
|
+
|
|
5
|
+
def self.new(&block)
|
|
6
|
+
unless block
|
|
7
|
+
raise ArgumentError, "tried to create a Proc object without a block"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
block
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def call(*args, &block)
|
|
14
|
+
%x{
|
|
15
|
+
if (block !== nil) {
|
|
16
|
+
self.$$p = block;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var result;
|
|
20
|
+
|
|
21
|
+
if (self.$$is_lambda) {
|
|
22
|
+
result = self.apply(null, args);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
result = Opal.$yieldX(self, args);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (result === $breaker) {
|
|
29
|
+
return $breaker.$v;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
alias [] call
|
|
37
|
+
|
|
38
|
+
def to_proc
|
|
39
|
+
self
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def lambda?
|
|
43
|
+
# This method should tell the user if the proc tricks are unavailable,
|
|
44
|
+
# (see Proc#lambda? on ruby docs to find out more).
|
|
45
|
+
`!!self.$$is_lambda`
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# FIXME: this should support the various splats and optional arguments
|
|
49
|
+
def arity
|
|
50
|
+
`self.length`
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
require 'corelib/enumerable'
|
|
2
|
+
|
|
3
|
+
class Range
|
|
4
|
+
include Enumerable
|
|
5
|
+
|
|
6
|
+
`def.$$is_range = true;`
|
|
7
|
+
|
|
8
|
+
attr_reader :begin, :end
|
|
9
|
+
|
|
10
|
+
def initialize(first, last, exclude = false)
|
|
11
|
+
raise ArgumentError unless first <=> last
|
|
12
|
+
|
|
13
|
+
@begin = first
|
|
14
|
+
@end = last
|
|
15
|
+
@exclude = exclude
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def ==(other)
|
|
19
|
+
%x{
|
|
20
|
+
if (!other.$$is_range) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return self.exclude === other.exclude &&
|
|
25
|
+
self.begin == other.begin &&
|
|
26
|
+
self.end == other.end;
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def ===(value)
|
|
31
|
+
include? value
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def cover?(value)
|
|
35
|
+
@begin <= value && (@exclude ? value < @end : value <= @end)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def each(&block)
|
|
39
|
+
return enum_for :each unless block_given?
|
|
40
|
+
|
|
41
|
+
current = @begin
|
|
42
|
+
last = @end
|
|
43
|
+
|
|
44
|
+
while current < last
|
|
45
|
+
yield current
|
|
46
|
+
|
|
47
|
+
current = current.succ
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
yield current if !@exclude && current == last
|
|
51
|
+
|
|
52
|
+
self
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def eql?(other)
|
|
56
|
+
return false unless Range === other
|
|
57
|
+
|
|
58
|
+
@exclude === other.exclude_end? &&
|
|
59
|
+
@begin.eql?(other.begin) &&
|
|
60
|
+
@end.eql?(other.end)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def exclude_end?
|
|
64
|
+
@exclude
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
alias :first :begin
|
|
68
|
+
|
|
69
|
+
alias :include? :cover?
|
|
70
|
+
|
|
71
|
+
alias :last :end
|
|
72
|
+
|
|
73
|
+
# FIXME: currently hardcoded to assume range holds numerics
|
|
74
|
+
def max
|
|
75
|
+
if block_given?
|
|
76
|
+
super
|
|
77
|
+
else
|
|
78
|
+
`#@exclude ? #@end - 1 : #@end`
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
alias :member? :cover?
|
|
83
|
+
|
|
84
|
+
def min
|
|
85
|
+
if block_given?
|
|
86
|
+
super
|
|
87
|
+
else
|
|
88
|
+
@begin
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
alias member? include?
|
|
93
|
+
|
|
94
|
+
def size
|
|
95
|
+
_begin = @begin
|
|
96
|
+
_end = @end
|
|
97
|
+
_end -= 1 if @exclude
|
|
98
|
+
|
|
99
|
+
return nil unless Numeric === _begin && Numeric === _end
|
|
100
|
+
return 0 if _end < _begin
|
|
101
|
+
infinity = Float::INFINITY
|
|
102
|
+
return infinity if infinity == _begin.abs || _end.abs == infinity
|
|
103
|
+
|
|
104
|
+
(`Math.abs(_end - _begin) + 1`).to_i
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def step(n = 1)
|
|
108
|
+
raise NotImplementedError
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def to_s
|
|
112
|
+
`#{@begin.inspect} + (#@exclude ? '...' : '..') + #{@end.inspect}`
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
alias inspect to_s
|
|
116
|
+
end
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
class Regexp
|
|
2
|
+
`def.$$is_regexp = true`
|
|
3
|
+
|
|
4
|
+
class << self
|
|
5
|
+
def escape(string)
|
|
6
|
+
%x{
|
|
7
|
+
return string.replace(/([-[\]/{}()*+?.^$\\| ])/g, '\\$1')
|
|
8
|
+
.replace(/[\n]/g, '\\n')
|
|
9
|
+
.replace(/[\r]/g, '\\r')
|
|
10
|
+
.replace(/[\f]/g, '\\f')
|
|
11
|
+
.replace(/[\t]/g, '\\t');
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
alias quote escape
|
|
16
|
+
|
|
17
|
+
def union(*parts)
|
|
18
|
+
`new RegExp(parts.join(''))`
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def new(regexp, options = undefined)
|
|
22
|
+
`new RegExp(regexp, options)`
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def ==(other)
|
|
27
|
+
`other.constructor == RegExp && self.toString() === other.toString()`
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def ===(str)
|
|
31
|
+
%x{
|
|
32
|
+
if (!str.$$is_string && #{str.respond_to?(:to_str)}) {
|
|
33
|
+
#{str = str.to_str};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!str.$$is_string) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return self.test(str);
|
|
41
|
+
}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def =~(string)
|
|
45
|
+
if `string === nil`
|
|
46
|
+
$~ = $` = $' = nil
|
|
47
|
+
|
|
48
|
+
return
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
string = Opal.coerce_to(string, String, :to_str).to_s
|
|
52
|
+
|
|
53
|
+
%x{
|
|
54
|
+
var re = self;
|
|
55
|
+
|
|
56
|
+
if (re.global) {
|
|
57
|
+
// should we clear it afterwards too?
|
|
58
|
+
re.lastIndex = 0;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// rewrite regular expression to add the global flag to capture pre/post match
|
|
62
|
+
re = new RegExp(re.source, 'g' + (re.multiline ? 'm' : '') + (re.ignoreCase ? 'i' : ''));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
var result = re.exec(string);
|
|
66
|
+
|
|
67
|
+
if (result) {
|
|
68
|
+
#{$~ = MatchData.new(`re`, `result`)};
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
#{$~ = $` = $' = nil};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return result ? result.index : nil;
|
|
75
|
+
}
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
alias eql? ==
|
|
79
|
+
|
|
80
|
+
def inspect
|
|
81
|
+
`self.toString()`
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def match(string, pos = undefined, &block)
|
|
85
|
+
if `string === nil`
|
|
86
|
+
$~ = $` = $' = nil
|
|
87
|
+
|
|
88
|
+
return
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
if `string.$$is_string == null`
|
|
92
|
+
unless string.respond_to? :to_str
|
|
93
|
+
raise TypeError, "no implicit conversion of #{string.class} into String"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
string = string.to_str
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
%x{
|
|
100
|
+
var re = self;
|
|
101
|
+
|
|
102
|
+
if (re.global) {
|
|
103
|
+
// should we clear it afterwards too?
|
|
104
|
+
re.lastIndex = 0;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
re = new RegExp(re.source, 'g' + (re.multiline ? 'm' : '') + (re.ignoreCase ? 'i' : ''));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
var result = re.exec(string);
|
|
111
|
+
|
|
112
|
+
if (result) {
|
|
113
|
+
result = #{$~ = MatchData.new(`re`, `result`)};
|
|
114
|
+
|
|
115
|
+
if (block === nil) {
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return #{block.call(`result`)};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
return #{$~ = $` = $' = nil};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def source
|
|
129
|
+
`self.source`
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
alias to_s source
|
|
133
|
+
end
|
|
@@ -0,0 +1,1240 @@
|
|
|
1
|
+
(function(undefined) {
|
|
2
|
+
if (typeof(this.Opal) !== 'undefined') {
|
|
3
|
+
console.warn('Opal already loaded. Loading twice can cause troubles, please fix your setup.');
|
|
4
|
+
return this.Opal;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// The Opal object that is exposed globally
|
|
8
|
+
var Opal = this.Opal = {}, $opal = Opal;
|
|
9
|
+
|
|
10
|
+
// All bridged classes - keep track to donate methods from Object
|
|
11
|
+
var bridged_classes = Opal.bridged_classes = [];
|
|
12
|
+
|
|
13
|
+
// TopScope is used for inheriting constants from the top scope
|
|
14
|
+
var TopScope = function(){};
|
|
15
|
+
|
|
16
|
+
// Opal just acts as the top scope
|
|
17
|
+
TopScope.prototype = Opal;
|
|
18
|
+
|
|
19
|
+
// To inherit scopes
|
|
20
|
+
Opal.constructor = TopScope;
|
|
21
|
+
|
|
22
|
+
// List top scope constants
|
|
23
|
+
Opal.constants = [];
|
|
24
|
+
|
|
25
|
+
// This is a useful reference to global object inside ruby files
|
|
26
|
+
Opal.global = this;
|
|
27
|
+
|
|
28
|
+
// Minify common function calls
|
|
29
|
+
var $hasOwn = Opal.hasOwnProperty;
|
|
30
|
+
var $slice = Opal.slice = Array.prototype.slice;
|
|
31
|
+
|
|
32
|
+
// Generates unique id for every ruby object
|
|
33
|
+
var unique_id = 0;
|
|
34
|
+
|
|
35
|
+
// Return next unique id
|
|
36
|
+
Opal.uid = function() {
|
|
37
|
+
return unique_id++;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Table holds all class variables
|
|
41
|
+
Opal.cvars = {};
|
|
42
|
+
|
|
43
|
+
// Globals table
|
|
44
|
+
Opal.gvars = {};
|
|
45
|
+
|
|
46
|
+
// Get constants
|
|
47
|
+
Opal.get = function(name) {
|
|
48
|
+
var constant = this[name];
|
|
49
|
+
|
|
50
|
+
if (constant == null) {
|
|
51
|
+
return this.base.$const_missing(name);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return constant;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/*
|
|
58
|
+
* Create a new constants scope for the given class with the given
|
|
59
|
+
* base. Constants are looked up through their parents, so the base
|
|
60
|
+
* scope will be the outer scope of the new klass.
|
|
61
|
+
*/
|
|
62
|
+
function create_scope(base, klass, id) {
|
|
63
|
+
var const_alloc = function() {};
|
|
64
|
+
var const_scope = const_alloc.prototype = new base.constructor();
|
|
65
|
+
|
|
66
|
+
klass.$$scope = const_scope;
|
|
67
|
+
klass.$$base_module = base.base;
|
|
68
|
+
|
|
69
|
+
const_scope.base = klass;
|
|
70
|
+
const_scope.constructor = const_alloc;
|
|
71
|
+
const_scope.constants = [];
|
|
72
|
+
|
|
73
|
+
if (id) {
|
|
74
|
+
klass.$$orig_scope = base;
|
|
75
|
+
base[id] = base.constructor[id] = klass;
|
|
76
|
+
base.constants.push(id);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
Opal.create_scope = create_scope;
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
* A `class Foo; end` expression in ruby is compiled to call this runtime
|
|
84
|
+
* method which either returns an existing class of the given name, or creates
|
|
85
|
+
* a new class in the given `base` scope.
|
|
86
|
+
*
|
|
87
|
+
* If a constant with the given name exists, then we check to make sure that
|
|
88
|
+
* it is a class and also that the superclasses match. If either of these
|
|
89
|
+
* fail, then we raise a `TypeError`. Note, superklass may be null if one was
|
|
90
|
+
* not specified in the ruby code.
|
|
91
|
+
*
|
|
92
|
+
* We pass a constructor to this method of the form `function ClassName() {}`
|
|
93
|
+
* simply so that classes show up with nicely formatted names inside debuggers
|
|
94
|
+
* in the web browser (or node/sprockets).
|
|
95
|
+
*
|
|
96
|
+
* The `base` is the current `self` value where the class is being created
|
|
97
|
+
* from. We use this to get the scope for where the class should be created.
|
|
98
|
+
* If `base` is an object (not a class/module), we simple get its class and
|
|
99
|
+
* use that as the base instead.
|
|
100
|
+
*
|
|
101
|
+
* @param [Object] base where the class is being created
|
|
102
|
+
* @param [Class] superklass superclass of the new class (may be null)
|
|
103
|
+
* @param [String] id the name of the class to be created
|
|
104
|
+
* @param [Function] constructor function to use as constructor
|
|
105
|
+
* @return [Class] new or existing ruby class
|
|
106
|
+
*/
|
|
107
|
+
Opal.klass = function(base, superklass, id, constructor) {
|
|
108
|
+
// If base is an object, use its class
|
|
109
|
+
if (!base.$$is_class) {
|
|
110
|
+
base = base.$$class;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Not specifying a superclass means we can assume it to be Object
|
|
114
|
+
if (superklass === null) {
|
|
115
|
+
superklass = ObjectClass;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
var klass = base.$$scope[id];
|
|
119
|
+
|
|
120
|
+
// If a constant exists in the scope, then we must use that
|
|
121
|
+
if ($hasOwn.call(base.$$scope, id) && klass.$$orig_scope === base.$$scope) {
|
|
122
|
+
// Make sure the existing constant is a class, or raise error
|
|
123
|
+
if (!klass.$$is_class) {
|
|
124
|
+
throw Opal.TypeError.$new(id + " is not a class");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Make sure existing class has same superclass
|
|
128
|
+
if (superklass !== klass.$$super && superklass !== ObjectClass) {
|
|
129
|
+
throw Opal.TypeError.$new("superclass mismatch for class " + id);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else if (typeof(superklass) === 'function') {
|
|
133
|
+
// passed native constructor as superklass, so bridge it as ruby class
|
|
134
|
+
return bridge_class(id, superklass);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
// if class doesnt exist, create a new one with given superclass
|
|
138
|
+
klass = boot_class(superklass, constructor);
|
|
139
|
+
|
|
140
|
+
// name class using base (e.g. Foo or Foo::Baz)
|
|
141
|
+
klass.$$name = id;
|
|
142
|
+
|
|
143
|
+
// every class gets its own constant scope, inherited from current scope
|
|
144
|
+
create_scope(base.$$scope, klass, id);
|
|
145
|
+
|
|
146
|
+
// Name new class directly onto current scope (Opal.Foo.Baz = klass)
|
|
147
|
+
base[id] = base.$$scope[id] = klass;
|
|
148
|
+
|
|
149
|
+
// Copy all parent constants to child, unless parent is Object
|
|
150
|
+
if (superklass !== ObjectClass && superklass !== BasicObjectClass) {
|
|
151
|
+
Opal.donate_constants(superklass, klass);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// call .inherited() hook with new class on the superclass
|
|
155
|
+
if (superklass.$inherited) {
|
|
156
|
+
superklass.$inherited(klass);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return klass;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// Create generic class with given superclass.
|
|
164
|
+
function boot_class(superklass, constructor) {
|
|
165
|
+
var alloc = boot_class_alloc(null, constructor, superklass)
|
|
166
|
+
|
|
167
|
+
return boot_class_object(superklass, alloc);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Make `boot_class` available to the JS-API
|
|
171
|
+
Opal.boot = boot_class;
|
|
172
|
+
|
|
173
|
+
/*
|
|
174
|
+
* The class object itself (as in `Class.new`)
|
|
175
|
+
*
|
|
176
|
+
* @param [(Opal) Class] superklass Another class object (as in `Class.new`)
|
|
177
|
+
* @param [constructor] alloc The constructor that holds the prototype
|
|
178
|
+
* that will be used for instances of the
|
|
179
|
+
* newly constructed class.
|
|
180
|
+
*/
|
|
181
|
+
function boot_class_object(superklass, alloc) {
|
|
182
|
+
var singleton_class = function() {};
|
|
183
|
+
singleton_class.prototype = superklass.constructor.prototype;
|
|
184
|
+
|
|
185
|
+
function OpalClass() {}
|
|
186
|
+
OpalClass.prototype = new singleton_class();
|
|
187
|
+
|
|
188
|
+
var klass = new OpalClass();
|
|
189
|
+
|
|
190
|
+
setup_module_or_class_object(klass, OpalClass, superklass, alloc.prototype);
|
|
191
|
+
|
|
192
|
+
// @property $$alloc This is the constructor of instances of the current
|
|
193
|
+
// class. Its prototype will be used for method lookup
|
|
194
|
+
klass.$$alloc = alloc;
|
|
195
|
+
|
|
196
|
+
// @property $$proto.$$class Make available to instances a reference to the
|
|
197
|
+
// class they belong to.
|
|
198
|
+
klass.$$proto.$$class = klass;
|
|
199
|
+
|
|
200
|
+
return klass;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/*
|
|
204
|
+
* Adds common/required properties to a module or class object
|
|
205
|
+
* (as in `Module.new` / `Class.new`)
|
|
206
|
+
*
|
|
207
|
+
* @param module The module or class that needs to be prepared
|
|
208
|
+
*
|
|
209
|
+
* @param constructor The constructor of the module or class itself,
|
|
210
|
+
* usually it's already assigned by using `new`. Some
|
|
211
|
+
* ipothesis on why it's needed can be found below.
|
|
212
|
+
*
|
|
213
|
+
* @param superklass The superclass of the class/module object, for modules
|
|
214
|
+
* is `Module` (of `ModuleClass` in JS context)
|
|
215
|
+
*
|
|
216
|
+
* @param prototype The prototype on which the class/module methods will
|
|
217
|
+
* be stored.
|
|
218
|
+
*/
|
|
219
|
+
function setup_module_or_class_object(module, constructor, superklass, prototype) {
|
|
220
|
+
// @property $$id Each class is assigned a unique `id` that helps
|
|
221
|
+
// comparation and implementation of `#object_id`
|
|
222
|
+
module.$$id = unique_id++;
|
|
223
|
+
|
|
224
|
+
// @property $$proto This is the prototype on which methods will be defined
|
|
225
|
+
module.$$proto = prototype;
|
|
226
|
+
|
|
227
|
+
// @property constructor keeps a ref to the constructor, but apparently the
|
|
228
|
+
// constructor is already set on:
|
|
229
|
+
//
|
|
230
|
+
// `var module = new constructor` is called.
|
|
231
|
+
//
|
|
232
|
+
// Maybe there are some browsers not abiding (IE6?)
|
|
233
|
+
module.constructor = constructor;
|
|
234
|
+
|
|
235
|
+
// @property $$is_class Clearly mark this as a class-like
|
|
236
|
+
module.$$is_class = true;
|
|
237
|
+
|
|
238
|
+
// @property $$super the superclass, doesn't get changed by module inclusions
|
|
239
|
+
module.$$super = superklass;
|
|
240
|
+
|
|
241
|
+
// @property $$parent direct parent class or module
|
|
242
|
+
// starts with the superclass, after module inclusion is
|
|
243
|
+
// the last included module
|
|
244
|
+
module.$$parent = superklass;
|
|
245
|
+
|
|
246
|
+
// @property $$methods keeps track of methods defined on the class
|
|
247
|
+
// but seems to be used just by `define_basic_object_method`
|
|
248
|
+
// and for donating (Ruby) Object methods to bridged classes
|
|
249
|
+
// TODO: check if it can be removed
|
|
250
|
+
module.$$methods = [];
|
|
251
|
+
|
|
252
|
+
// @property $$inc included modules
|
|
253
|
+
module.$$inc = [];
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Define new module (or return existing module)
|
|
257
|
+
Opal.module = function(base, id) {
|
|
258
|
+
var module;
|
|
259
|
+
|
|
260
|
+
if (!base.$$is_class) {
|
|
261
|
+
base = base.$$class;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if ($hasOwn.call(base.$$scope, id)) {
|
|
265
|
+
module = base.$$scope[id];
|
|
266
|
+
|
|
267
|
+
if (!module.$$is_mod && module !== ObjectClass) {
|
|
268
|
+
throw Opal.TypeError.$new(id + " is not a module");
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
module = boot_module_object();
|
|
273
|
+
module.$$name = id;
|
|
274
|
+
|
|
275
|
+
create_scope(base.$$scope, module, id);
|
|
276
|
+
|
|
277
|
+
// Name new module directly onto current scope (Opal.Foo.Baz = module)
|
|
278
|
+
base[id] = base.$$scope[id] = module;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return module;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
/*
|
|
285
|
+
* Internal function to create a new module instance. This simply sets up
|
|
286
|
+
* the prototype hierarchy and method tables.
|
|
287
|
+
*/
|
|
288
|
+
function boot_module_object() {
|
|
289
|
+
var mtor = function() {};
|
|
290
|
+
mtor.prototype = ModuleClass.constructor.prototype;
|
|
291
|
+
|
|
292
|
+
function module_constructor() {}
|
|
293
|
+
module_constructor.prototype = new mtor();
|
|
294
|
+
|
|
295
|
+
var module = new module_constructor();
|
|
296
|
+
var module_prototype = {};
|
|
297
|
+
|
|
298
|
+
setup_module_or_class_object(module, module_constructor, ModuleClass, module_prototype);
|
|
299
|
+
|
|
300
|
+
module.$$is_mod = true;
|
|
301
|
+
module.$$dep = [];
|
|
302
|
+
|
|
303
|
+
return module;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/*
|
|
307
|
+
* Get (or prepare) the singleton class for the passed object.
|
|
308
|
+
*
|
|
309
|
+
* @param object [Ruby Object]
|
|
310
|
+
*/
|
|
311
|
+
Opal.get_singleton_class = function(object) {
|
|
312
|
+
if (object.$$meta) {
|
|
313
|
+
return object.$$meta;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (object.$$is_class) {
|
|
317
|
+
return build_class_singleton_class(object);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return build_object_singleton_class(object);
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
/*
|
|
324
|
+
* Build the singleton class for an existing class.
|
|
325
|
+
*
|
|
326
|
+
* NOTE: Actually in MRI a class' singleton class inherits from its
|
|
327
|
+
* superclass' singleton class which in turn inherits from Class;
|
|
328
|
+
*/
|
|
329
|
+
function build_class_singleton_class(klass) {
|
|
330
|
+
var meta = new $opal.Class.$$alloc;
|
|
331
|
+
|
|
332
|
+
meta.$$class = $opal.Class;
|
|
333
|
+
meta.$$proto = klass.constructor.prototype;
|
|
334
|
+
|
|
335
|
+
meta.$$is_singleton = true;
|
|
336
|
+
meta.$$inc = [];
|
|
337
|
+
meta.$$methods = [];
|
|
338
|
+
meta.$$scope = klass.$$scope;
|
|
339
|
+
|
|
340
|
+
return klass.$$meta = meta;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/*
|
|
344
|
+
* Build the singleton class for a Ruby (non class) Object.
|
|
345
|
+
*/
|
|
346
|
+
function build_object_singleton_class(object) {
|
|
347
|
+
var orig_class = object.$$class,
|
|
348
|
+
class_id = "#<Class:#<" + orig_class.$$name + ":" + orig_class.$$id + ">>";
|
|
349
|
+
|
|
350
|
+
var Singleton = function () {};
|
|
351
|
+
var meta = Opal.boot(orig_class, Singleton);
|
|
352
|
+
meta.$$name = class_id;
|
|
353
|
+
|
|
354
|
+
meta.$$proto = object;
|
|
355
|
+
meta.$$class = orig_class.$$class;
|
|
356
|
+
meta.$$scope = orig_class.$$scope;
|
|
357
|
+
meta.$$parent = orig_class;
|
|
358
|
+
return object.$$meta = meta;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/*
|
|
362
|
+
* The actual inclusion of a module into a class.
|
|
363
|
+
*/
|
|
364
|
+
Opal.append_features = function(module, klass) {
|
|
365
|
+
var included = klass.$$inc;
|
|
366
|
+
|
|
367
|
+
// check if this module is already included in the klass
|
|
368
|
+
for (var j = 0, jj = included.length; j < jj; j++) {
|
|
369
|
+
if (included[j] === module) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
included.push(module);
|
|
375
|
+
module.$$dep.push(klass);
|
|
376
|
+
|
|
377
|
+
// iclass
|
|
378
|
+
var iclass = {
|
|
379
|
+
$$name: module.$$name,
|
|
380
|
+
$$proto: module.$$proto,
|
|
381
|
+
$$parent: klass.$$parent,
|
|
382
|
+
$$module: module,
|
|
383
|
+
$$iclass: true
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
klass.$$parent = iclass;
|
|
387
|
+
|
|
388
|
+
var donator = module.$$proto,
|
|
389
|
+
prototype = klass.$$proto,
|
|
390
|
+
methods = module.$$methods;
|
|
391
|
+
|
|
392
|
+
for (var i = 0, length = methods.length; i < length; i++) {
|
|
393
|
+
var method = methods[i], current;
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
if ( prototype.hasOwnProperty(method) &&
|
|
397
|
+
!(current = prototype[method]).$$donated && !current.$$stub ) {
|
|
398
|
+
// if the target class already has a method of the same name defined
|
|
399
|
+
// and that method was NOT donated, then it must be a method defined
|
|
400
|
+
// by the class so we do not want to override it
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
prototype[method] = donator[method];
|
|
404
|
+
prototype[method].$$donated = true;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (klass.$$dep) {
|
|
409
|
+
$opal.donate(klass, methods.slice(), true);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
$opal.donate_constants(module, klass);
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
// Boot a base class (makes instances).
|
|
417
|
+
function boot_class_alloc(id, constructor, superklass) {
|
|
418
|
+
if (superklass) {
|
|
419
|
+
var ctor = function() {};
|
|
420
|
+
ctor.prototype = superklass.$$proto || superklass.prototype;
|
|
421
|
+
|
|
422
|
+
if (id) {
|
|
423
|
+
ctor.displayName = id;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
constructor.prototype = new ctor();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
constructor.prototype.constructor = constructor;
|
|
430
|
+
|
|
431
|
+
return constructor;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/*
|
|
435
|
+
* Builds the class object for core classes:
|
|
436
|
+
* - make the class object have a singleton class
|
|
437
|
+
* - make the singleton class inherit from its parent singleton class
|
|
438
|
+
*
|
|
439
|
+
* @param id [String] the name of the class
|
|
440
|
+
* @param alloc [Function] the constructor for the core class instances
|
|
441
|
+
* @param superclass [Class alloc] the constructor of the superclass
|
|
442
|
+
*/
|
|
443
|
+
function boot_core_class_object(id, alloc, superclass) {
|
|
444
|
+
var superclass_constructor = function() {};
|
|
445
|
+
superclass_constructor.prototype = superclass.prototype;
|
|
446
|
+
|
|
447
|
+
var singleton_class = function() {};
|
|
448
|
+
singleton_class.prototype = new superclass_constructor();
|
|
449
|
+
|
|
450
|
+
singleton_class.displayName = "#<Class:"+id+">";
|
|
451
|
+
|
|
452
|
+
// the singleton_class acts as the class object constructor
|
|
453
|
+
var klass = new singleton_class();
|
|
454
|
+
|
|
455
|
+
setup_module_or_class_object(klass, singleton_class, superclass, alloc.prototype);
|
|
456
|
+
|
|
457
|
+
klass.$$alloc = alloc;
|
|
458
|
+
klass.$$name = id;
|
|
459
|
+
|
|
460
|
+
// Give all instances a ref to their class
|
|
461
|
+
alloc.prototype.$$class = klass;
|
|
462
|
+
|
|
463
|
+
Opal[id] = klass;
|
|
464
|
+
Opal.constants.push(id);
|
|
465
|
+
|
|
466
|
+
return klass;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/*
|
|
470
|
+
* For performance, some core ruby classes are toll-free bridged to their
|
|
471
|
+
* native javascript counterparts (e.g. a ruby Array is a javascript Array).
|
|
472
|
+
*
|
|
473
|
+
* This method is used to setup a native constructor (e.g. Array), to have
|
|
474
|
+
* its prototype act like a normal ruby class. Firstly, a new ruby class is
|
|
475
|
+
* created using the native constructor so that its prototype is set as the
|
|
476
|
+
* target for th new class. Note: all bridged classes are set to inherit
|
|
477
|
+
* from Object.
|
|
478
|
+
*
|
|
479
|
+
* Bridged classes are tracked in `bridged_classes` array so that methods
|
|
480
|
+
* defined on Object can be "donated" to all bridged classes. This allows
|
|
481
|
+
* us to fake the inheritance of a native prototype from our Object
|
|
482
|
+
* prototype.
|
|
483
|
+
*
|
|
484
|
+
* Example:
|
|
485
|
+
*
|
|
486
|
+
* bridge_class("Proc", Function);
|
|
487
|
+
*
|
|
488
|
+
* @param [String] name the name of the ruby class to create
|
|
489
|
+
* @param [Function] constructor native javascript constructor to use
|
|
490
|
+
* @return [Class] returns new ruby class
|
|
491
|
+
*/
|
|
492
|
+
function bridge_class(name, constructor) {
|
|
493
|
+
var klass = boot_class_object(ObjectClass, constructor);
|
|
494
|
+
|
|
495
|
+
klass.$$name = name;
|
|
496
|
+
|
|
497
|
+
create_scope(Opal, klass, name);
|
|
498
|
+
bridged_classes.push(klass);
|
|
499
|
+
|
|
500
|
+
var object_methods = BasicObjectClass.$$methods.concat(ObjectClass.$$methods);
|
|
501
|
+
|
|
502
|
+
for (var i = 0, len = object_methods.length; i < len; i++) {
|
|
503
|
+
var meth = object_methods[i];
|
|
504
|
+
constructor.prototype[meth] = ObjectClass.$$proto[meth];
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
add_stubs_subscriber(constructor.prototype);
|
|
508
|
+
|
|
509
|
+
return klass;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/*
|
|
513
|
+
* constant assign
|
|
514
|
+
*/
|
|
515
|
+
Opal.casgn = function(base_module, name, value) {
|
|
516
|
+
var scope = base_module.$$scope;
|
|
517
|
+
|
|
518
|
+
if (value.$$is_class && value.$$name === nil) {
|
|
519
|
+
value.$$name = name;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
if (value.$$is_class) {
|
|
523
|
+
value.$$base_module = base_module;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
scope.constants.push(name);
|
|
527
|
+
return scope[name] = value;
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
/*
|
|
531
|
+
* constant decl
|
|
532
|
+
*/
|
|
533
|
+
Opal.cdecl = function(base_scope, name, value) {
|
|
534
|
+
base_scope.constants.push(name);
|
|
535
|
+
return base_scope[name] = value;
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
/*
|
|
539
|
+
* constant get
|
|
540
|
+
*/
|
|
541
|
+
Opal.cget = function(base_scope, path) {
|
|
542
|
+
if (path == null) {
|
|
543
|
+
path = base_scope;
|
|
544
|
+
base_scope = Opal.Object;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
var result = base_scope;
|
|
548
|
+
|
|
549
|
+
path = path.split('::');
|
|
550
|
+
while (path.length !== 0) {
|
|
551
|
+
result = result.$const_get(path.shift());
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
return result;
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
/*
|
|
558
|
+
* When a source module is included into the target module, we must also copy
|
|
559
|
+
* its constants to the target.
|
|
560
|
+
*/
|
|
561
|
+
Opal.donate_constants = function(source_mod, target_mod) {
|
|
562
|
+
var source_constants = source_mod.$$scope.constants,
|
|
563
|
+
target_scope = target_mod.$$scope,
|
|
564
|
+
target_constants = target_scope.constants;
|
|
565
|
+
|
|
566
|
+
for (var i = 0, length = source_constants.length; i < length; i++) {
|
|
567
|
+
target_constants.push(source_constants[i]);
|
|
568
|
+
target_scope[source_constants[i]] = source_mod.$$scope[source_constants[i]];
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
/*
|
|
573
|
+
* Methods stubs are used to facilitate method_missing in opal. A stub is a
|
|
574
|
+
* placeholder function which just calls `method_missing` on the receiver.
|
|
575
|
+
* If no method with the given name is actually defined on an object, then it
|
|
576
|
+
* is obvious to say that the stub will be called instead, and then in turn
|
|
577
|
+
* method_missing will be called.
|
|
578
|
+
*
|
|
579
|
+
* When a file in ruby gets compiled to javascript, it includes a call to
|
|
580
|
+
* this function which adds stubs for every method name in the compiled file.
|
|
581
|
+
* It should then be safe to assume that method_missing will work for any
|
|
582
|
+
* method call detected.
|
|
583
|
+
*
|
|
584
|
+
* Method stubs are added to the BasicObject prototype, which every other
|
|
585
|
+
* ruby object inherits, so all objects should handle method missing. A stub
|
|
586
|
+
* is only added if the given property name (method name) is not already
|
|
587
|
+
* defined.
|
|
588
|
+
*
|
|
589
|
+
* Note: all ruby methods have a `$` prefix in javascript, so all stubs will
|
|
590
|
+
* have this prefix as well (to make this method more performant).
|
|
591
|
+
*
|
|
592
|
+
* Opal.add_stubs(["$foo", "$bar", "$baz="]);
|
|
593
|
+
*
|
|
594
|
+
* All stub functions will have a private `$$stub` property set to true so
|
|
595
|
+
* that other internal methods can detect if a method is just a stub or not.
|
|
596
|
+
* `Kernel#respond_to?` uses this property to detect a methods presence.
|
|
597
|
+
*
|
|
598
|
+
* @param [Array] stubs an array of method stubs to add
|
|
599
|
+
*/
|
|
600
|
+
Opal.add_stubs = function(stubs) {
|
|
601
|
+
var subscribers = Opal.stub_subscribers;
|
|
602
|
+
var subscriber;
|
|
603
|
+
|
|
604
|
+
for (var i = 0, length = stubs.length; i < length; i++) {
|
|
605
|
+
var method_name = stubs[i], stub = stub_for(method_name);
|
|
606
|
+
|
|
607
|
+
for (var j = 0; j < subscribers.length; j++) {
|
|
608
|
+
subscriber = subscribers[j];
|
|
609
|
+
if (!(method_name in subscriber)) {
|
|
610
|
+
subscriber[method_name] = stub;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
/*
|
|
617
|
+
* Add a prototype to the subscribers list, and (TODO) add previously stubbed
|
|
618
|
+
* methods.
|
|
619
|
+
*
|
|
620
|
+
* @param [Prototype]
|
|
621
|
+
*/
|
|
622
|
+
function add_stubs_subscriber(prototype) {
|
|
623
|
+
// TODO: Add previously stubbed methods too.
|
|
624
|
+
Opal.stub_subscribers.push(prototype);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/*
|
|
628
|
+
* Keep a list of prototypes that want method_missing stubs to be added.
|
|
629
|
+
*
|
|
630
|
+
* @default [Prototype List] BasicObject.prototype
|
|
631
|
+
*/
|
|
632
|
+
Opal.stub_subscribers = [BasicObject.prototype];
|
|
633
|
+
|
|
634
|
+
/*
|
|
635
|
+
* Add a method_missing stub function to the given prototype for the
|
|
636
|
+
* given name.
|
|
637
|
+
*
|
|
638
|
+
* @param [Prototype] prototype the target prototype
|
|
639
|
+
* @param [String] stub stub name to add (e.g. "$foo")
|
|
640
|
+
*/
|
|
641
|
+
function add_stub_for(prototype, stub) {
|
|
642
|
+
var method_missing_stub = stub_for(stub);
|
|
643
|
+
prototype[stub] = method_missing_stub;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/*
|
|
647
|
+
* Generate the method_missing stub for a given method name.
|
|
648
|
+
*
|
|
649
|
+
* @param [String] method_name The js-name of the method to stub (e.g. "$foo")
|
|
650
|
+
*/
|
|
651
|
+
function stub_for(method_name) {
|
|
652
|
+
function method_missing_stub() {
|
|
653
|
+
// Copy any given block onto the method_missing dispatcher
|
|
654
|
+
this.$method_missing.$$p = method_missing_stub.$$p;
|
|
655
|
+
|
|
656
|
+
// Set block property to null ready for the next call (stop false-positives)
|
|
657
|
+
method_missing_stub.$$p = null;
|
|
658
|
+
|
|
659
|
+
// call method missing with correct args (remove '$' prefix on method name)
|
|
660
|
+
return this.$method_missing.apply(this, [method_name.slice(1)].concat($slice.call(arguments)));
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
method_missing_stub.$$stub = true;
|
|
664
|
+
|
|
665
|
+
return method_missing_stub;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// Expose for other parts of Opal to use
|
|
669
|
+
Opal.add_stub_for = add_stub_for;
|
|
670
|
+
|
|
671
|
+
// Arity count error dispatcher
|
|
672
|
+
Opal.ac = function(actual, expected, object, meth) {
|
|
673
|
+
var inspect = (object.$$is_class ? object.$$name + '.' : object.$$class.$$name + '#') + meth;
|
|
674
|
+
var msg = '[' + inspect + '] wrong number of arguments(' + actual + ' for ' + expected + ')';
|
|
675
|
+
throw Opal.ArgumentError.$new(msg);
|
|
676
|
+
};
|
|
677
|
+
|
|
678
|
+
// Super dispatcher
|
|
679
|
+
Opal.find_super_dispatcher = function(obj, jsid, current_func, iter, defs) {
|
|
680
|
+
var dispatcher;
|
|
681
|
+
|
|
682
|
+
if (defs) {
|
|
683
|
+
dispatcher = obj.$$is_class ? defs.$$super : obj.$$class.$$proto;
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
if (obj.$$is_class) {
|
|
687
|
+
dispatcher = obj.$$super;
|
|
688
|
+
}
|
|
689
|
+
else {
|
|
690
|
+
dispatcher = find_obj_super_dispatcher(obj, jsid, current_func);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
dispatcher = dispatcher['$' + jsid];
|
|
695
|
+
dispatcher.$$p = iter;
|
|
696
|
+
|
|
697
|
+
return dispatcher;
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
// Iter dispatcher for super in a block
|
|
701
|
+
Opal.find_iter_super_dispatcher = function(obj, jsid, current_func, iter, defs) {
|
|
702
|
+
if (current_func.$$def) {
|
|
703
|
+
return Opal.find_super_dispatcher(obj, current_func.$$jsid, current_func, iter, defs);
|
|
704
|
+
}
|
|
705
|
+
else {
|
|
706
|
+
return Opal.find_super_dispatcher(obj, jsid, current_func, iter, defs);
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
|
|
710
|
+
function find_obj_super_dispatcher(obj, jsid, current_func) {
|
|
711
|
+
var klass = obj.$$meta || obj.$$class;
|
|
712
|
+
jsid = '$' + jsid;
|
|
713
|
+
|
|
714
|
+
while (klass) {
|
|
715
|
+
if (klass.$$proto[jsid] === current_func) {
|
|
716
|
+
// ok
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
klass = klass.$$parent;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// if we arent in a class, we couldnt find current?
|
|
724
|
+
if (!klass) {
|
|
725
|
+
throw new Error("could not find current class for super()");
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
klass = klass.$$parent;
|
|
729
|
+
|
|
730
|
+
// else, let's find the next one
|
|
731
|
+
while (klass) {
|
|
732
|
+
var working = klass.$$proto[jsid];
|
|
733
|
+
|
|
734
|
+
if (working && working !== current_func) {
|
|
735
|
+
// ok
|
|
736
|
+
break;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
klass = klass.$$parent;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
return klass.$$proto;
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
/*
|
|
746
|
+
* Used to return as an expression. Sometimes, we can't simply return from
|
|
747
|
+
* a javascript function as if we were a method, as the return is used as
|
|
748
|
+
* an expression, or even inside a block which must "return" to the outer
|
|
749
|
+
* method. This helper simply throws an error which is then caught by the
|
|
750
|
+
* method. This approach is expensive, so it is only used when absolutely
|
|
751
|
+
* needed.
|
|
752
|
+
*/
|
|
753
|
+
Opal.$return = function(val) {
|
|
754
|
+
Opal.returner.$v = val;
|
|
755
|
+
throw Opal.returner;
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
// handles yield calls for 1 yielded arg
|
|
759
|
+
Opal.$yield1 = function(block, arg) {
|
|
760
|
+
if (typeof(block) !== "function") {
|
|
761
|
+
throw Opal.LocalJumpError.$new("no block given");
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
if (block.length > 1 && arg.$$is_array) {
|
|
765
|
+
return block.apply(null, arg);
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
return block(arg);
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
// handles yield for > 1 yielded arg
|
|
773
|
+
Opal.$yieldX = function(block, args) {
|
|
774
|
+
if (typeof(block) !== "function") {
|
|
775
|
+
throw Opal.LocalJumpError.$new("no block given");
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
if (block.length > 1 && args.length == 1) {
|
|
779
|
+
if (args[0].$$is_array) {
|
|
780
|
+
return block.apply(null, args[0]);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
if (!args.$$is_array) {
|
|
785
|
+
args = $slice.call(args);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
return block.apply(null, args);
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
// Finds the corresponding exception match in candidates. Each candidate can
|
|
792
|
+
// be a value, or an array of values. Returns null if not found.
|
|
793
|
+
Opal.$rescue = function(exception, candidates) {
|
|
794
|
+
for (var i = 0; i != candidates.length; i++) {
|
|
795
|
+
var candidate = candidates[i];
|
|
796
|
+
if (candidate.$$is_array) {
|
|
797
|
+
var subresult = Opal.$rescue(exception, candidate);
|
|
798
|
+
if (subresult) {
|
|
799
|
+
return subresult;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
else if (candidate['$==='](exception)) {
|
|
803
|
+
return candidate;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return null;
|
|
807
|
+
};
|
|
808
|
+
|
|
809
|
+
Opal.is_a = function(object, klass) {
|
|
810
|
+
if (object.$$meta === klass) {
|
|
811
|
+
return true;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
var search = object.$$class;
|
|
815
|
+
|
|
816
|
+
while (search) {
|
|
817
|
+
if (search === klass) {
|
|
818
|
+
return true;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
for (var i = 0, length = search.$$inc.length; i < length; i++) {
|
|
822
|
+
if (search.$$inc[i] == klass) {
|
|
823
|
+
return true;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
search = search.$$super;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
return false;
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
// Helper to convert the given object to an array
|
|
834
|
+
Opal.to_ary = function(value) {
|
|
835
|
+
if (value.$$is_array) {
|
|
836
|
+
return value;
|
|
837
|
+
}
|
|
838
|
+
else if (value.$to_ary && !value.$to_ary.$$stub) {
|
|
839
|
+
return value.$to_ary();
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
return [value];
|
|
843
|
+
};
|
|
844
|
+
|
|
845
|
+
/*
|
|
846
|
+
* Call a ruby method on a ruby object with some arguments:
|
|
847
|
+
*
|
|
848
|
+
* var my_array = [1, 2, 3, 4]
|
|
849
|
+
* Opal.send(my_array, 'length') # => 4
|
|
850
|
+
* Opal.send(my_array, 'reverse!') # => [4, 3, 2, 1]
|
|
851
|
+
*
|
|
852
|
+
* A missing method will be forwarded to the object via
|
|
853
|
+
* method_missing.
|
|
854
|
+
*
|
|
855
|
+
* The result of either call with be returned.
|
|
856
|
+
*
|
|
857
|
+
* @param [Object] recv the ruby object
|
|
858
|
+
* @param [String] mid ruby method to call
|
|
859
|
+
*/
|
|
860
|
+
Opal.send = function(recv, mid) {
|
|
861
|
+
var args = $slice.call(arguments, 2),
|
|
862
|
+
func = recv['$' + mid];
|
|
863
|
+
|
|
864
|
+
if (func) {
|
|
865
|
+
return func.apply(recv, args);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
return recv.$method_missing.apply(recv, [mid].concat(args));
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
Opal.block_send = function(recv, mid, block) {
|
|
872
|
+
var args = $slice.call(arguments, 3),
|
|
873
|
+
func = recv['$' + mid];
|
|
874
|
+
|
|
875
|
+
if (func) {
|
|
876
|
+
func.$$p = block;
|
|
877
|
+
return func.apply(recv, args);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
return recv.$method_missing.apply(recv, [mid].concat(args));
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
/*
|
|
884
|
+
* Donate methods for a class/module
|
|
885
|
+
*/
|
|
886
|
+
Opal.donate = function(klass, defined, indirect) {
|
|
887
|
+
var methods = klass.$$methods, included_in = klass.$$dep;
|
|
888
|
+
|
|
889
|
+
// if (!indirect) {
|
|
890
|
+
klass.$$methods = methods.concat(defined);
|
|
891
|
+
// }
|
|
892
|
+
|
|
893
|
+
if (included_in) {
|
|
894
|
+
for (var i = 0, length = included_in.length; i < length; i++) {
|
|
895
|
+
var includee = included_in[i];
|
|
896
|
+
var dest = includee.$$proto;
|
|
897
|
+
|
|
898
|
+
for (var j = 0, jj = defined.length; j < jj; j++) {
|
|
899
|
+
var method = defined[j];
|
|
900
|
+
|
|
901
|
+
dest[method] = klass.$$proto[method];
|
|
902
|
+
dest[method].$$donated = true;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
if (includee.$$dep) {
|
|
906
|
+
Opal.donate(includee, defined, true);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
|
|
912
|
+
Opal.defn = function(obj, jsid, body) {
|
|
913
|
+
if (obj.$$is_mod) {
|
|
914
|
+
obj.$$proto[jsid] = body;
|
|
915
|
+
Opal.donate(obj, [jsid]);
|
|
916
|
+
}
|
|
917
|
+
else if (obj.$$is_class) {
|
|
918
|
+
obj.$$proto[jsid] = body;
|
|
919
|
+
|
|
920
|
+
if (obj === BasicObjectClass) {
|
|
921
|
+
define_basic_object_method(jsid, body);
|
|
922
|
+
}
|
|
923
|
+
else if (obj === ObjectClass) {
|
|
924
|
+
Opal.donate(obj, [jsid]);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
else {
|
|
928
|
+
obj[jsid] = body;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
return nil;
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
/*
|
|
935
|
+
* Define a singleton method on the given object.
|
|
936
|
+
*/
|
|
937
|
+
Opal.defs = function(obj, jsid, body) {
|
|
938
|
+
if (obj.$$is_class || obj.$$is_mod) {
|
|
939
|
+
obj.constructor.prototype[jsid] = body;
|
|
940
|
+
}
|
|
941
|
+
else {
|
|
942
|
+
obj[jsid] = body;
|
|
943
|
+
}
|
|
944
|
+
};
|
|
945
|
+
|
|
946
|
+
function define_basic_object_method(jsid, body) {
|
|
947
|
+
BasicObjectClass.$$methods.push(jsid);
|
|
948
|
+
for (var i = 0, len = bridged_classes.length; i < len; i++) {
|
|
949
|
+
bridged_classes[i].$$proto[jsid] = body;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
Opal.hash = function() {
|
|
954
|
+
if (arguments.length == 1 && arguments[0].$$class == Opal.Hash) {
|
|
955
|
+
return arguments[0];
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
var hash = new Opal.Hash.$$alloc(),
|
|
959
|
+
keys = [],
|
|
960
|
+
assocs = {},
|
|
961
|
+
key, obj, length;
|
|
962
|
+
|
|
963
|
+
hash.map = assocs;
|
|
964
|
+
hash.keys = keys;
|
|
965
|
+
|
|
966
|
+
if (arguments.length == 1) {
|
|
967
|
+
if (arguments[0].$$is_array) {
|
|
968
|
+
var args = arguments[0];
|
|
969
|
+
|
|
970
|
+
for (var i = 0, ii = args.length; i < ii; i++) {
|
|
971
|
+
var pair = args[i];
|
|
972
|
+
|
|
973
|
+
if (pair.length !== 2) {
|
|
974
|
+
throw Opal.ArgumentError.$new("value not of length 2: " + pair.$inspect());
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
key = pair[0];
|
|
978
|
+
obj = pair[1];
|
|
979
|
+
|
|
980
|
+
if (assocs[key] == null) {
|
|
981
|
+
keys.push(key);
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
assocs[key] = obj;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
else {
|
|
988
|
+
obj = arguments[0];
|
|
989
|
+
for (key in obj) {
|
|
990
|
+
assocs[key] = obj[key];
|
|
991
|
+
keys.push(key);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
else {
|
|
996
|
+
length = arguments.length;
|
|
997
|
+
if (length % 2 !== 0) {
|
|
998
|
+
throw Opal.ArgumentError.$new("odd number of arguments for Hash");
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
for (var j = 0; j < length; j++) {
|
|
1002
|
+
key = arguments[j];
|
|
1003
|
+
obj = arguments[++j];
|
|
1004
|
+
|
|
1005
|
+
if (assocs[key] == null) {
|
|
1006
|
+
keys.push(key);
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
assocs[key] = obj;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
return hash;
|
|
1014
|
+
};
|
|
1015
|
+
|
|
1016
|
+
/*
|
|
1017
|
+
* hash2 is a faster creator for hashes that just use symbols and
|
|
1018
|
+
* strings as keys. The map and keys array can be constructed at
|
|
1019
|
+
* compile time, so they are just added here by the constructor
|
|
1020
|
+
* function
|
|
1021
|
+
*/
|
|
1022
|
+
Opal.hash2 = function(keys, map) {
|
|
1023
|
+
var hash = new Opal.Hash.$$alloc();
|
|
1024
|
+
|
|
1025
|
+
hash.keys = keys;
|
|
1026
|
+
hash.map = map;
|
|
1027
|
+
|
|
1028
|
+
return hash;
|
|
1029
|
+
};
|
|
1030
|
+
|
|
1031
|
+
/*
|
|
1032
|
+
* Create a new range instance with first and last values, and whether the
|
|
1033
|
+
* range excludes the last value.
|
|
1034
|
+
*/
|
|
1035
|
+
Opal.range = function(first, last, exc) {
|
|
1036
|
+
var range = new Opal.Range.$$alloc();
|
|
1037
|
+
range.begin = first;
|
|
1038
|
+
range.end = last;
|
|
1039
|
+
range.exclude = exc;
|
|
1040
|
+
|
|
1041
|
+
return range;
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
// Require system
|
|
1045
|
+
// --------------
|
|
1046
|
+
(function(Opal) {
|
|
1047
|
+
var loaded_features = ['corelib/runtime.js'],
|
|
1048
|
+
require_table = {'corelib/runtime.js': true},
|
|
1049
|
+
modules = {};
|
|
1050
|
+
|
|
1051
|
+
var current_dir = '.',
|
|
1052
|
+
current_file = '.';
|
|
1053
|
+
|
|
1054
|
+
function mark_as_loaded(filename) {
|
|
1055
|
+
if (require_table[filename]) {
|
|
1056
|
+
return false;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
loaded_features.push(filename);
|
|
1060
|
+
require_table[filename] = true;
|
|
1061
|
+
|
|
1062
|
+
return true;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
function normalize_loadable_path(path) {
|
|
1066
|
+
var parts, part, new_parts = [], SEPARATOR = '/';
|
|
1067
|
+
|
|
1068
|
+
if (current_dir !== '.') {
|
|
1069
|
+
path = current_dir.replace(/\/*$/, '/') + path;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
parts = path.split(SEPARATOR);
|
|
1073
|
+
|
|
1074
|
+
for (var i = 0, ii = parts.length; i < ii; i++) {
|
|
1075
|
+
part = parts[i];
|
|
1076
|
+
(part === '..') ? new_parts.pop() : new_parts.push(part)
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
return new_parts.join(SEPARATOR);
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
function load(path) {
|
|
1083
|
+
mark_as_loaded(path);
|
|
1084
|
+
|
|
1085
|
+
var module = modules[path];
|
|
1086
|
+
|
|
1087
|
+
if (module) {
|
|
1088
|
+
var tmp = current_file;
|
|
1089
|
+
current_file = path;
|
|
1090
|
+
|
|
1091
|
+
module(Opal);
|
|
1092
|
+
|
|
1093
|
+
current_file = tmp;
|
|
1094
|
+
}
|
|
1095
|
+
else {
|
|
1096
|
+
var severity = Opal.dynamic_require_severity || 'warning';
|
|
1097
|
+
var message = 'cannot load such file -- ' + path;
|
|
1098
|
+
|
|
1099
|
+
if (severity === "error") {
|
|
1100
|
+
Opal.LoadError ? Opal.LoadError.$new(message) : function(){throw message}();
|
|
1101
|
+
}
|
|
1102
|
+
else if (severity === "warning") {
|
|
1103
|
+
Opal.gvars.stderr.$puts('WARNING: LoadError: ' + message);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
return true;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
function require(path) {
|
|
1111
|
+
if (require_table[path]) {
|
|
1112
|
+
return false;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
return load(path);
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
Opal.modules = modules;
|
|
1119
|
+
Opal.loaded_features = loaded_features;
|
|
1120
|
+
|
|
1121
|
+
Opal.normalize_loadable_path = normalize_loadable_path;
|
|
1122
|
+
Opal.mark_as_loaded = mark_as_loaded;
|
|
1123
|
+
|
|
1124
|
+
Opal.load = load;
|
|
1125
|
+
Opal.require = require;
|
|
1126
|
+
|
|
1127
|
+
Opal.current_file = current_file;
|
|
1128
|
+
})(Opal);
|
|
1129
|
+
|
|
1130
|
+
// Initialization
|
|
1131
|
+
// --------------
|
|
1132
|
+
|
|
1133
|
+
// The actual class for BasicObject
|
|
1134
|
+
var BasicObjectClass;
|
|
1135
|
+
|
|
1136
|
+
// The actual Object class
|
|
1137
|
+
var ObjectClass;
|
|
1138
|
+
|
|
1139
|
+
// The actual Module class
|
|
1140
|
+
var ModuleClass;
|
|
1141
|
+
|
|
1142
|
+
// The actual Class class
|
|
1143
|
+
var ClassClass;
|
|
1144
|
+
|
|
1145
|
+
// Constructor for instances of BasicObject
|
|
1146
|
+
function BasicObject(){}
|
|
1147
|
+
|
|
1148
|
+
// Constructor for instances of Object
|
|
1149
|
+
function Object(){}
|
|
1150
|
+
|
|
1151
|
+
// Constructor for instances of Class
|
|
1152
|
+
function Class(){}
|
|
1153
|
+
|
|
1154
|
+
// Constructor for instances of Module
|
|
1155
|
+
function Module(){}
|
|
1156
|
+
|
|
1157
|
+
// Constructor for instances of NilClass (nil)
|
|
1158
|
+
function NilClass(){}
|
|
1159
|
+
|
|
1160
|
+
// Constructors for *instances* of core objects
|
|
1161
|
+
boot_class_alloc('BasicObject', BasicObject);
|
|
1162
|
+
boot_class_alloc('Object', Object, BasicObject);
|
|
1163
|
+
boot_class_alloc('Module', Module, Object);
|
|
1164
|
+
boot_class_alloc('Class', Class, Module);
|
|
1165
|
+
|
|
1166
|
+
// Constructors for *classes* of core objects
|
|
1167
|
+
BasicObjectClass = boot_core_class_object('BasicObject', BasicObject, Class);
|
|
1168
|
+
ObjectClass = boot_core_class_object('Object', Object, BasicObjectClass.constructor);
|
|
1169
|
+
ModuleClass = boot_core_class_object('Module', Module, ObjectClass.constructor);
|
|
1170
|
+
ClassClass = boot_core_class_object('Class', Class, ModuleClass.constructor);
|
|
1171
|
+
|
|
1172
|
+
// Fix booted classes to use their metaclass
|
|
1173
|
+
BasicObjectClass.$$class = ClassClass;
|
|
1174
|
+
ObjectClass.$$class = ClassClass;
|
|
1175
|
+
ModuleClass.$$class = ClassClass;
|
|
1176
|
+
ClassClass.$$class = ClassClass;
|
|
1177
|
+
|
|
1178
|
+
// Fix superclasses of booted classes
|
|
1179
|
+
BasicObjectClass.$$super = null;
|
|
1180
|
+
ObjectClass.$$super = BasicObjectClass;
|
|
1181
|
+
ModuleClass.$$super = ObjectClass;
|
|
1182
|
+
ClassClass.$$super = ModuleClass;
|
|
1183
|
+
|
|
1184
|
+
BasicObjectClass.$$parent = null;
|
|
1185
|
+
ObjectClass.$$parent = BasicObjectClass;
|
|
1186
|
+
ModuleClass.$$parent = ObjectClass;
|
|
1187
|
+
ClassClass.$$parent = ModuleClass;
|
|
1188
|
+
|
|
1189
|
+
// Internally, Object acts like a module as it is "included" into bridged
|
|
1190
|
+
// classes. In other words, we donate methods from Object into our bridged
|
|
1191
|
+
// classes as their prototypes don't inherit from our root Object, so they
|
|
1192
|
+
// act like module includes.
|
|
1193
|
+
ObjectClass.$$dep = bridged_classes;
|
|
1194
|
+
|
|
1195
|
+
Opal.base = ObjectClass;
|
|
1196
|
+
BasicObjectClass.$$scope = ObjectClass.$$scope = Opal;
|
|
1197
|
+
BasicObjectClass.$$orig_scope = ObjectClass.$$orig_scope = Opal;
|
|
1198
|
+
Opal.Kernel = ObjectClass;
|
|
1199
|
+
|
|
1200
|
+
ModuleClass.$$scope = ObjectClass.$$scope;
|
|
1201
|
+
ModuleClass.$$orig_scope = ObjectClass.$$orig_scope;
|
|
1202
|
+
ClassClass.$$scope = ObjectClass.$$scope;
|
|
1203
|
+
ClassClass.$$orig_scope = ObjectClass.$$orig_scope;
|
|
1204
|
+
|
|
1205
|
+
ObjectClass.$$proto.toString = function() {
|
|
1206
|
+
return this.$to_s();
|
|
1207
|
+
};
|
|
1208
|
+
|
|
1209
|
+
ObjectClass.$$proto.$require = Opal.require;
|
|
1210
|
+
|
|
1211
|
+
Opal.top = new ObjectClass.$$alloc();
|
|
1212
|
+
|
|
1213
|
+
Opal.klass(ObjectClass, ObjectClass, 'NilClass', NilClass);
|
|
1214
|
+
|
|
1215
|
+
var nil = Opal.nil = new NilClass();
|
|
1216
|
+
nil.call = nil.apply = function() { throw Opal.LocalJumpError.$new('no block given'); };
|
|
1217
|
+
|
|
1218
|
+
Opal.breaker = new Error('unexpected break');
|
|
1219
|
+
Opal.returner = new Error('unexpected return');
|
|
1220
|
+
|
|
1221
|
+
bridge_class('Array', Array);
|
|
1222
|
+
bridge_class('Boolean', Boolean);
|
|
1223
|
+
bridge_class('Numeric', Number);
|
|
1224
|
+
bridge_class('String', String);
|
|
1225
|
+
bridge_class('Proc', Function);
|
|
1226
|
+
bridge_class('Exception', Error);
|
|
1227
|
+
bridge_class('Regexp', RegExp);
|
|
1228
|
+
bridge_class('Time', Date);
|
|
1229
|
+
|
|
1230
|
+
TypeError.$$super = Error;
|
|
1231
|
+
}).call(this);
|
|
1232
|
+
|
|
1233
|
+
if (typeof(global) !== 'undefined') {
|
|
1234
|
+
global.Opal = this.Opal;
|
|
1235
|
+
Opal.global = global;
|
|
1236
|
+
}
|
|
1237
|
+
if (typeof(window) !== 'undefined') {
|
|
1238
|
+
window.Opal = this.Opal;
|
|
1239
|
+
Opal.global = window;
|
|
1240
|
+
}
|