opal 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +3 -0
- data/.travis.yml +0 -4
- data/README.md +6 -0
- data/Rakefile +30 -6
- data/bin/opal +6 -82
- data/corelib/{opal/array.rb → array.rb} +40 -56
- data/corelib/{opal/basic_object.rb → basic_object.rb} +2 -2
- data/corelib/{opal/boolean.rb → boolean.rb} +0 -8
- data/corelib/class.rb +47 -0
- data/corelib/{opal/comparable.rb → comparable.rb} +0 -0
- data/corelib/{opal/enumerable.rb → enumerable.rb} +208 -141
- data/corelib/{opal/enumerator.rb → enumerator.rb} +3 -3
- data/corelib/{opal/error.rb → error.rb} +1 -0
- data/corelib/{opal/hash.rb → hash.rb} +67 -56
- data/corelib/io.rb +39 -0
- data/corelib/{opal/kernel.rb → kernel.rb} +35 -31
- data/corelib/{opal/class.rb → module.rb} +29 -57
- data/corelib/native.rb +148 -0
- data/corelib/{opal/nil_class.rb → nil_class.rb} +2 -10
- data/corelib/{opal/numeric.rb → numeric.rb} +39 -14
- data/corelib/opal.rb +42 -25
- data/corelib/{opal/proc.rb → proc.rb} +3 -3
- data/corelib/{opal/range.rb → range.rb} +5 -1
- data/corelib/{opal/regexp.rb → regexp.rb} +0 -0
- data/corelib/{opal/runtime.js → runtime.js} +96 -188
- data/corelib/{opal/string.rb → string.rb} +20 -15
- data/corelib/struct.rb +139 -0
- data/corelib/{opal/time.rb → time.rb} +0 -0
- data/lib/opal.rb +4 -0
- data/lib/opal/cli.rb +79 -32
- data/lib/opal/cli_options.rb +91 -0
- data/lib/opal/erb.rb +41 -8
- data/lib/opal/grammar.rb +24 -10
- data/lib/opal/grammar.y +15 -4
- data/lib/opal/grammar_helpers.rb +4 -0
- data/lib/opal/lexer.rb +214 -143
- data/lib/opal/parser.rb +596 -562
- data/lib/opal/require_parser.rb +1 -1
- data/lib/opal/source_map.rb +15 -30
- data/lib/opal/target_scope.rb +24 -5
- data/lib/opal/version.rb +1 -1
- data/mri_spec/cli_spec.rb +18 -0
- data/mri_spec/fixtures/opal_file.rb +2 -0
- data/mri_spec/spec_helper.rb +17 -0
- data/opal.gemspec +5 -2
- data/spec/{rubyspec/filters → filters}/bugs/alias.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/ancestors.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array.rb +0 -0
- data/spec/filters/bugs/array/combination.rb +11 -0
- data/spec/filters/bugs/array/count.rb +3 -0
- data/spec/filters/bugs/array/delete_if.rb +3 -0
- data/spec/filters/bugs/array/drop.rb +3 -0
- data/spec/filters/bugs/array/drop_while.rb +5 -0
- data/spec/filters/bugs/array/eql.rb +3 -0
- data/spec/filters/bugs/array/flatten.rb +9 -0
- data/spec/filters/bugs/array/minus.rb +5 -0
- data/spec/filters/bugs/array/multipliy.rb +9 -0
- data/spec/filters/bugs/array/new.rb +3 -0
- data/spec/filters/bugs/array/pop.rb +6 -0
- data/spec/filters/bugs/array/rassoc.rb +4 -0
- data/spec/filters/bugs/array/rindex.rb +6 -0
- data/spec/filters/bugs/array/select.rb +3 -0
- data/spec/filters/bugs/array/shift.rb +7 -0
- data/spec/filters/bugs/array/shuffle.rb +11 -0
- data/spec/filters/bugs/array/slice.rb +7 -0
- data/spec/filters/bugs/array/take.rb +3 -0
- data/spec/filters/bugs/array/to_a.rb +3 -0
- data/spec/filters/bugs/array/try_convert.rb +7 -0
- data/spec/filters/bugs/array/uniq.rb +10 -0
- data/spec/filters/bugs/array/zip.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_delete.rb +1 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_fetch.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_first.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_flatten.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_intersection.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_join.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/break.rb +0 -0
- data/spec/filters/bugs/case.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/coerce_integer.rb +0 -0
- data/spec/filters/bugs/enumerable_sort_by.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/kernel/instance_variables.rb +0 -0
- data/spec/filters/bugs/kernel/rand.rb +4 -0
- data/spec/filters/bugs/language/array.rb +3 -0
- data/spec/filters/bugs/language/block.rb +6 -0
- data/spec/filters/bugs/language/break.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class_variables.rb +0 -0
- data/spec/filters/bugs/language/def.rb +27 -0
- data/spec/filters/bugs/language/defined.rb +3 -0
- data/spec/filters/bugs/language/ensure.rb +4 -0
- data/spec/filters/bugs/language/execution.rb +4 -0
- data/spec/filters/bugs/language/for.rb +18 -0
- data/spec/filters/bugs/language/if.rb +13 -0
- data/spec/filters/bugs/language/loop.rb +4 -0
- data/spec/filters/bugs/language/metaclass.rb +14 -0
- data/spec/filters/bugs/language/module.rb +6 -0
- data/spec/filters/bugs/language/next.rb +3 -0
- data/spec/filters/bugs/language/or.rb +3 -0
- data/spec/filters/bugs/language/order.rb +4 -0
- data/spec/filters/bugs/language/precedence.rb +10 -0
- data/spec/filters/bugs/language/proc.rb +24 -0
- data/spec/filters/bugs/language/redo.rb +5 -0
- data/spec/filters/bugs/language/rescue.rb +9 -0
- data/spec/filters/bugs/language/retry.rb +5 -0
- data/spec/filters/bugs/language/send.rb +10 -0
- data/spec/filters/bugs/language/super.rb +9 -0
- data/spec/filters/bugs/language/until.rb +8 -0
- data/spec/filters/bugs/language/variables.rb +37 -0
- data/spec/filters/bugs/language/while.rb +6 -0
- data/spec/filters/bugs/language/yield.rb +5 -0
- data/spec/{rubyspec/filters → filters}/bugs/module/class_variables.rb +0 -0
- data/spec/filters/bugs/module/method_defined.rb +6 -0
- data/spec/filters/bugs/parser.rb +10 -0
- data/spec/{rubyspec/filters → filters}/bugs/public_methods.rb +1 -0
- data/spec/filters/bugs/return.rb +7 -0
- data/spec/filters/bugs/singleton/instance.rb +4 -0
- data/spec/filters/bugs/source_map.rb +3 -0
- data/spec/filters/bugs/string/center.rb +4 -0
- data/spec/filters/bugs/string/lines.rb +3 -0
- data/spec/{rubyspec/filters → filters}/mspec/mocks.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/ruby_exe.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/should_receive.rb +0 -0
- data/spec/{rubyspec/filters → filters}/parser/block_args.rb +0 -0
- data/spec/{rubyspec/filters → filters}/unsupported/array_subclasses.rb +1 -0
- data/spec/filters/unsupported/frozen.rb +32 -0
- data/spec/filters/unsupported/immutable_strings.rb +3 -0
- data/spec/filters/unsupported/tainted.rb +17 -0
- data/spec/filters/unsupported/trusted.rb +15 -0
- data/spec/opal/class/constants_spec.rb +7 -0
- data/spec/opal/erb/erb_spec.rb +7 -1
- data/spec/opal/erb/inline_block.opalerb +3 -0
- data/spec/opal/hash/allocate_spec.rb +16 -0
- data/spec/opal/hash/new_spec.rb +10 -0
- data/spec/opal/hash/to_s_spec.rb +9 -0
- data/spec/opal/kernel/instance_variable_defined_spec.rb +15 -0
- data/spec/opal/kernel/rand_spec.rb +5 -5
- data/spec/opal/kernel/respond_to_spec.rb +14 -1
- data/spec/opal/language/block_spec.rb +13 -0
- data/spec/opal/language/rescue_spec.rb +27 -0
- data/spec/opal/language/return_spec.rb +38 -0
- data/spec/opal/language/singleton_class_spec.rb +13 -0
- data/spec/opal/language/super_spec.rb +99 -0
- data/spec/opal/language/variables_spec.rb +20 -0
- data/spec/opal/module/attr_accessor_spec.rb +8 -0
- data/spec/opal/module/constants_spec.rb +2 -2
- data/spec/opal/native/alias_native_spec.rb +18 -0
- data/spec/opal/native/each_spec.rb +14 -0
- data/spec/opal/native/element_reference_spec.rb +14 -0
- data/spec/opal/native/method_missing_spec.rb +39 -0
- data/spec/opal/native/new_spec.rb +19 -0
- data/spec/opal/native/nil_spec.rb +14 -0
- data/spec/opal/runtime2/class_hierarchy_spec.rb +2 -2
- data/spec/opal/source_map_spec.rb +3 -7
- data/spec/ospec/main.rb.erb +2 -5
- data/spec/parser/alias_spec.rb +4 -4
- data/spec/parser/and_spec.rb +2 -2
- data/spec/parser/array_spec.rb +6 -6
- data/spec/parser/attrasgn_spec.rb +8 -8
- data/spec/parser/begin_spec.rb +11 -11
- data/spec/parser/block_spec.rb +3 -3
- data/spec/parser/break_spec.rb +4 -4
- data/spec/parser/call_spec.rb +50 -48
- data/spec/parser/class_spec.rb +2 -2
- data/spec/parser/const_spec.rb +1 -1
- data/spec/parser/cvar_spec.rb +1 -1
- data/spec/parser/def_spec.rb +5 -5
- data/spec/parser/gvar_spec.rb +2 -2
- data/spec/parser/hash_spec.rb +4 -4
- data/spec/parser/iasgn_spec.rb +3 -3
- data/spec/parser/if_spec.rb +6 -6
- data/spec/parser/iter_spec.rb +6 -6
- data/spec/parser/lambda_spec.rb +5 -5
- data/spec/parser/lasgn_spec.rb +2 -2
- data/spec/parser/line_spec.rb +2 -2
- data/spec/parser/lvar_spec.rb +5 -5
- data/spec/parser/masgn_spec.rb +1 -1
- data/spec/parser/module_spec.rb +2 -2
- data/spec/parser/not_spec.rb +4 -4
- data/spec/parser/op_asgn1_spec.rb +2 -2
- data/spec/parser/op_asgn2_spec.rb +2 -2
- data/spec/parser/or_spec.rb +2 -2
- data/spec/parser/parse_spec.rb +66 -0
- data/spec/parser/parser_spec.rb +32 -38
- data/spec/parser/regexp_spec.rb +4 -4
- data/spec/parser/return_spec.rb +4 -4
- data/spec/parser/sclass_spec.rb +4 -4
- data/spec/parser/str_spec.rb +3 -3
- data/spec/parser/super_spec.rb +6 -6
- data/spec/parser/undef_spec.rb +3 -3
- data/spec/parser/unless_spec.rb +4 -4
- data/spec/parser/while_spec.rb +3 -3
- data/spec/parser/xstr_spec.rb +3 -3
- data/spec/parser/yield_spec.rb +6 -6
- data/spec/rubyspec/core/array/drop_spec.rb +1 -1
- data/spec/rubyspec/core/array/keep_if_spec.rb +1 -3
- data/spec/rubyspec/core/array/length_spec.rb +1 -3
- data/spec/rubyspec/core/array/map_spec.rb +2 -6
- data/spec/rubyspec/core/array/minus_spec.rb +3 -3
- data/spec/rubyspec/core/array/multiply_spec.rb +14 -16
- data/spec/rubyspec/core/array/new_spec.rb +3 -5
- data/spec/rubyspec/core/array/plus_spec.rb +2 -2
- data/spec/rubyspec/core/array/pop_spec.rb +4 -4
- data/spec/rubyspec/core/array/rassoc_spec.rb +2 -2
- data/spec/rubyspec/core/array/reject_spec.rb +2 -6
- data/spec/rubyspec/core/array/replace_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_each_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_spec.rb +4 -4
- data/spec/rubyspec/core/array/rindex_spec.rb +1 -1
- data/spec/rubyspec/core/array/select_spec.rb +3 -7
- data/spec/rubyspec/core/array/shared/collect.rb +7 -0
- data/spec/rubyspec/core/array/shared/index.rb +1 -1
- data/spec/rubyspec/core/array/shared/keep_if.rb +3 -0
- data/spec/rubyspec/core/array/shared/length.rb +3 -0
- data/spec/rubyspec/core/array/shared/replace.rb +3 -0
- data/spec/rubyspec/core/array/shared/slice.rb +3 -0
- data/spec/rubyspec/core/array/shuffle_spec.rb +1 -1
- data/spec/rubyspec/core/array/size_spec.rb +1 -3
- data/spec/rubyspec/core/array/slice_spec.rb +4 -6
- data/spec/rubyspec/core/array/sort_spec.rb +2 -2
- data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
- data/spec/rubyspec/core/array/try_convert_spec.rb +7 -7
- data/spec/rubyspec/core/array/uniq_spec.rb +7 -7
- data/spec/rubyspec/core/array/zip_spec.rb +1 -1
- data/spec/rubyspec/core/enumerable/collect_spec.rb +24 -0
- data/spec/rubyspec/core/enumerable/count_spec.rb +35 -19
- data/spec/rubyspec/core/enumerable/find_spec.rb +5 -0
- data/spec/rubyspec/core/hash/each_pair_spec.rb +7 -7
- data/spec/rubyspec/core/hash/each_spec.rb +13 -7
- data/spec/rubyspec/core/module/method_defined_spec.rb +4 -4
- data/spec/rubyspec/core/module/public_method_defined_spec.rb +19 -0
- data/spec/rubyspec/core/module/remove_const_spec.rb +23 -0
- data/spec/rubyspec/core/numeric/step_spec.rb +14 -0
- data/spec/rubyspec/core/string/center_spec.rb +43 -65
- data/spec/rubyspec/core/string/lines_spec.rb +1 -1
- data/spec/rubyspec/core/string/ljust_spec.rb +25 -9
- data/spec/rubyspec/core/string/rjust_spec.rb +26 -10
- data/spec/rubyspec/core/struct/fixtures/classes.rb +26 -0
- data/spec/rubyspec/core/struct/initialize_spec.rb +11 -0
- data/spec/rubyspec/core/struct/new_spec.rb +24 -0
- data/spec/rubyspec/fixtures/constants.rb +7 -0
- data/spec/rubyspec/language/break_spec.rb +1 -1
- data/spec/rubyspec/language/case_spec.rb +30 -30
- data/spec/rubyspec/language/def_spec.rb +34 -34
- data/spec/rubyspec/language/defined_spec.rb +2 -2
- data/spec/rubyspec/language/ensure_spec.rb +2 -2
- data/spec/rubyspec/language/execution_spec.rb +2 -2
- data/spec/rubyspec/language/for_spec.rb +17 -17
- data/spec/rubyspec/language/hash_spec.rb +3 -3
- data/spec/rubyspec/language/if_spec.rb +11 -11
- data/spec/rubyspec/language/loop_spec.rb +3 -3
- data/spec/rubyspec/language/metaclass_spec.rb +14 -14
- data/spec/rubyspec/language/module_spec.rb +6 -6
- data/spec/rubyspec/language/next_spec.rb +5 -5
- data/spec/rubyspec/language/not_spec.rb +1 -1
- data/spec/rubyspec/language/or_spec.rb +1 -1
- data/spec/rubyspec/language/order_spec.rb +3 -5
- data/spec/rubyspec/language/precedence_spec.rb +19 -19
- data/spec/rubyspec/language/proc_spec.rb +29 -29
- data/spec/rubyspec/language/redo_spec.rb +3 -5
- data/spec/rubyspec/language/rescue_spec.rb +7 -7
- data/spec/rubyspec/language/retry_spec.rb +2 -2
- data/spec/rubyspec/language/return_spec.rb +12 -12
- data/spec/rubyspec/language/send_spec.rb +9 -9
- data/spec/rubyspec/language/singleton_class_spec.rb +3 -4
- data/spec/rubyspec/language/super_spec.rb +7 -11
- data/spec/rubyspec/language/until_spec.rb +10 -10
- data/spec/rubyspec/language/variables_spec.rb +59 -67
- data/spec/rubyspec/language/versions/array_1.9.rb +1 -1
- data/spec/rubyspec/language/versions/block_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/break_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/literal_lambda_1.9.rb +12 -12
- data/spec/rubyspec/language/versions/send_1.9.rb +23 -23
- data/spec/rubyspec/language/versions/symbol_1.9.rb +2 -2
- data/spec/rubyspec/language/versions/variables_1.9.rb +1 -1
- data/spec/rubyspec/language/while_spec.rb +4 -4
- data/spec/rubyspec/language/yield_spec.rb +3 -3
- data/spec/rubyspec/library/erb/util/html_escape_spec.rb +10 -0
- data/spec/rubyspec/library/singleton/clone_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/dup_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/fixtures/classes.rb +18 -0
- data/spec/rubyspec/library/singleton/instance_spec.rb +30 -0
- data/spec/spec_helper.rb +214 -0
- data/stdlib/buffer.rb +40 -0
- data/stdlib/buffer/array.rb +66 -0
- data/stdlib/buffer/view.rb +70 -0
- data/stdlib/erb.rb +11 -20
- data/stdlib/forwardable.rb +71 -0
- data/stdlib/json.rb +78 -0
- data/stdlib/ostruct.rb +69 -0
- data/stdlib/rbconfig.rb +1 -0
- data/stdlib/singleton.rb +40 -0
- data/stdlib/stringio.rb +173 -0
- data/stdlib/template.rb +44 -0
- metadata +285 -79
- data/corelib/opal/native.rb +0 -31
- data/spec/opal/class/bridge_class_spec.rb +0 -39
- data/spec/opal/native_spec.rb +0 -209
- data/spec/ospec/runner.rb +0 -223
- data/spec/rubyspec/filters/bugs/block_args.rb +0 -3
- data/spec/rubyspec/filters/bugs/case.rb +0 -8
- data/spec/rubyspec/filters/bugs/language/module.rb +0 -3
- data/spec/rubyspec/filters/unsupported/frozen.rb +0 -4
- data/spec/rubyspec/filters/unsupported/tainted.rb +0 -7
@@ -4,14 +4,14 @@ class Enumerator
|
|
4
4
|
def initialize(obj, method = :each, *args)
|
5
5
|
@object = obj
|
6
6
|
@method = method
|
7
|
-
@args
|
7
|
+
@args = args
|
8
8
|
end
|
9
9
|
|
10
10
|
def each(&block)
|
11
11
|
return enum_for :each unless block_given?
|
12
12
|
|
13
|
-
@object.__send__(@method, *@args) do
|
14
|
-
block.call
|
13
|
+
@object.__send__(@method, *@args) do |*e|
|
14
|
+
block.call(*e)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -43,6 +43,7 @@ class StandardError < Exception; end
|
|
43
43
|
class StopIteration < IndexError; end
|
44
44
|
class KeyError < IndexError; end
|
45
45
|
class RangeError < StandardError; end
|
46
|
+
class IOError < StandardError; end
|
46
47
|
|
47
48
|
class ScriptError < Exception; end
|
48
49
|
class SyntaxError < ScriptError; end
|
@@ -2,9 +2,13 @@ class Hash
|
|
2
2
|
include Enumerable
|
3
3
|
|
4
4
|
%x{
|
5
|
-
var
|
5
|
+
var $hash = Opal.hash = function() {
|
6
|
+
if (arguments.length == 1 && arguments[0]._klass == Hash) {
|
7
|
+
return arguments[0];
|
8
|
+
}
|
9
|
+
|
6
10
|
var hash = new Hash._alloc,
|
7
|
-
args =
|
11
|
+
args = $slice.call(arguments),
|
8
12
|
keys = [],
|
9
13
|
assocs = {};
|
10
14
|
|
@@ -30,7 +34,7 @@ class Hash
|
|
30
34
|
# compile time, so they are just added here by the constructor
|
31
35
|
# function
|
32
36
|
%x{
|
33
|
-
var
|
37
|
+
var $hash2 = Opal.hash2 = function(keys, map) {
|
34
38
|
var hash = new Hash._alloc;
|
35
39
|
hash.keys = keys;
|
36
40
|
hash.map = map;
|
@@ -38,23 +42,26 @@ class Hash
|
|
38
42
|
};
|
39
43
|
}
|
40
44
|
|
41
|
-
`var
|
45
|
+
`var $hasOwn = {}.hasOwnProperty`
|
42
46
|
|
43
47
|
def self.[](*objs)
|
44
|
-
|
48
|
+
`$hash.apply(null, objs)`
|
45
49
|
end
|
46
50
|
|
47
51
|
def self.allocate
|
48
|
-
|
52
|
+
%x{
|
53
|
+
var hash = new #{self}._alloc;
|
54
|
+
hash.map = {};
|
55
|
+
hash.keys = [];
|
56
|
+
return hash;
|
57
|
+
}
|
49
58
|
end
|
50
59
|
|
51
|
-
def
|
60
|
+
def initialize(defaults = undefined, &block)
|
52
61
|
%x{
|
53
|
-
var hash = __hash();
|
54
|
-
|
55
62
|
if (defaults != null) {
|
56
63
|
if (defaults.constructor == Object) {
|
57
|
-
var map =
|
64
|
+
var map = #{self}.map, keys = #{self}.keys;
|
58
65
|
|
59
66
|
for (var key in defaults) {
|
60
67
|
keys.push(key);
|
@@ -62,14 +69,14 @@ class Hash
|
|
62
69
|
}
|
63
70
|
}
|
64
71
|
else {
|
65
|
-
|
72
|
+
#{self}.none = defaults;
|
66
73
|
}
|
67
74
|
}
|
68
75
|
else if (block !== nil) {
|
69
|
-
|
76
|
+
#{self}.proc = block;
|
70
77
|
}
|
71
78
|
|
72
|
-
return
|
79
|
+
return #{self};
|
73
80
|
}
|
74
81
|
end
|
75
82
|
|
@@ -124,7 +131,7 @@ class Hash
|
|
124
131
|
%x{
|
125
132
|
var map = #{self}.map;
|
126
133
|
|
127
|
-
if (
|
134
|
+
if (!$hasOwn.call(map, key)) {
|
128
135
|
#{self}.keys.push(key);
|
129
136
|
}
|
130
137
|
|
@@ -160,7 +167,7 @@ class Hash
|
|
160
167
|
|
161
168
|
def clone
|
162
169
|
%x{
|
163
|
-
var result =
|
170
|
+
var result = $hash(),
|
164
171
|
map = #{self}.map,
|
165
172
|
map2 = result.map,
|
166
173
|
keys2 = result.keys;
|
@@ -206,14 +213,16 @@ class Hash
|
|
206
213
|
end
|
207
214
|
|
208
215
|
def delete_if(&block)
|
216
|
+
return enum_for :delete_if unless block
|
217
|
+
|
209
218
|
%x{
|
210
219
|
var map = #{self}.map, keys = #{self}.keys, value;
|
211
220
|
|
212
221
|
for (var i = 0, length = keys.length; i < length; i++) {
|
213
222
|
var key = keys[i], obj = map[key];
|
214
223
|
|
215
|
-
if ((value = block(key, obj)) ===
|
216
|
-
return
|
224
|
+
if ((value = block(key, obj)) === $breaker) {
|
225
|
+
return $breaker.$v;
|
217
226
|
}
|
218
227
|
|
219
228
|
if (value !== false && value !== nil) {
|
@@ -232,15 +241,15 @@ class Hash
|
|
232
241
|
alias dup clone
|
233
242
|
|
234
243
|
def each(&block)
|
244
|
+
return enum_for :each unless block
|
245
|
+
|
235
246
|
%x{
|
236
247
|
var map = #{self}.map, keys = #{self}.keys;
|
237
248
|
|
238
249
|
for (var i = 0, length = keys.length; i < length; i++) {
|
239
250
|
var key = keys[i];
|
240
251
|
|
241
|
-
|
242
|
-
return __breaker.$v;
|
243
|
-
}
|
252
|
+
#{yield [`key`, `map[key]`]};
|
244
253
|
}
|
245
254
|
|
246
255
|
return #{self};
|
@@ -248,14 +257,16 @@ class Hash
|
|
248
257
|
end
|
249
258
|
|
250
259
|
def each_key(&block)
|
260
|
+
return enum_for :each_key unless block
|
261
|
+
|
251
262
|
%x{
|
252
263
|
var keys = #{self}.keys;
|
253
264
|
|
254
265
|
for (var i = 0, length = keys.length; i < length; i++) {
|
255
266
|
var key = keys[i];
|
256
267
|
|
257
|
-
if (block(key) ===
|
258
|
-
return
|
268
|
+
if (block(key) === $breaker) {
|
269
|
+
return $breaker.$v;
|
259
270
|
}
|
260
271
|
}
|
261
272
|
|
@@ -266,12 +277,14 @@ class Hash
|
|
266
277
|
alias each_pair each
|
267
278
|
|
268
279
|
def each_value(&block)
|
280
|
+
return enum_for :each_value unless block
|
281
|
+
|
269
282
|
%x{
|
270
283
|
var map = #{self}.map, keys = #{self}.keys;
|
271
284
|
|
272
285
|
for (var i = 0, length = keys.length; i < length; i++) {
|
273
|
-
if (block(map[keys[i]]) ===
|
274
|
-
return
|
286
|
+
if (block(map[keys[i]]) === $breaker) {
|
287
|
+
return $breaker.$v;
|
275
288
|
}
|
276
289
|
}
|
277
290
|
|
@@ -280,9 +293,7 @@ class Hash
|
|
280
293
|
end
|
281
294
|
|
282
295
|
def empty?
|
283
|
-
|
284
|
-
return #{self}.keys.length === 0;
|
285
|
-
}
|
296
|
+
`#{self}.keys.length === 0`
|
286
297
|
end
|
287
298
|
|
288
299
|
alias eql? ==
|
@@ -298,8 +309,8 @@ class Hash
|
|
298
309
|
if (block !== nil) {
|
299
310
|
var value;
|
300
311
|
|
301
|
-
if ((value = block(key)) ===
|
302
|
-
return
|
312
|
+
if ((value = block(key)) === $breaker) {
|
313
|
+
return $breaker.$v;
|
303
314
|
}
|
304
315
|
|
305
316
|
return value;
|
@@ -403,8 +414,13 @@ class Hash
|
|
403
414
|
var inspect = [], keys = #{self}.keys, map = #{self}.map;
|
404
415
|
|
405
416
|
for (var i = 0, length = keys.length; i < length; i++) {
|
406
|
-
var key = keys[i];
|
407
|
-
|
417
|
+
var key = keys[i], val = map[key];
|
418
|
+
|
419
|
+
if (val === #{self}) {
|
420
|
+
inspect.push(#{`key`.inspect} + '=>' + '{...}');
|
421
|
+
} else {
|
422
|
+
inspect.push(#{`key`.inspect} + '=>' + #{`map[key]`.inspect});
|
423
|
+
}
|
408
424
|
}
|
409
425
|
|
410
426
|
return '{' + inspect.join(', ') + '}';
|
@@ -413,7 +429,7 @@ class Hash
|
|
413
429
|
|
414
430
|
def invert
|
415
431
|
%x{
|
416
|
-
var result =
|
432
|
+
var result = $hash(), keys = #{self}.keys, map = #{self}.map,
|
417
433
|
keys2 = result.keys, map2 = result.map;
|
418
434
|
|
419
435
|
for (var i = 0, length = keys.length; i < length; i++) {
|
@@ -428,14 +444,16 @@ class Hash
|
|
428
444
|
end
|
429
445
|
|
430
446
|
def keep_if(&block)
|
447
|
+
return enum_for :keep_if unless block
|
448
|
+
|
431
449
|
%x{
|
432
450
|
var map = #{self}.map, keys = #{self}.keys, value;
|
433
451
|
|
434
452
|
for (var i = 0, length = keys.length; i < length; i++) {
|
435
453
|
var key = keys[i], obj = map[key];
|
436
454
|
|
437
|
-
if ((value = block(key, obj)) ===
|
438
|
-
return
|
455
|
+
if ((value = block(key, obj)) === $breaker) {
|
456
|
+
return $breaker.$v;
|
439
457
|
}
|
440
458
|
|
441
459
|
if (value === false || value === nil) {
|
@@ -472,7 +490,7 @@ class Hash
|
|
472
490
|
def merge(other, &block)
|
473
491
|
%x{
|
474
492
|
var keys = #{self}.keys, map = #{self}.map,
|
475
|
-
result =
|
493
|
+
result = $hash(), keys2 = result.keys, map2 = result.map;
|
476
494
|
|
477
495
|
for (var i = 0, length = keys.length; i < length; i++) {
|
478
496
|
var key = keys[i];
|
@@ -563,15 +581,17 @@ class Hash
|
|
563
581
|
end
|
564
582
|
|
565
583
|
def reject(&block)
|
584
|
+
return enum_for :reject unless block
|
585
|
+
|
566
586
|
%x{
|
567
587
|
var keys = #{self}.keys, map = #{self}.map,
|
568
|
-
result =
|
588
|
+
result = $hash(), map2 = result.map, keys2 = result.keys;
|
569
589
|
|
570
590
|
for (var i = 0, length = keys.length; i < length; i++) {
|
571
591
|
var key = keys[i], obj = map[key], value;
|
572
592
|
|
573
|
-
if ((value = block(key, obj)) ===
|
574
|
-
return
|
593
|
+
if ((value = block(key, obj)) === $breaker) {
|
594
|
+
return $breaker.$v;
|
575
595
|
}
|
576
596
|
|
577
597
|
if (value === false || value === nil) {
|
@@ -599,15 +619,17 @@ class Hash
|
|
599
619
|
end
|
600
620
|
|
601
621
|
def select(&block)
|
622
|
+
return enum_for :select unless block
|
623
|
+
|
602
624
|
%x{
|
603
625
|
var keys = #{self}.keys, map = #{self}.map,
|
604
|
-
result =
|
626
|
+
result = $hash(), map2 = result.map, keys2 = result.keys;
|
605
627
|
|
606
628
|
for (var i = 0, length = keys.length; i < length; i++) {
|
607
629
|
var key = keys[i], obj = map[key], value;
|
608
630
|
|
609
|
-
if ((value = block(key, obj)) ===
|
610
|
-
return
|
631
|
+
if ((value = block(key, obj)) === $breaker) {
|
632
|
+
return $breaker.$v;
|
611
633
|
}
|
612
634
|
|
613
635
|
if (value !== false && value !== nil) {
|
@@ -621,14 +643,16 @@ class Hash
|
|
621
643
|
end
|
622
644
|
|
623
645
|
def select!(&block)
|
646
|
+
return enum_for :select! unless block
|
647
|
+
|
624
648
|
%x{
|
625
649
|
var map = #{self}.map, keys = #{self}.keys, value, result = nil;
|
626
650
|
|
627
651
|
for (var i = 0, length = keys.length; i < length; i++) {
|
628
652
|
var key = keys[i], obj = map[key];
|
629
653
|
|
630
|
-
if ((value = block(key, obj)) ===
|
631
|
-
return
|
654
|
+
if ((value = block(key, obj)) === $breaker) {
|
655
|
+
return $breaker.$v;
|
632
656
|
}
|
633
657
|
|
634
658
|
if (value === false || value === nil) {
|
@@ -681,19 +705,6 @@ class Hash
|
|
681
705
|
self
|
682
706
|
end
|
683
707
|
|
684
|
-
def to_json
|
685
|
-
%x{
|
686
|
-
var inspect = [], keys = #{self}.keys, map = #{self}.map;
|
687
|
-
|
688
|
-
for (var i = 0, length = keys.length; i < length; i++) {
|
689
|
-
var key = keys[i];
|
690
|
-
inspect.push(#{`key`.to_json} + ': ' + #{`map[key]`.to_json});
|
691
|
-
}
|
692
|
-
|
693
|
-
return '{' + inspect.join(', ') + '}';
|
694
|
-
}
|
695
|
-
end
|
696
|
-
|
697
708
|
def to_n
|
698
709
|
%x{
|
699
710
|
var result = {}, keys = #{self}.keys, map = #{self}.map, bucket, value;
|
data/corelib/io.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
class IO
|
2
|
+
SEEK_SET = 0
|
3
|
+
SEEK_CUR = 1
|
4
|
+
SEEK_END = 2
|
5
|
+
|
6
|
+
module Writable
|
7
|
+
def <<(string)
|
8
|
+
write(string)
|
9
|
+
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def print(*args)
|
14
|
+
write args.map { |arg| String(arg) }.join($,)
|
15
|
+
end
|
16
|
+
|
17
|
+
def puts(*args)
|
18
|
+
write args.map { |arg| String(arg) }.join($/)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module Readable
|
23
|
+
def readbyte
|
24
|
+
getbyte
|
25
|
+
end
|
26
|
+
|
27
|
+
def readchar
|
28
|
+
getc
|
29
|
+
end
|
30
|
+
|
31
|
+
def readline(sep = $/)
|
32
|
+
raise NotImplementedError
|
33
|
+
end
|
34
|
+
|
35
|
+
def readpartial(integer, outbuf = nil)
|
36
|
+
raise NotImplementedError
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -20,16 +20,12 @@ module Kernel
|
|
20
20
|
`#{self} == other`
|
21
21
|
end
|
22
22
|
|
23
|
-
def as_json
|
24
|
-
nil
|
25
|
-
end
|
26
|
-
|
27
23
|
def method(name)
|
28
24
|
%x{
|
29
25
|
var recv = #{self},
|
30
26
|
meth = recv['$' + name],
|
31
27
|
func = function() {
|
32
|
-
return meth.apply(recv,
|
28
|
+
return meth.apply(recv, $slice.call(arguments, 0));
|
33
29
|
};
|
34
30
|
|
35
31
|
if (!meth) {
|
@@ -58,19 +54,29 @@ module Kernel
|
|
58
54
|
}
|
59
55
|
end
|
60
56
|
|
61
|
-
def Array(object)
|
57
|
+
def Array(object, func = undefined, length = :length)
|
62
58
|
%x{
|
63
|
-
if (object === nil) {
|
59
|
+
if (object == null || object === nil) {
|
64
60
|
return [];
|
65
61
|
}
|
66
|
-
else if (object
|
62
|
+
else if (#{native?(object)} && object[length] != null) {
|
63
|
+
var result = [];
|
64
|
+
|
65
|
+
for (var i = 0, length = object[length]; i < length; i++) {
|
66
|
+
result.push(func ? object[func](i) : object[i]);
|
67
|
+
}
|
68
|
+
|
69
|
+
return result;
|
70
|
+
}
|
71
|
+
else if (#{object.respond_to? :to_ary}) {
|
67
72
|
return #{object.to_ary};
|
68
73
|
}
|
69
|
-
else if (object
|
74
|
+
else if (#{object.respond_to? :to_a}) {
|
70
75
|
return #{object.to_a};
|
71
76
|
}
|
72
|
-
|
73
|
-
|
77
|
+
else {
|
78
|
+
return [object];
|
79
|
+
}
|
74
80
|
}
|
75
81
|
end
|
76
82
|
|
@@ -81,7 +87,7 @@ module Kernel
|
|
81
87
|
def define_singleton_method(name, &body)
|
82
88
|
%x{
|
83
89
|
if (body === nil) {
|
84
|
-
|
90
|
+
throw new Error("no block given");
|
85
91
|
}
|
86
92
|
|
87
93
|
var jsid = '$' + name;
|
@@ -259,7 +265,7 @@ module Kernel
|
|
259
265
|
end
|
260
266
|
|
261
267
|
def instance_variable_defined?(name)
|
262
|
-
|
268
|
+
`#{self}.hasOwnProperty(name.substr(1))`
|
263
269
|
end
|
264
270
|
|
265
271
|
def instance_variable_get(name)
|
@@ -288,6 +294,10 @@ module Kernel
|
|
288
294
|
}
|
289
295
|
end
|
290
296
|
|
297
|
+
def Integer(str)
|
298
|
+
`parseInt(str)`
|
299
|
+
end
|
300
|
+
|
291
301
|
def is_a?(klass)
|
292
302
|
%x{
|
293
303
|
var search = #{self}._klass;
|
@@ -345,20 +355,12 @@ module Kernel
|
|
345
355
|
end
|
346
356
|
|
347
357
|
def puts(*strs)
|
348
|
-
|
349
|
-
for (var i = 0; i < strs.length; i++) {
|
350
|
-
if(strs[i] instanceof Array) {
|
351
|
-
#{ puts *`strs[i]` }
|
352
|
-
} else {
|
353
|
-
__opal.puts(#{ `strs[i]`.to_s });
|
354
|
-
}
|
355
|
-
}
|
356
|
-
}
|
357
|
-
nil
|
358
|
+
$stdout.puts(*strs)
|
358
359
|
end
|
359
360
|
|
360
361
|
def p(*args)
|
361
|
-
|
362
|
+
args.each { |obj| $stdout.puts obj.inspect }
|
363
|
+
|
362
364
|
args.length <= 1 ? args[0] : args
|
363
365
|
end
|
364
366
|
|
@@ -393,7 +395,10 @@ module Kernel
|
|
393
395
|
end
|
394
396
|
|
395
397
|
def respond_to?(name)
|
396
|
-
|
398
|
+
%x{
|
399
|
+
var body = #{self}['$' + name];
|
400
|
+
return (!!body) && !body.rb_stub;
|
401
|
+
}
|
397
402
|
end
|
398
403
|
|
399
404
|
alias send __send__
|
@@ -406,14 +411,16 @@ module Kernel
|
|
406
411
|
return #{self}._singleton;
|
407
412
|
}
|
408
413
|
|
409
|
-
var meta = new
|
410
|
-
meta._klass =
|
414
|
+
var meta = new $opal.Class._alloc;
|
415
|
+
meta._klass = $opal.Class;
|
411
416
|
#{self}._singleton = meta;
|
412
417
|
// FIXME - is this right? (probably - methods defined on
|
413
418
|
// class' singleton should also go to subclasses?)
|
414
419
|
meta._proto = #{self}.constructor.prototype;
|
415
420
|
meta._isSingleton = true;
|
416
421
|
|
422
|
+
meta._scope = #{self}._scope;
|
423
|
+
|
417
424
|
return meta;
|
418
425
|
}
|
419
426
|
|
@@ -436,6 +443,7 @@ module Kernel
|
|
436
443
|
meta._proto = #{self};
|
437
444
|
#{self}._singleton = meta;
|
438
445
|
meta._klass = orig_class._klass;
|
446
|
+
meta._scope = orig_class._scope;
|
439
447
|
|
440
448
|
return meta;
|
441
449
|
}
|
@@ -453,10 +461,6 @@ module Kernel
|
|
453
461
|
self
|
454
462
|
end
|
455
463
|
|
456
|
-
def to_json
|
457
|
-
to_s.to_json
|
458
|
-
end
|
459
|
-
|
460
464
|
def to_proc
|
461
465
|
self
|
462
466
|
end
|