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,78 @@
|
|
|
1
|
+
class String
|
|
2
|
+
def self.inherited(klass)
|
|
3
|
+
replace = Class.new(String::Wrapper)
|
|
4
|
+
|
|
5
|
+
%x{
|
|
6
|
+
klass.$$proto = replace.$$proto;
|
|
7
|
+
klass.$$proto.$$class = klass;
|
|
8
|
+
klass.$$alloc = replace.$$alloc;
|
|
9
|
+
klass.$$parent = #{String::Wrapper};
|
|
10
|
+
|
|
11
|
+
klass.$allocate = replace.$allocate;
|
|
12
|
+
klass.$new = replace.$new;
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class String::Wrapper
|
|
18
|
+
def self.allocate(string = "")
|
|
19
|
+
obj = super()
|
|
20
|
+
`obj.literal = string`
|
|
21
|
+
obj
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.new(*args, &block)
|
|
25
|
+
obj = allocate
|
|
26
|
+
obj.initialize(*args, &block)
|
|
27
|
+
obj
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.[](*objects)
|
|
31
|
+
allocate(objects)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def initialize(string = '')
|
|
35
|
+
@literal = string
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def method_missing(*args, &block)
|
|
39
|
+
result = @literal.__send__(*args, &block)
|
|
40
|
+
|
|
41
|
+
if `result.$$is_string != null`
|
|
42
|
+
if `result == #@literal`
|
|
43
|
+
self
|
|
44
|
+
else
|
|
45
|
+
self.class.allocate(result)
|
|
46
|
+
end
|
|
47
|
+
else
|
|
48
|
+
result
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def initialize_copy(other)
|
|
53
|
+
@literal = `other.literal`.clone
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def respond_to?(name, *)
|
|
57
|
+
super || @literal.respond_to?(name)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def ==(other)
|
|
61
|
+
@literal == other
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
alias eql? ==
|
|
65
|
+
alias === ==
|
|
66
|
+
|
|
67
|
+
def to_s
|
|
68
|
+
@literal
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def to_str
|
|
72
|
+
self
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def inspect
|
|
76
|
+
@literal.inspect
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
class Struct
|
|
2
|
+
def self.new(name = undefined, *args, &block)
|
|
3
|
+
return super unless self == Struct
|
|
4
|
+
|
|
5
|
+
if name[0] == name[0].upcase
|
|
6
|
+
Struct.const_set(name, new(*args))
|
|
7
|
+
else
|
|
8
|
+
args.unshift name
|
|
9
|
+
|
|
10
|
+
Class.new(self) {
|
|
11
|
+
args.each { |arg| define_struct_attribute arg }
|
|
12
|
+
|
|
13
|
+
instance_eval(&block) if block
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.define_struct_attribute(name)
|
|
19
|
+
if self == Struct
|
|
20
|
+
raise ArgumentError, 'you cannot define attributes to the Struct class'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
members << name
|
|
24
|
+
|
|
25
|
+
define_method name do
|
|
26
|
+
instance_variable_get "@#{name}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
define_method "#{name}=" do |value|
|
|
30
|
+
instance_variable_set "@#{name}", value
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.members
|
|
35
|
+
if self == Struct
|
|
36
|
+
raise ArgumentError, 'the Struct class has no members'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
@members ||= []
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.inherited(klass)
|
|
43
|
+
return if self == Struct
|
|
44
|
+
|
|
45
|
+
members = @members
|
|
46
|
+
|
|
47
|
+
klass.instance_eval {
|
|
48
|
+
@members = members
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class << self
|
|
53
|
+
alias [] new
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
include Enumerable
|
|
57
|
+
|
|
58
|
+
def initialize(*args)
|
|
59
|
+
members.each_with_index {|name, index|
|
|
60
|
+
instance_variable_set "@#{name}", args[index]
|
|
61
|
+
}
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def members
|
|
65
|
+
self.class.members
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def [](name)
|
|
69
|
+
if Integer === name
|
|
70
|
+
raise IndexError, "offset #{name} too large for struct(size:#{members.size})" if name >= members.size
|
|
71
|
+
|
|
72
|
+
name = members[name]
|
|
73
|
+
else
|
|
74
|
+
raise NameError, "no member '#{name}' in struct" unless members.include?(name.to_sym)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
instance_variable_get "@#{name}"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def []=(name, value)
|
|
81
|
+
if Integer === name
|
|
82
|
+
raise IndexError, "offset #{name} too large for struct(size:#{members.size})" if name >= members.size
|
|
83
|
+
|
|
84
|
+
name = members[name]
|
|
85
|
+
else
|
|
86
|
+
raise NameError, "no member '#{name}' in struct" unless members.include?(name.to_sym)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
instance_variable_set "@#{name}", value
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def each
|
|
93
|
+
return enum_for :each unless block_given?
|
|
94
|
+
|
|
95
|
+
members.each { |name| yield self[name] }
|
|
96
|
+
self
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def each_pair
|
|
100
|
+
return enum_for :each_pair unless block_given?
|
|
101
|
+
|
|
102
|
+
members.each { |name| yield name, self[name] }
|
|
103
|
+
self
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def eql?(other)
|
|
107
|
+
hash == other.hash || other.each_with_index.all? {|object, index|
|
|
108
|
+
self[members[index]] == object
|
|
109
|
+
}
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def length
|
|
113
|
+
members.length
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
alias size length
|
|
117
|
+
|
|
118
|
+
def to_a
|
|
119
|
+
members.map { |name| self[name] }
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
alias values to_a
|
|
123
|
+
|
|
124
|
+
def inspect
|
|
125
|
+
result = "#<struct "
|
|
126
|
+
|
|
127
|
+
if self.class == Struct
|
|
128
|
+
result += "#{self.class.name} "
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
result += each_pair.map {|name, value|
|
|
132
|
+
"#{name}=#{value.inspect}"
|
|
133
|
+
}.join ", "
|
|
134
|
+
|
|
135
|
+
result += ">"
|
|
136
|
+
|
|
137
|
+
result
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
alias to_s inspect
|
|
141
|
+
end
|
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
require 'corelib/comparable'
|
|
2
|
+
|
|
3
|
+
class Time
|
|
4
|
+
include Comparable
|
|
5
|
+
|
|
6
|
+
%x{
|
|
7
|
+
var days_of_week = #{%w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sunday]},
|
|
8
|
+
short_days = #{%w[Sun Mon Tue Wed Thu Fri Sat]},
|
|
9
|
+
short_months = #{%w[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec]},
|
|
10
|
+
long_months = #{%w[January February March April May June July August September October November December]};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
def self.at(seconds, frac = 0)
|
|
14
|
+
`new Date(seconds * 1000 + frac)`
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.new(year = undefined, month = undefined, day = undefined, hour = undefined, minute = undefined, second = undefined, utc_offset = undefined)
|
|
18
|
+
%x{
|
|
19
|
+
switch (arguments.length) {
|
|
20
|
+
case 1:
|
|
21
|
+
return new Date(year, 0);
|
|
22
|
+
|
|
23
|
+
case 2:
|
|
24
|
+
return new Date(year, month - 1);
|
|
25
|
+
|
|
26
|
+
case 3:
|
|
27
|
+
return new Date(year, month - 1, day);
|
|
28
|
+
|
|
29
|
+
case 4:
|
|
30
|
+
return new Date(year, month - 1, day, hour);
|
|
31
|
+
|
|
32
|
+
case 5:
|
|
33
|
+
return new Date(year, month - 1, day, hour, minute);
|
|
34
|
+
|
|
35
|
+
case 6:
|
|
36
|
+
return new Date(year, month - 1, day, hour, minute, second);
|
|
37
|
+
|
|
38
|
+
case 7:
|
|
39
|
+
return new Date(year, month - 1, day, hour, minute, second);
|
|
40
|
+
|
|
41
|
+
default:
|
|
42
|
+
return new Date();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.local(year, month = nil, day = nil, hour = nil, minute = nil, second = nil, millisecond = nil)
|
|
48
|
+
if `arguments.length === 10`
|
|
49
|
+
%x{
|
|
50
|
+
var args = $slice.call(arguments).reverse();
|
|
51
|
+
|
|
52
|
+
second = args[9];
|
|
53
|
+
minute = args[8];
|
|
54
|
+
hour = args[7];
|
|
55
|
+
day = args[6];
|
|
56
|
+
month = args[5];
|
|
57
|
+
year = args[4];
|
|
58
|
+
}
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
year = year.kind_of?(String) ? year.to_i : Opal.coerce_to(year, Integer, :to_int)
|
|
62
|
+
|
|
63
|
+
month = month.kind_of?(String) ? month.to_i : Opal.coerce_to(month || 1, Integer, :to_int)
|
|
64
|
+
|
|
65
|
+
unless month.between?(1, 12)
|
|
66
|
+
raise ArgumentError, "month out of range: #{month}"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
day = day.kind_of?(String) ? day.to_i : Opal.coerce_to(day || 1, Integer, :to_int)
|
|
70
|
+
|
|
71
|
+
unless day.between?(1, 31)
|
|
72
|
+
raise ArgumentError, "day out of range: #{day}"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
hour = hour.kind_of?(String) ? hour.to_i : Opal.coerce_to(hour || 0, Integer, :to_int)
|
|
76
|
+
|
|
77
|
+
unless hour.between?(0, 24)
|
|
78
|
+
raise ArgumentError, "hour out of range: #{hour}"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
minute = minute.kind_of?(String) ? minute.to_i : Opal.coerce_to(minute || 0, Integer, :to_int)
|
|
82
|
+
|
|
83
|
+
unless minute.between?(0, 59)
|
|
84
|
+
raise ArgumentError, "minute out of range: #{minute}"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
second = second.kind_of?(String) ? second.to_i : Opal.coerce_to(second || 0, Integer, :to_int)
|
|
88
|
+
|
|
89
|
+
unless second.between?(0, 59)
|
|
90
|
+
raise ArgumentError, "second out of range: #{second}"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
new(*[year, month, day, hour, minute, second].compact)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def self.gm(year, month = undefined, day = undefined, hour = undefined, minute = undefined, second = undefined, utc_offset = undefined)
|
|
97
|
+
raise TypeError, 'missing year (got nil)' if year.nil?
|
|
98
|
+
|
|
99
|
+
%x{
|
|
100
|
+
if (month > 12 || day > 31 || hour > 24 || minute > 59 || second > 59) {
|
|
101
|
+
#{raise ArgumentError};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var date = new Date(Date.UTC(year, (month || 1) - 1, (day || 1), (hour || 0), (minute || 0), (second || 0)));
|
|
105
|
+
date.tz_offset = 0
|
|
106
|
+
return date;
|
|
107
|
+
}
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
class << self
|
|
111
|
+
alias mktime local
|
|
112
|
+
alias utc gm
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def self.now
|
|
116
|
+
`new Date()`
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def +(other)
|
|
120
|
+
if Time === other
|
|
121
|
+
raise TypeError, "time + time?"
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
other = Opal.coerce_to other, Integer, :to_int
|
|
125
|
+
|
|
126
|
+
%x{
|
|
127
|
+
var result = new Date(self.getTime() + (other * 1000));
|
|
128
|
+
result.tz_offset = #@tz_offset;
|
|
129
|
+
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def -(other)
|
|
135
|
+
if Time === other
|
|
136
|
+
return `(self.getTime() - other.getTime()) / 1000`
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
other = Opal.coerce_to other, Integer, :to_int
|
|
140
|
+
|
|
141
|
+
%x{
|
|
142
|
+
var result = new Date(self.getTime() - (other * 1000));
|
|
143
|
+
result.tz_offset = #@tz_offset;
|
|
144
|
+
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def <=>(other)
|
|
150
|
+
to_f <=> other.to_f
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def ==(other)
|
|
154
|
+
`#{to_f} === #{other.to_f}`
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def asctime
|
|
158
|
+
strftime '%a %b %e %H:%M:%S %Y'
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
alias ctime asctime
|
|
162
|
+
|
|
163
|
+
def day
|
|
164
|
+
%x{
|
|
165
|
+
if (#@tz_offset === 0) {
|
|
166
|
+
return self.getUTCDate();
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return self.getDate();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def yday
|
|
175
|
+
%x{
|
|
176
|
+
// http://javascript.about.com/library/bldayyear.htm
|
|
177
|
+
var onejan = new Date(self.getFullYear(), 0, 1);
|
|
178
|
+
return Math.ceil((self - onejan) / 86400000);
|
|
179
|
+
}
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def isdst
|
|
183
|
+
raise NotImplementedError
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def eql?(other)
|
|
187
|
+
other.is_a?(Time) && (self <=> other).zero?
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def friday?
|
|
191
|
+
`#{wday} == 5`
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def hour
|
|
195
|
+
%x{
|
|
196
|
+
if (#@tz_offset === 0) {
|
|
197
|
+
return self.getUTCHours();
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
return self.getHours();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def inspect
|
|
206
|
+
if utc?
|
|
207
|
+
strftime '%Y-%m-%d %H:%M:%S UTC'
|
|
208
|
+
else
|
|
209
|
+
strftime '%Y-%m-%d %H:%M:%S %z'
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
alias mday day
|
|
214
|
+
|
|
215
|
+
def min
|
|
216
|
+
%x{
|
|
217
|
+
if (#@tz_offset === 0) {
|
|
218
|
+
return self.getUTCMinutes();
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
return self.getMinutes();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def mon
|
|
227
|
+
%x{
|
|
228
|
+
if (#@tz_offset === 0) {
|
|
229
|
+
return self.getUTCMonth() + 1;
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
return self.getMonth() + 1;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def monday?
|
|
238
|
+
`#{wday} == 1`
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
alias month mon
|
|
242
|
+
|
|
243
|
+
def saturday?
|
|
244
|
+
`#{wday} == 6`
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def sec
|
|
248
|
+
%x{
|
|
249
|
+
if (#@tz_offset === 0) {
|
|
250
|
+
return self.getUTCSeconds();
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
return self.getSeconds();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def usec
|
|
259
|
+
warn 'Microseconds are not supported'
|
|
260
|
+
0
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def zone
|
|
264
|
+
%x{
|
|
265
|
+
var string = self.toString(),
|
|
266
|
+
result;
|
|
267
|
+
|
|
268
|
+
if (string.indexOf('(') == -1) {
|
|
269
|
+
result = string.match(/[A-Z]{3,4}/)[0];
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
result = string.match(/\([^)]+\)/)[0].match(/[A-Z]/g).join('');
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (result == "GMT" && /(GMT\W*\d{4})/.test(string)) {
|
|
276
|
+
return RegExp.$1;
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def getgm
|
|
285
|
+
%x{
|
|
286
|
+
var result = new Date(self.getTime());
|
|
287
|
+
result.tz_offset = 0;
|
|
288
|
+
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
def gmt?
|
|
294
|
+
`#@tz_offset === 0`
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
def gmt_offset
|
|
298
|
+
`-self.getTimezoneOffset() * 60`
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
def strftime(format)
|
|
302
|
+
%x{
|
|
303
|
+
return format.replace(/%([\-_#^0]*:{0,2})(\d+)?([EO]*)(.)/g, function(full, flags, width, _, conv) {
|
|
304
|
+
var result = "",
|
|
305
|
+
width = parseInt(width),
|
|
306
|
+
zero = flags.indexOf('0') !== -1,
|
|
307
|
+
pad = flags.indexOf('-') === -1,
|
|
308
|
+
blank = flags.indexOf('_') !== -1,
|
|
309
|
+
upcase = flags.indexOf('^') !== -1,
|
|
310
|
+
invert = flags.indexOf('#') !== -1,
|
|
311
|
+
colons = (flags.match(':') || []).length;
|
|
312
|
+
|
|
313
|
+
if (zero && blank) {
|
|
314
|
+
if (flags.indexOf('0') < flags.indexOf('_')) {
|
|
315
|
+
zero = false;
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
blank = false;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
switch (conv) {
|
|
323
|
+
case 'Y':
|
|
324
|
+
result += #{year};
|
|
325
|
+
break;
|
|
326
|
+
|
|
327
|
+
case 'C':
|
|
328
|
+
zero = !blank;
|
|
329
|
+
result += Match.round(#{year} / 100);
|
|
330
|
+
break;
|
|
331
|
+
|
|
332
|
+
case 'y':
|
|
333
|
+
zero = !blank;
|
|
334
|
+
result += (#{year} % 100);
|
|
335
|
+
break;
|
|
336
|
+
|
|
337
|
+
case 'm':
|
|
338
|
+
zero = !blank;
|
|
339
|
+
result += #{mon};
|
|
340
|
+
break;
|
|
341
|
+
|
|
342
|
+
case 'B':
|
|
343
|
+
result += long_months[#{mon} - 1];
|
|
344
|
+
break;
|
|
345
|
+
|
|
346
|
+
case 'b':
|
|
347
|
+
case 'h':
|
|
348
|
+
blank = !zero;
|
|
349
|
+
result += short_months[#{mon} - 1];
|
|
350
|
+
break;
|
|
351
|
+
|
|
352
|
+
case 'd':
|
|
353
|
+
zero = !blank
|
|
354
|
+
result += #{day};
|
|
355
|
+
break;
|
|
356
|
+
|
|
357
|
+
case 'e':
|
|
358
|
+
blank = !zero
|
|
359
|
+
result += #{day};
|
|
360
|
+
break;
|
|
361
|
+
|
|
362
|
+
case 'j':
|
|
363
|
+
result += #{yday};
|
|
364
|
+
break;
|
|
365
|
+
|
|
366
|
+
case 'H':
|
|
367
|
+
zero = !blank;
|
|
368
|
+
result += #{hour};
|
|
369
|
+
break;
|
|
370
|
+
|
|
371
|
+
case 'k':
|
|
372
|
+
blank = !zero;
|
|
373
|
+
result += #{hour};
|
|
374
|
+
break;
|
|
375
|
+
|
|
376
|
+
case 'I':
|
|
377
|
+
zero = !blank;
|
|
378
|
+
result += (#{hour} % 12 || 12);
|
|
379
|
+
break;
|
|
380
|
+
|
|
381
|
+
case 'l':
|
|
382
|
+
blank = !zero;
|
|
383
|
+
result += (#{hour} % 12 || 12);
|
|
384
|
+
break;
|
|
385
|
+
|
|
386
|
+
case 'P':
|
|
387
|
+
result += (#{hour} >= 12 ? "pm" : "am");
|
|
388
|
+
break;
|
|
389
|
+
|
|
390
|
+
case 'p':
|
|
391
|
+
result += (#{hour} >= 12 ? "PM" : "AM");
|
|
392
|
+
break;
|
|
393
|
+
|
|
394
|
+
case 'M':
|
|
395
|
+
zero = !blank;
|
|
396
|
+
result += #{min};
|
|
397
|
+
break;
|
|
398
|
+
|
|
399
|
+
case 'S':
|
|
400
|
+
zero = !blank;
|
|
401
|
+
result += #{sec}
|
|
402
|
+
break;
|
|
403
|
+
|
|
404
|
+
case 'L':
|
|
405
|
+
zero = !blank;
|
|
406
|
+
width = isNaN(width) ? 3 : width;
|
|
407
|
+
result += self.getMilliseconds();
|
|
408
|
+
break;
|
|
409
|
+
|
|
410
|
+
case 'N':
|
|
411
|
+
width = isNaN(width) ? 9 : width;
|
|
412
|
+
result += #{`self.getMilliseconds().toString()`.rjust(3, '0')};
|
|
413
|
+
result = #{`result`.ljust(`width`, '0')};
|
|
414
|
+
break;
|
|
415
|
+
|
|
416
|
+
case 'z':
|
|
417
|
+
var offset = self.getTimezoneOffset(),
|
|
418
|
+
hours = Math.floor(Math.abs(offset) / 60),
|
|
419
|
+
minutes = Math.abs(offset) % 60;
|
|
420
|
+
|
|
421
|
+
result += offset < 0 ? "+" : "-";
|
|
422
|
+
result += hours < 10 ? "0" : "";
|
|
423
|
+
result += hours;
|
|
424
|
+
|
|
425
|
+
if (colons > 0) {
|
|
426
|
+
result += ":";
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
result += minutes < 10 ? "0" : "";
|
|
430
|
+
result += minutes;
|
|
431
|
+
|
|
432
|
+
if (colons > 1) {
|
|
433
|
+
result += ":00";
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
break;
|
|
437
|
+
|
|
438
|
+
case 'Z':
|
|
439
|
+
result += #{zone};
|
|
440
|
+
break;
|
|
441
|
+
|
|
442
|
+
case 'A':
|
|
443
|
+
result += days_of_week[#{wday}];
|
|
444
|
+
break;
|
|
445
|
+
|
|
446
|
+
case 'a':
|
|
447
|
+
result += short_days[#{wday}];
|
|
448
|
+
break;
|
|
449
|
+
|
|
450
|
+
case 'u':
|
|
451
|
+
result += (#{wday} + 1);
|
|
452
|
+
break;
|
|
453
|
+
|
|
454
|
+
case 'w':
|
|
455
|
+
result += #{wday};
|
|
456
|
+
break;
|
|
457
|
+
|
|
458
|
+
// TODO: week year
|
|
459
|
+
// TODO: week number
|
|
460
|
+
|
|
461
|
+
case 's':
|
|
462
|
+
result += #{to_i};
|
|
463
|
+
break;
|
|
464
|
+
|
|
465
|
+
case 'n':
|
|
466
|
+
result += "\n";
|
|
467
|
+
break;
|
|
468
|
+
|
|
469
|
+
case 't':
|
|
470
|
+
result += "\t";
|
|
471
|
+
break;
|
|
472
|
+
|
|
473
|
+
case '%':
|
|
474
|
+
result += "%";
|
|
475
|
+
break;
|
|
476
|
+
|
|
477
|
+
case 'c':
|
|
478
|
+
result += #{strftime('%a %b %e %T %Y')};
|
|
479
|
+
break;
|
|
480
|
+
|
|
481
|
+
case 'D':
|
|
482
|
+
case 'x':
|
|
483
|
+
result += #{strftime('%m/%d/%y')};
|
|
484
|
+
break;
|
|
485
|
+
|
|
486
|
+
case 'F':
|
|
487
|
+
result += #{strftime('%Y-%m-%d')};
|
|
488
|
+
break;
|
|
489
|
+
|
|
490
|
+
case 'v':
|
|
491
|
+
result += #{strftime('%e-%^b-%4Y')};
|
|
492
|
+
break;
|
|
493
|
+
|
|
494
|
+
case 'r':
|
|
495
|
+
result += #{strftime('%I:%M:%S %p')};
|
|
496
|
+
break;
|
|
497
|
+
|
|
498
|
+
case 'R':
|
|
499
|
+
result += #{strftime('%H:%M')};
|
|
500
|
+
break;
|
|
501
|
+
|
|
502
|
+
case 'T':
|
|
503
|
+
case 'X':
|
|
504
|
+
result += #{strftime('%H:%M:%S')};
|
|
505
|
+
break;
|
|
506
|
+
|
|
507
|
+
default:
|
|
508
|
+
return full;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (upcase) {
|
|
512
|
+
result = result.toUpperCase();
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
if (invert) {
|
|
516
|
+
result = result.replace(/[A-Z]/, function(c) { c.toLowerCase() }).
|
|
517
|
+
replace(/[a-z]/, function(c) { c.toUpperCase() });
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
if (pad && (zero || blank)) {
|
|
521
|
+
result = #{`result`.rjust(`isNaN(width) ? 2 : width`, `blank ? " " : "0"`)};
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
return result;
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
end
|
|
528
|
+
|
|
529
|
+
def sunday?
|
|
530
|
+
`#{wday} == 0`
|
|
531
|
+
end
|
|
532
|
+
|
|
533
|
+
def thursday?
|
|
534
|
+
`#{wday} == 4`
|
|
535
|
+
end
|
|
536
|
+
|
|
537
|
+
def to_a
|
|
538
|
+
[sec, min, hour, day, month, year, wday, yday, isdst, zone]
|
|
539
|
+
end
|
|
540
|
+
|
|
541
|
+
def to_f
|
|
542
|
+
`self.getTime() / 1000`
|
|
543
|
+
end
|
|
544
|
+
|
|
545
|
+
def to_i
|
|
546
|
+
`parseInt(self.getTime() / 1000)`
|
|
547
|
+
end
|
|
548
|
+
|
|
549
|
+
alias to_s inspect
|
|
550
|
+
|
|
551
|
+
def tuesday?
|
|
552
|
+
`#{wday} == 2`
|
|
553
|
+
end
|
|
554
|
+
|
|
555
|
+
alias utc? gmt?
|
|
556
|
+
|
|
557
|
+
alias utc_offset gmt_offset
|
|
558
|
+
|
|
559
|
+
def wday
|
|
560
|
+
%x{
|
|
561
|
+
if (#@tz_offset === 0) {
|
|
562
|
+
return self.getUTCDay();
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
return self.getDay();
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
end
|
|
569
|
+
|
|
570
|
+
def wednesday?
|
|
571
|
+
`#{wday} == 3`
|
|
572
|
+
end
|
|
573
|
+
|
|
574
|
+
def year
|
|
575
|
+
%x{
|
|
576
|
+
if (#@tz_offset === 0) {
|
|
577
|
+
return self.getUTCFullYear();
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
return self.getFullYear();
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
end
|
|
584
|
+
end
|