opal 0.3.16 → 0.3.17
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +8 -7
- data/README.md +21 -13
- data/Rakefile +64 -78
- data/bin/opal +18 -29
- data/core/alpha.rb +2 -9
- data/core/array.rb +106 -50
- data/core/basic_object.rb +10 -8
- data/core/boolean.rb +2 -0
- data/core/class.rb +25 -13
- data/core/comparable.rb +6 -6
- data/core/enumerable.rb +90 -94
- data/core/enumerator.rb +3 -3
- data/core/hash.rb +86 -46
- data/core/kernel.rb +55 -39
- data/core/load_order +2 -5
- data/core/match_data.rb +1 -1
- data/core/module.rb +45 -20
- data/core/nil_class.rb +6 -2
- data/core/numeric.rb +20 -10
- data/core/proc.rb +2 -2
- data/core/range.rb +72 -13
- data/core/regexp.rb +5 -3
- data/core/runtime.js +228 -287
- data/core/string.rb +345 -37
- data/core/top_self.rb +1 -1
- data/lib/opal.rb +13 -91
- data/lib/opal/builder.rb +47 -120
- data/lib/opal/builder_task.rb +74 -0
- data/lib/opal/{parser/grammar.rb → grammar.rb} +1094 -1083
- data/lib/opal/{parser/grammar.y → grammar.y} +7 -0
- data/lib/opal/{parser/lexer.rb → lexer.rb} +32 -11
- data/lib/opal/{parser/parser.rb → parser.rb} +232 -238
- data/lib/opal/{parser/scope.rb → scope.rb} +72 -9
- data/lib/opal/version.rb +2 -3
- data/opal.gemspec +1 -2
- data/{core_spec → spec}/core/array/allocate_spec.rb +1 -3
- data/{core_spec → spec}/core/array/append_spec.rb +1 -4
- data/{core_spec → spec}/core/array/assoc_spec.rb +1 -4
- data/{core_spec → spec}/core/array/at_spec.rb +1 -3
- data/{core_spec → spec}/core/array/clear_spec.rb +1 -3
- data/spec/core/array/clone_spec.rb +15 -0
- data/{core_spec/core/array/shared/collect.rb → spec/core/array/collect_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/compact_spec.rb +1 -3
- data/{core_spec → spec}/core/array/concat_spec.rb +1 -3
- data/{core_spec → spec}/core/array/constructor_spec.rb +9 -3
- data/{core_spec → spec}/core/array/count_spec.rb +1 -3
- data/{core_spec → spec}/core/array/delete_at_spec.rb +1 -4
- data/{core_spec → spec}/core/array/delete_if_spec.rb +1 -4
- data/{core_spec → spec}/core/array/delete_spec.rb +1 -4
- data/{core_spec → spec}/core/array/each_index_spec.rb +1 -4
- data/{core_spec → spec}/core/array/each_spec.rb +1 -4
- data/{core_spec → spec}/core/array/element_reference_spec.rb +74 -4
- data/{core_spec → spec}/core/array/empty_spec.rb +1 -4
- data/{core_spec/core/array/shared/eql.rb → spec/core/array/eql_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/fetch_spec.rb +1 -4
- data/{core_spec → spec}/core/array/first_spec.rb +1 -3
- data/{core_spec → spec}/core/array/flatten_spec.rb +1 -3
- data/{core_spec → spec}/core/array/include_spec.rb +1 -3
- data/{core_spec → spec}/core/array/insert_spec.rb +1 -4
- data/{core_spec → spec}/core/array/last_spec.rb +1 -4
- data/{core_spec/core/array/shared/length.rb → spec/core/array/length_spec.rb} +1 -1
- data/spec/core/array/map_spec.rb +53 -0
- data/{core_spec → spec}/core/array/plus_spec.rb +1 -4
- data/{core_spec → spec}/core/array/pop_spec.rb +1 -4
- data/{core_spec → spec}/core/array/push_spec.rb +1 -4
- data/{core_spec → spec}/core/array/rassoc_spec.rb +1 -4
- data/{core_spec → spec}/core/array/reject_spec.rb +1 -4
- data/{core_spec/core/array/shared/replace.rb → spec/core/array/replace_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/reverse_each_spec.rb +1 -4
- data/{core_spec → spec}/core/array/reverse_spec.rb +1 -4
- data/spec/core/array/size_spec.rb +6 -0
- data/spec/core/array/to_ary_spec.rb +6 -0
- data/spec/core/array/uniq_spec.rb +22 -0
- data/spec/core/array/zip_spec.rb +20 -0
- data/{core_spec → spec}/core/class/new_spec.rb +1 -4
- data/{core_spec → spec}/core/enumerable/all_spec.rb +1 -4
- data/{core_spec → spec}/core/enumerable/any_spec.rb +1 -4
- data/{core_spec/core/enumerable/shared/collect.rb → spec/core/enumerable/collect_spec.rb} +1 -1
- data/{core_spec → spec}/core/enumerable/count_spec.rb +2 -5
- data/{core_spec → spec}/core/enumerable/fixtures/classes.rb +1 -2
- data/{core_spec → spec}/core/false/and_spec.rb +1 -3
- data/{core_spec → spec}/core/false/inspect_spec.rb +1 -3
- data/{core_spec → spec}/core/false/or_spec.rb +1 -3
- data/{core_spec → spec}/core/false/to_s_spec.rb +1 -3
- data/{core_spec → spec}/core/false/xor_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/allocate_spec.rb +1 -3
- data/spec/core/hash/assoc_spec.rb +25 -0
- data/{core_spec → spec}/core/hash/clear_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/clone_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/default_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/delete_if_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/element_reference_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/element_set_spec.rb +1 -3
- data/spec/core/hash/merge_spec.rb +37 -0
- data/{core_spec → spec}/core/hash/new_spec.rb +1 -3
- data/{core_spec → spec}/core/matchdata/to_a_spec.rb +1 -3
- data/{core_spec → spec}/core/nil/and_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/inspect_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/nil_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/or_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_a_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_f_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_i_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_s_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/xor_spec.rb +1 -4
- data/{core_spec → spec}/core/numeric/equal_value_spec.rb +1 -3
- data/{core_spec → spec}/core/regexp/match_spec.rb +10 -3
- data/{core_spec → spec}/core/symbol/to_proc_spec.rb +1 -3
- data/{core_spec → spec}/core/true/and_spec.rb +1 -3
- data/{core_spec → spec}/core/true/inspect_spec.rb +1 -3
- data/{core_spec → spec}/core/true/or_spec.rb +1 -3
- data/{core_spec → spec}/core/true/to_s_spec.rb +1 -3
- data/{core_spec → spec}/core/true/xor_spec.rb +1 -3
- data/spec/index.html +11 -0
- data/{core_spec → spec}/language/alias_spec.rb +1 -3
- data/{core_spec → spec}/language/and_spec.rb +1 -4
- data/{core_spec → spec}/language/array_spec.rb +1 -4
- data/{core_spec → spec}/language/block_spec.rb +20 -3
- data/{core_spec → spec}/language/break_spec.rb +40 -3
- data/{core_spec → spec}/language/case_spec.rb +1 -4
- data/{core_spec → spec}/language/defined_spec.rb +9 -3
- data/{core_spec → spec}/language/ensure_spec.rb +38 -3
- data/{core_spec → spec}/language/hash_spec.rb +1 -3
- data/{core_spec → spec}/language/if_spec.rb +1 -4
- data/{core_spec → spec}/language/loop_spec.rb +1 -3
- data/spec/language/metaclass_spec.rb +13 -0
- data/{core_spec → spec}/language/next_spec.rb +47 -3
- data/{core_spec → spec}/language/or_spec.rb +1 -4
- data/{core_spec → spec}/language/predefined_spec.rb +1 -3
- data/{core_spec/language/regexp/interpolation_spec.rb → spec/language/regexp_spec.rb} +6 -3
- data/{core_spec → spec}/language/send_spec.rb +38 -4
- data/spec/language/singleton_class_spec.rb +31 -0
- data/spec/language/super_spec.rb +188 -0
- data/{core_spec → spec}/language/symbol_spec.rb +1 -3
- data/{core_spec → spec}/language/undef_spec.rb +1 -3
- data/{core_spec → spec}/language/unless_spec.rb +1 -4
- data/{core_spec → spec}/language/until_spec.rb +1 -3
- data/{core_spec → spec}/language/variables_spec.rb +1 -3
- data/{core_spec → spec}/language/while_spec.rb +1 -3
- data/{spec → test}/builder/build_source_spec.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/adam.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/a.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/wow/b.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/beynon.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/charles.js +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/a.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/b.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/x.js +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/y.js +0 -0
- data/{spec → test}/grammar/alias_spec.rb +0 -0
- data/{spec → test}/grammar/and_spec.rb +0 -0
- data/{spec → test}/grammar/array_spec.rb +0 -0
- data/{spec → test}/grammar/attrasgn_spec.rb +0 -0
- data/{spec → test}/grammar/begin_spec.rb +0 -0
- data/{spec → test}/grammar/block_spec.rb +0 -0
- data/{spec → test}/grammar/break_spec.rb +0 -0
- data/{spec → test}/grammar/call_spec.rb +0 -0
- data/{spec → test}/grammar/class_spec.rb +0 -0
- data/{spec → test}/grammar/const_spec.rb +0 -0
- data/{spec → test}/grammar/cvar_spec.rb +0 -0
- data/{spec → test}/grammar/def_spec.rb +0 -0
- data/{spec → test}/grammar/false_spec.rb +0 -0
- data/{spec → test}/grammar/file_spec.rb +0 -0
- data/{spec → test}/grammar/gvar_spec.rb +0 -0
- data/{spec → test}/grammar/hash_spec.rb +0 -0
- data/{spec → test}/grammar/iasgn_spec.rb +0 -0
- data/{spec → test}/grammar/if_spec.rb +0 -0
- data/{spec → test}/grammar/iter_spec.rb +0 -0
- data/{spec → test}/grammar/ivar_spec.rb +0 -0
- data/{spec → test}/grammar/lasgn_spec.rb +0 -0
- data/{spec → test}/grammar/line_spec.rb +0 -0
- data/{spec → test}/grammar/lvar_spec.rb +0 -0
- data/{spec → test}/grammar/masgn_spec.rb +0 -0
- data/{spec → test}/grammar/module_spec.rb +0 -0
- data/{spec → test}/grammar/nil_spec.rb +0 -0
- data/{spec → test}/grammar/not_spec.rb +0 -0
- data/{spec → test}/grammar/op_asgn1_spec.rb +0 -0
- data/{spec → test}/grammar/op_asgn2_spec.rb +0 -0
- data/{spec → test}/grammar/or_spec.rb +0 -0
- data/{spec → test}/grammar/return_spec.rb +0 -0
- data/{spec → test}/grammar/sclass_spec.rb +0 -0
- data/{spec → test}/grammar/self_spec.rb +0 -0
- data/{spec → test}/grammar/str_spec.rb +0 -0
- data/{spec → test}/grammar/super_spec.rb +0 -0
- data/{spec → test}/grammar/true_spec.rb +0 -0
- data/{spec → test}/grammar/undef_spec.rb +0 -0
- data/{spec → test}/grammar/unless_spec.rb +0 -0
- data/{spec → test}/grammar/while_spec.rb +0 -0
- data/{spec → test}/grammar/xstr_spec.rb +0 -0
- data/{spec → test}/grammar/yield_spec.rb +0 -0
- data/{spec → test}/spec_helper.rb +0 -0
- metadata +330 -264
- data/core/debug.js +0 -59
- data/core/debug.rb +0 -35
- data/core/dir.rb +0 -90
- data/core/file.rb +0 -83
- data/core/gemlib.rb +0 -30
- data/core/io.rb +0 -44
- data/core_spec/README.md +0 -34
- data/core_spec/core/array/collect_spec.rb +0 -3
- data/core_spec/core/array/element_set_spec.rb +0 -7
- data/core_spec/core/array/eql_spec.rb +0 -3
- data/core_spec/core/array/equal_value_spec.rb +0 -3
- data/core_spec/core/array/fixtures/classes.rb +0 -8
- data/core_spec/core/array/length_spec.rb +0 -3
- data/core_spec/core/array/map_spec.rb +0 -3
- data/core_spec/core/array/replace_spec.rb +0 -3
- data/core_spec/core/enumerable/collect_spec.rb +0 -3
- data/core_spec/core/enumerable/detect_spec.rb +0 -3
- data/core_spec/core/enumerable/find_spec.rb +0 -3
- data/core_spec/core/enumerable/first_spec.rb +0 -3
- data/core_spec/core/enumerable/shared/entries.rb +0 -7
- data/core_spec/core/enumerable/shared/find.rb +0 -49
- data/core_spec/core/enumerable/shared/take.rb +0 -31
- data/core_spec/core/enumerable/to_a_spec.rb +0 -7
- data/core_spec/core/hash/assoc_spec.rb +0 -29
- data/core_spec/core/object/is_a_spec.rb +0 -2
- data/core_spec/core/object/shared/kind_of.rb +0 -0
- data/core_spec/core/regexp/shared/match.rb +0 -11
- data/core_spec/language/fixtures/block.rb +0 -19
- data/core_spec/language/fixtures/break.rb +0 -39
- data/core_spec/language/fixtures/defined.rb +0 -9
- data/core_spec/language/fixtures/ensure.rb +0 -37
- data/core_spec/language/fixtures/next.rb +0 -46
- data/core_spec/language/fixtures/send.rb +0 -36
- data/core_spec/language/fixtures/super.rb +0 -43
- data/core_spec/language/regexp_spec.rb +0 -7
- data/core_spec/language/string_spec.rb +0 -4
- data/core_spec/language/super_spec.rb +0 -18
- data/core_spec/language/versions/hash_1.9.rb +0 -20
- data/core_spec/opal/opal/defined_spec.rb +0 -15
- data/core_spec/opal/opal/function_spec.rb +0 -11
- data/core_spec/opal/opal/native_spec.rb +0 -16
- data/core_spec/opal/opal/null_spec.rb +0 -10
- data/core_spec/opal/opal/number_spec.rb +0 -11
- data/core_spec/opal/opal/object_spec.rb +0 -16
- data/core_spec/opal/opal/string_spec.rb +0 -11
- data/core_spec/opal/opal/typeof_spec.rb +0 -9
- data/core_spec/opal/opal/undefined_spec.rb +0 -10
- data/core_spec/opal/true/case_compare_spec.rb +0 -12
- data/core_spec/opal/true/class_spec.rb +0 -10
- data/core_spec/release_runner.html +0 -17
- data/core_spec/runner.html +0 -16
- data/core_spec/spec_helper.rb +0 -23
- data/lib/opal/context.rb +0 -269
- data/lib/opal/dependency_builder.rb +0 -133
- data/lib/opal/environment.rb +0 -87
- data/lib/opal/parser/sexp.rb +0 -17
data/core/basic_object.rb
CHANGED
@@ -8,7 +8,8 @@ class BasicObject
|
|
8
8
|
|
9
9
|
def __send__(symbol, *args, &block)
|
10
10
|
%x{
|
11
|
-
var meth = this[mid_to_jsid(symbol)] ||
|
11
|
+
var meth = this[mid_to_jsid(symbol)] || opal.mm(mid_to_jsid(symbol));
|
12
|
+
args.unshift(block);
|
12
13
|
|
13
14
|
return meth.apply(this, args);
|
14
15
|
}
|
@@ -19,20 +20,20 @@ class BasicObject
|
|
19
20
|
alias eql? ==
|
20
21
|
alias equal? ==
|
21
22
|
|
22
|
-
def instance_eval(string
|
23
|
+
def instance_eval(string, &block)
|
23
24
|
%x{
|
24
|
-
if (block
|
25
|
-
|
25
|
+
if (block == null) {
|
26
|
+
throw RubyArgError.$new('block not supplied');
|
26
27
|
}
|
27
28
|
|
28
|
-
return block.call(this, this);
|
29
|
+
return block.call(this, null, this);
|
29
30
|
}
|
30
31
|
end
|
31
32
|
|
32
33
|
def instance_exec(*args, &block)
|
33
34
|
%x{
|
34
|
-
if (block
|
35
|
-
|
35
|
+
if (block == null) {
|
36
|
+
throw RubyArgError.$new('block not supplied');
|
36
37
|
}
|
37
38
|
|
38
39
|
return block.apply(this, args);
|
@@ -40,7 +41,8 @@ class BasicObject
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def method_missing(symbol, *args)
|
43
|
-
`throw RubyNoMethodError.$new('undefined method \`' + symbol + '\` for ' + #{inspect});`
|
44
|
+
`throw RubyNoMethodError.$new(null, 'undefined method \`' + symbol + '\` for ' + #{inspect});`
|
45
|
+
|
44
46
|
self
|
45
47
|
end
|
46
48
|
|
data/core/boolean.rb
CHANGED
data/core/class.rb
CHANGED
@@ -1,14 +1,18 @@
|
|
1
1
|
class Class
|
2
2
|
def self.new(sup = Object, &block)
|
3
3
|
%x{
|
4
|
-
var klass
|
5
|
-
klass
|
4
|
+
var klass = boot_class(sup);
|
5
|
+
klass._name = "AnonClass";
|
6
6
|
|
7
|
-
make_metaclass(klass, sup
|
7
|
+
make_metaclass(klass, sup._klass);
|
8
8
|
|
9
9
|
#{sup.inherited `klass`};
|
10
10
|
|
11
|
-
|
11
|
+
if (block !== null) {
|
12
|
+
block.call(klass, null);
|
13
|
+
}
|
14
|
+
|
15
|
+
return klass;
|
12
16
|
}
|
13
17
|
end
|
14
18
|
|
@@ -17,15 +21,15 @@ class Class
|
|
17
21
|
var prototype = constructor.prototype,
|
18
22
|
klass = this;
|
19
23
|
|
20
|
-
klass
|
21
|
-
klass
|
24
|
+
klass._alloc = constructor;
|
25
|
+
klass._proto = prototype;
|
22
26
|
|
23
27
|
bridged_classes.push(klass);
|
24
28
|
|
25
|
-
prototype
|
26
|
-
prototype
|
29
|
+
prototype._klass = klass;
|
30
|
+
prototype._flags = T_OBJECT;
|
27
31
|
|
28
|
-
var donator = RubyObject
|
32
|
+
var donator = RubyObject._proto;
|
29
33
|
for (var method in donator) {
|
30
34
|
if (donator.hasOwnProperty(method)) {
|
31
35
|
if (!prototype[method]) {
|
@@ -39,7 +43,7 @@ class Class
|
|
39
43
|
end
|
40
44
|
|
41
45
|
def allocate
|
42
|
-
`new this
|
46
|
+
`new this._alloc()`
|
43
47
|
end
|
44
48
|
|
45
49
|
def new(*args, &block)
|
@@ -53,14 +57,22 @@ class Class
|
|
53
57
|
|
54
58
|
def superclass
|
55
59
|
%x{
|
56
|
-
var sup = this
|
60
|
+
var sup = this._super;
|
57
61
|
|
58
62
|
if (!sup) {
|
59
63
|
if (this === RubyObject) {
|
60
|
-
return
|
64
|
+
return null;
|
61
65
|
}
|
62
66
|
|
63
|
-
|
67
|
+
throw RubyRuntimeError.$new('uninitialized class');
|
68
|
+
}
|
69
|
+
|
70
|
+
while (sup && (sup._flags & T_ICLASS)) {
|
71
|
+
sup = sup._super;
|
72
|
+
}
|
73
|
+
|
74
|
+
if (!sup) {
|
75
|
+
return null;
|
64
76
|
}
|
65
77
|
|
66
78
|
return sup;
|
data/core/comparable.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
module Comparable
|
2
|
-
def <
|
2
|
+
def <(other)
|
3
3
|
(self <=> other) == -1
|
4
4
|
end
|
5
5
|
|
6
|
-
def <=
|
6
|
+
def <=(other)
|
7
7
|
(self <=> other) <= 0
|
8
8
|
end
|
9
9
|
|
10
|
-
def ==
|
10
|
+
def ==(other)
|
11
11
|
(self <=> other) == 0
|
12
12
|
end
|
13
13
|
|
14
|
-
def >
|
14
|
+
def >(other)
|
15
15
|
(self <=> other) == 1
|
16
16
|
end
|
17
17
|
|
18
|
-
def >=
|
18
|
+
def >=(other)
|
19
19
|
(self <=> other) >= 0
|
20
20
|
end
|
21
21
|
|
22
|
-
def between?
|
22
|
+
def between?(min, max)
|
23
23
|
self > min && self < max
|
24
24
|
end
|
25
25
|
end
|
data/core/enumerable.rb
CHANGED
@@ -1,32 +1,36 @@
|
|
1
1
|
module Enumerable
|
2
2
|
def all?(&block)
|
3
3
|
%x{
|
4
|
-
var result = true;
|
4
|
+
var result = true, proc;
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
if (block) {
|
7
|
+
proc = function(obj) {
|
8
|
+
var value;
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
if ((value = block.call(__context, obj)) === __breaker) {
|
11
|
+
return __breaker.$v;
|
12
|
+
}
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
if (value === false || value === nil) {
|
15
|
+
result = false;
|
16
|
+
__breaker.$v = nil;
|
17
17
|
|
18
|
-
|
19
|
-
}
|
18
|
+
return __breaker;
|
20
19
|
}
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
}
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
proc = function(obj) {
|
24
|
+
if (obj === false || obj === nil) {
|
25
|
+
result = false;
|
26
|
+
__breaker.$v = nil;
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
return __breaker;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
29
32
|
|
33
|
+
this.$each._p = proc;
|
30
34
|
this.$each();
|
31
35
|
|
32
36
|
return result;
|
@@ -35,32 +39,36 @@ module Enumerable
|
|
35
39
|
|
36
40
|
def any?(&block)
|
37
41
|
%x{
|
38
|
-
var result = false;
|
42
|
+
var result = false, proc;
|
39
43
|
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
if (block) {
|
45
|
+
proc = function(obj) {
|
46
|
+
var value;
|
43
47
|
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
if ((value = block.call(__context, obj)) === __breaker) {
|
49
|
+
return __breaker.$v;
|
50
|
+
}
|
47
51
|
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
if (value !== false && value !== nil) {
|
53
|
+
result = true;
|
54
|
+
__breaker.$v = nil;
|
51
55
|
|
52
|
-
|
53
|
-
}
|
56
|
+
return __breaker;
|
54
57
|
}
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
58
|
+
}
|
59
|
+
}
|
60
|
+
else {
|
61
|
+
proc = function(obj) {
|
62
|
+
if (obj !== false && obj !== nil) {
|
63
|
+
result = true;
|
64
|
+
__breaker.$v = nil;
|
59
65
|
|
60
|
-
|
61
|
-
|
62
|
-
|
66
|
+
return __breaker;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
63
70
|
|
71
|
+
this.$each._p = proc;
|
64
72
|
this.$each();
|
65
73
|
|
66
74
|
return result;
|
@@ -73,17 +81,17 @@ module Enumerable
|
|
73
81
|
%x{
|
74
82
|
var result = [];
|
75
83
|
|
76
|
-
|
77
|
-
var obj =
|
78
|
-
value;
|
84
|
+
var proc = function() {
|
85
|
+
var obj = __slice.call(arguments), value;
|
79
86
|
|
80
|
-
if ((value =
|
81
|
-
return
|
87
|
+
if ((value = block.apply(__context, obj)) === __breaker) {
|
88
|
+
return __breaker.$v;
|
82
89
|
}
|
83
90
|
|
84
91
|
result.push(value);
|
85
92
|
};
|
86
93
|
|
94
|
+
this.$each._p = proc;
|
87
95
|
this.$each();
|
88
96
|
|
89
97
|
return result;
|
@@ -94,27 +102,28 @@ module Enumerable
|
|
94
102
|
%x{
|
95
103
|
var result = 0;
|
96
104
|
|
97
|
-
if (block
|
98
|
-
if (object
|
99
|
-
|
105
|
+
if (!block) {
|
106
|
+
if (object == null) {
|
107
|
+
block = function() { return true; };
|
100
108
|
}
|
101
109
|
else {
|
102
|
-
|
110
|
+
block = function(obj) { return #{`obj` == `object`}; };
|
103
111
|
}
|
104
112
|
}
|
105
113
|
|
106
|
-
|
114
|
+
var proc = function(obj) {
|
107
115
|
var value;
|
108
116
|
|
109
|
-
if ((value =
|
110
|
-
return
|
117
|
+
if ((value = block.call(__context, obj)) === __breaker) {
|
118
|
+
return __breaker.$v;
|
111
119
|
}
|
112
120
|
|
113
121
|
if (value !== false && value !== nil) {
|
114
122
|
result++;
|
115
123
|
}
|
116
|
-
}
|
124
|
+
}
|
117
125
|
|
126
|
+
this.$each._p = proc;
|
118
127
|
this.$each();
|
119
128
|
|
120
129
|
return result;
|
@@ -127,10 +136,10 @@ module Enumerable
|
|
127
136
|
%x{
|
128
137
|
var result = nil;
|
129
138
|
|
130
|
-
this.$each
|
139
|
+
this.$each(function(y, obj) {
|
131
140
|
var value;
|
132
141
|
|
133
|
-
if ((value = $yield.call($context, obj)) === $breaker) {
|
142
|
+
if ((value = $yield.call($context, null, obj)) === $breaker) {
|
134
143
|
return $breaker.$v;
|
135
144
|
}
|
136
145
|
|
@@ -140,9 +149,7 @@ module Enumerable
|
|
140
149
|
|
141
150
|
return $breaker;
|
142
151
|
}
|
143
|
-
};
|
144
|
-
|
145
|
-
this.$each();
|
152
|
+
});
|
146
153
|
|
147
154
|
if (result !== nil) {
|
148
155
|
return result;
|
@@ -163,15 +170,13 @@ module Enumerable
|
|
163
170
|
var result = [],
|
164
171
|
current = 0;
|
165
172
|
|
166
|
-
this.$each
|
173
|
+
this.$each(function(y, obj) {
|
167
174
|
if (number < current) {
|
168
175
|
result.push(e);
|
169
176
|
}
|
170
177
|
|
171
178
|
current++;
|
172
|
-
};
|
173
|
-
|
174
|
-
this.$each();
|
179
|
+
});
|
175
180
|
|
176
181
|
return result;
|
177
182
|
}
|
@@ -183,10 +188,10 @@ module Enumerable
|
|
183
188
|
%x{
|
184
189
|
var result = [];
|
185
190
|
|
186
|
-
this.$each.$P = function(obj) {
|
191
|
+
this.$each.$P = function(y, obj) {
|
187
192
|
var value;
|
188
193
|
|
189
|
-
if ((value = $yield.call($context, obj)) === $breaker) {
|
194
|
+
if ((value = $yield.call($context, null, obj)) === $breaker) {
|
190
195
|
return $breaker.$v;
|
191
196
|
}
|
192
197
|
|
@@ -210,31 +215,28 @@ module Enumerable
|
|
210
215
|
%x{
|
211
216
|
var index = 0;
|
212
217
|
|
213
|
-
this.$each
|
218
|
+
this.$each(function(y, obj) {
|
214
219
|
var value;
|
215
220
|
|
216
|
-
if ((value = $yield.call($context, obj, index)) === $breaker) {
|
221
|
+
if ((value = $yield.call($context, null, obj, index)) === $breaker) {
|
217
222
|
return $breaker.$v;
|
218
223
|
}
|
219
224
|
|
220
225
|
index++;
|
221
|
-
};
|
222
|
-
|
223
|
-
this.$each();
|
226
|
+
});
|
224
227
|
|
225
228
|
return nil;
|
226
229
|
}
|
227
230
|
end
|
228
231
|
|
229
232
|
def entries
|
230
|
-
|
231
|
-
var result = [];
|
232
|
-
|
233
|
-
this.$each.$P = function(obj) { return result.push(obj); };
|
234
|
-
this.$each();
|
233
|
+
result = []
|
235
234
|
|
236
|
-
|
235
|
+
each {|*args|
|
236
|
+
result.push args.length == 1 ? args.first : args
|
237
237
|
}
|
238
|
+
|
239
|
+
result
|
238
240
|
end
|
239
241
|
|
240
242
|
alias find detect
|
@@ -244,15 +246,15 @@ module Enumerable
|
|
244
246
|
|
245
247
|
%x{
|
246
248
|
if (object !== undefined) {
|
247
|
-
$yield = function (
|
249
|
+
$yield = function (y, obj) { return obj.$eq$(null, object); };
|
248
250
|
}
|
249
251
|
|
250
252
|
var result = nil;
|
251
253
|
|
252
|
-
this.$each_with_index
|
254
|
+
this.$each_with_index(function(y, obj, index) {
|
253
255
|
var value;
|
254
256
|
|
255
|
-
if ((value = $yield.call($context, obj)) === $breaker) {
|
257
|
+
if ((value = $yield.call($context, null, obj)) === $breaker) {
|
256
258
|
return $breaker.$v;
|
257
259
|
}
|
258
260
|
|
@@ -262,9 +264,7 @@ module Enumerable
|
|
262
264
|
|
263
265
|
return $breaker;
|
264
266
|
}
|
265
|
-
};
|
266
|
-
|
267
|
-
this.$each_with_index();
|
267
|
+
});
|
268
268
|
|
269
269
|
return result;
|
270
270
|
}
|
@@ -275,11 +275,11 @@ module Enumerable
|
|
275
275
|
var result = [],
|
276
276
|
current = 0;
|
277
277
|
|
278
|
-
this.$each
|
279
|
-
? function(obj) {
|
278
|
+
this.$each(number === undefined
|
279
|
+
? function(y, obj) {
|
280
280
|
result = obj; return $breaker;
|
281
281
|
}
|
282
|
-
: function(obj) {
|
282
|
+
: function(y, obj) {
|
283
283
|
if (number <= current) {
|
284
284
|
return $breaker;
|
285
285
|
}
|
@@ -287,9 +287,7 @@ module Enumerable
|
|
287
287
|
result.push(obj);
|
288
288
|
|
289
289
|
current++;
|
290
|
-
};
|
291
|
-
|
292
|
-
this.$each();
|
290
|
+
});
|
293
291
|
|
294
292
|
return result;
|
295
293
|
}
|
@@ -299,27 +297,25 @@ module Enumerable
|
|
299
297
|
%x{
|
300
298
|
var result = [];
|
301
299
|
|
302
|
-
this.$each
|
303
|
-
? function(obj) {
|
304
|
-
var value = pattern.$eqq$(obj);
|
300
|
+
this.$each(block !== nil
|
301
|
+
? function(y, obj) {
|
302
|
+
var value = pattern.$eqq$(null, obj);
|
305
303
|
|
306
304
|
if (value !== false && value !== nil) {
|
307
|
-
if ((value = $yield.call($context, obj)) === $breaker) {
|
305
|
+
if ((value = $yield.call($context, null, obj)) === $breaker) {
|
308
306
|
return $breaker.$v;
|
309
307
|
}
|
310
308
|
|
311
309
|
result.push(obj);
|
312
310
|
}
|
313
311
|
}
|
314
|
-
: function(obj) {
|
315
|
-
var value = pattern.$eqq$(obj);
|
312
|
+
: function(y, obj) {
|
313
|
+
var value = pattern.$eqq$(null, obj);
|
316
314
|
|
317
315
|
if (value !== false && value !== nil) {
|
318
316
|
ary.push(obj);
|
319
317
|
}
|
320
|
-
};
|
321
|
-
|
322
|
-
this.$each();
|
318
|
+
});
|
323
319
|
|
324
320
|
return result;
|
325
321
|
}
|