opal 0.3.11 → 0.3.15
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/Gemfile +10 -0
- data/LICENSE +20 -0
- data/README.md +11 -116
- data/Rakefile +126 -0
- data/bin/opal +1 -2
- data/docs/spec_runner.html +16 -0
- data/index.html +434 -0
- data/lib/opal.rb +14 -15
- data/lib/opal/builder.rb +46 -148
- data/lib/opal/command.rb +45 -115
- data/lib/opal/context.rb +139 -78
- data/lib/opal/dependency_builder.rb +34 -0
- data/lib/opal/environment.rb +92 -0
- data/lib/opal/parser/grammar.rb +4915 -0
- data/lib/opal/{parser.y → parser/grammar.y} +430 -284
- data/lib/opal/parser/lexer.rb +1329 -0
- data/lib/opal/parser/parser.rb +1460 -0
- data/lib/opal/parser/scope.rb +140 -0
- data/lib/opal/parser/sexp.rb +17 -0
- data/lib/opal/version.rb +2 -1
- data/opal.gemspec +23 -0
- data/opal.js +3149 -4162
- data/runtime/README.md +25 -0
- data/runtime/corelib/alpha.rb +10 -0
- data/runtime/corelib/array.rb +962 -0
- data/runtime/corelib/basic_object.rb +66 -0
- data/runtime/corelib/boolean.rb +44 -0
- data/runtime/corelib/class.rb +43 -0
- data/runtime/corelib/comparable.rb +25 -0
- data/runtime/corelib/complex.rb +2 -0
- data/runtime/corelib/dir.rb +29 -0
- data/runtime/corelib/enumerable.rb +316 -0
- data/runtime/corelib/enumerator.rb +80 -0
- data/runtime/corelib/error.rb +25 -0
- data/runtime/corelib/file.rb +80 -0
- data/runtime/corelib/hash.rb +503 -0
- data/runtime/corelib/io.rb +44 -0
- data/runtime/corelib/kernel.rb +237 -0
- data/runtime/corelib/load_order +29 -0
- data/runtime/corelib/match_data.rb +37 -0
- data/runtime/corelib/module.rb +171 -0
- data/runtime/corelib/native.rb +50 -0
- data/runtime/corelib/nil_class.rb +47 -0
- data/runtime/corelib/numeric.rb +219 -0
- data/runtime/corelib/object.rb +21 -0
- data/runtime/corelib/proc.rb +42 -0
- data/runtime/corelib/range.rb +38 -0
- data/runtime/corelib/rational.rb +16 -0
- data/runtime/corelib/regexp.rb +63 -0
- data/runtime/corelib/string.rb +185 -0
- data/runtime/corelib/struct.rb +97 -0
- data/runtime/corelib/time.rb +196 -0
- data/runtime/corelib/top_self.rb +7 -0
- data/runtime/gemlib/alpha.rb +5 -0
- data/runtime/gemlib/kernel.rb +17 -0
- data/runtime/gemlib/load_order +2 -0
- data/runtime/kernel/class.js +256 -0
- data/runtime/kernel/debug.js +42 -0
- data/runtime/kernel/init.js +114 -0
- data/runtime/kernel/load_order +5 -0
- data/runtime/kernel/loader.js +151 -0
- data/runtime/kernel/runtime.js +414 -0
- data/runtime/spec/README.md +34 -0
- data/runtime/spec/core/array/allocate_spec.rb +15 -0
- data/runtime/spec/core/array/append_spec.rb +31 -0
- data/runtime/spec/core/array/assoc_spec.rb +29 -0
- data/runtime/spec/core/array/at_spec.rb +38 -0
- data/runtime/spec/core/array/clear_spec.rb +22 -0
- data/runtime/spec/core/array/collect_spec.rb +3 -0
- data/runtime/spec/core/array/compact_spec.rb +42 -0
- data/runtime/spec/core/array/concat_spec.rb +21 -0
- data/runtime/spec/core/array/constructor_spec.rb +24 -0
- data/runtime/spec/core/array/count_spec.rb +11 -0
- data/runtime/spec/core/array/delete_at_spec.rb +31 -0
- data/runtime/spec/core/array/delete_if_spec.rb +24 -0
- data/runtime/spec/core/array/delete_spec.rb +26 -0
- data/runtime/spec/core/array/each_index_spec.rb +33 -0
- data/runtime/spec/core/array/each_spec.rb +11 -0
- data/runtime/spec/core/array/element_reference_spec.rb +136 -0
- data/runtime/spec/core/array/element_set_spec.rb +7 -0
- data/runtime/spec/core/array/empty_spec.rb +10 -0
- data/runtime/spec/core/array/eql_spec.rb +3 -0
- data/runtime/spec/core/array/equal_value_spec.rb +3 -0
- data/runtime/spec/core/array/fetch_spec.rb +26 -0
- data/runtime/spec/core/array/first_spec.rb +54 -0
- data/runtime/spec/core/array/fixtures/classes.rb +8 -0
- data/runtime/spec/core/array/flatten_spec.rb +41 -0
- data/runtime/spec/core/array/include_spec.rb +20 -0
- data/runtime/spec/core/array/insert_spec.rb +59 -0
- data/runtime/spec/core/array/last_spec.rb +57 -0
- data/runtime/spec/core/array/length_spec.rb +3 -0
- data/runtime/spec/core/array/map_spec.rb +3 -0
- data/runtime/spec/core/array/plus_spec.rb +16 -0
- data/runtime/spec/core/array/pop_spec.rb +79 -0
- data/runtime/spec/core/array/push_spec.rb +19 -0
- data/runtime/spec/core/array/rassoc_spec.rb +12 -0
- data/runtime/spec/core/array/reject_spec.rb +54 -0
- data/runtime/spec/core/array/replace_spec.rb +3 -0
- data/runtime/spec/core/array/reverse_each_spec.rb +18 -0
- data/runtime/spec/core/array/reverse_spec.rb +9 -0
- data/runtime/spec/core/array/shared/collect.rb +53 -0
- data/runtime/spec/core/array/shared/eql.rb +19 -0
- data/runtime/spec/core/array/shared/length.rb +6 -0
- data/runtime/spec/core/array/shared/replace.rb +31 -0
- data/runtime/spec/core/class/new_spec.rb +19 -0
- data/runtime/spec/core/enumerable/all_spec.rb +102 -0
- data/runtime/spec/core/enumerable/any_spec.rb +115 -0
- data/runtime/spec/core/enumerable/collect_spec.rb +3 -0
- data/runtime/spec/core/enumerable/count_spec.rb +29 -0
- data/runtime/spec/core/enumerable/detect_spec.rb +3 -0
- data/runtime/spec/core/enumerable/find_spec.rb +3 -0
- data/runtime/spec/core/enumerable/fixtures/classes.rb +26 -0
- data/runtime/spec/core/enumerable/shared/collect.rb +12 -0
- data/runtime/spec/core/enumerable/shared/entries.rb +7 -0
- data/runtime/spec/core/enumerable/shared/find.rb +49 -0
- data/runtime/spec/core/enumerable/to_a_spec.rb +7 -0
- data/runtime/spec/core/false/and_spec.rb +11 -0
- data/runtime/spec/core/false/inspect_spec.rb +7 -0
- data/runtime/spec/core/false/or_spec.rb +11 -0
- data/runtime/spec/core/false/to_s_spec.rb +7 -0
- data/runtime/spec/core/false/xor_spec.rb +11 -0
- data/runtime/spec/core/hash/allocate_spec.rb +15 -0
- data/runtime/spec/core/hash/assoc_spec.rb +29 -0
- data/runtime/spec/core/hash/clear_spec.rb +21 -0
- data/runtime/spec/core/hash/clone_spec.rb +12 -0
- data/runtime/spec/core/hash/default_spec.rb +6 -0
- data/runtime/spec/core/hash/delete_if_spec.rb +15 -0
- data/runtime/spec/core/hash/element_reference_spec.rb +16 -0
- data/runtime/spec/core/hash/element_set_spec.rb +8 -0
- data/runtime/spec/core/hash/new_spec.rb +13 -0
- data/runtime/spec/core/matchdata/to_a_spec.rb +7 -0
- data/runtime/spec/core/nil/and_spec.rb +12 -0
- data/runtime/spec/core/nil/inspect_spec.rb +8 -0
- data/runtime/spec/core/nil/nil_spec.rb +8 -0
- data/runtime/spec/core/nil/or_spec.rb +12 -0
- data/runtime/spec/core/nil/to_a_spec.rb +8 -0
- data/runtime/spec/core/nil/to_f_spec.rb +12 -0
- data/runtime/spec/core/nil/to_i_spec.rb +12 -0
- data/runtime/spec/core/nil/to_s_spec.rb +8 -0
- data/runtime/spec/core/nil/xor_spec.rb +12 -0
- data/runtime/spec/core/numeric/equal_value_spec.rb +11 -0
- data/runtime/spec/core/object/is_a_spec.rb +2 -0
- data/runtime/spec/core/object/shared/kind_of.rb +0 -0
- data/runtime/spec/core/regexp/match_spec.rb +23 -0
- data/runtime/spec/core/regexp/shared/match.rb +11 -0
- data/runtime/spec/core/symbol/to_proc_spec.rb +8 -0
- data/runtime/spec/core/true/and_spec.rb +11 -0
- data/runtime/spec/core/true/inspect_spec.rb +7 -0
- data/runtime/spec/core/true/or_spec.rb +11 -0
- data/runtime/spec/core/true/to_s_spec.rb +7 -0
- data/runtime/spec/core/true/xor_spec.rb +11 -0
- data/runtime/spec/language/alias_spec.rb +25 -0
- data/runtime/spec/language/and_spec.rb +62 -0
- data/runtime/spec/language/array_spec.rb +68 -0
- data/runtime/spec/language/block_spec.rb +105 -0
- data/runtime/spec/language/break_spec.rb +49 -0
- data/runtime/spec/language/case_spec.rb +165 -0
- data/runtime/spec/language/defined_spec.rb +80 -0
- data/runtime/spec/language/ensure_spec.rb +82 -0
- data/runtime/spec/language/fixtures/block.rb +19 -0
- data/runtime/spec/language/fixtures/break.rb +39 -0
- data/runtime/spec/language/fixtures/defined.rb +9 -0
- data/runtime/spec/language/fixtures/ensure.rb +37 -0
- data/runtime/spec/language/fixtures/next.rb +46 -0
- data/runtime/spec/language/fixtures/send.rb +36 -0
- data/runtime/spec/language/fixtures/super.rb +43 -0
- data/runtime/spec/language/hash_spec.rb +43 -0
- data/runtime/spec/language/if_spec.rb +278 -0
- data/runtime/spec/language/loop_spec.rb +32 -0
- data/runtime/spec/language/next_spec.rb +128 -0
- data/runtime/spec/language/or_spec.rb +65 -0
- data/runtime/spec/language/predefined_spec.rb +21 -0
- data/runtime/spec/language/regexp/interpolation_spec.rb +9 -0
- data/runtime/spec/language/regexp_spec.rb +7 -0
- data/runtime/spec/language/send_spec.rb +105 -0
- data/runtime/spec/language/string_spec.rb +4 -0
- data/runtime/spec/language/super_spec.rb +18 -0
- data/runtime/spec/language/symbol_spec.rb +41 -0
- data/runtime/spec/language/undef_spec.rb +16 -0
- data/runtime/spec/language/unless_spec.rb +44 -0
- data/runtime/spec/language/until_spec.rb +137 -0
- data/runtime/spec/language/variables_spec.rb +28 -0
- data/runtime/spec/language/versions/hash_1.9.rb +20 -0
- data/runtime/spec/language/while_spec.rb +175 -0
- data/runtime/spec/library/stringscanner/scan_spec.rb +36 -0
- data/runtime/spec/opal/forwardable/def_instance_delegator_spec.rb +49 -0
- data/runtime/spec/opal/opal/defined_spec.rb +15 -0
- data/runtime/spec/opal/opal/function_spec.rb +11 -0
- data/runtime/spec/opal/opal/native_spec.rb +16 -0
- data/runtime/spec/opal/opal/null_spec.rb +10 -0
- data/runtime/spec/opal/opal/number_spec.rb +11 -0
- data/runtime/spec/opal/opal/object_spec.rb +16 -0
- data/runtime/spec/opal/opal/string_spec.rb +11 -0
- data/runtime/spec/opal/opal/typeof_spec.rb +9 -0
- data/runtime/spec/opal/opal/undefined_spec.rb +10 -0
- data/runtime/spec/opal/true/case_compare_spec.rb +12 -0
- data/runtime/spec/opal/true/class_spec.rb +10 -0
- data/runtime/spec/spec_helper.rb +25 -0
- data/runtime/stdlib/base64.rb +91 -0
- data/runtime/stdlib/date.rb +4 -0
- data/{stdlib → runtime/stdlib}/dev.rb +0 -0
- data/runtime/stdlib/forwardable.rb +33 -0
- data/runtime/stdlib/optparse.rb +0 -0
- data/runtime/stdlib/pp.rb +6 -0
- data/{stdlib → runtime/stdlib}/racc/parser.rb +0 -0
- data/runtime/stdlib/rbconfig.rb +0 -0
- data/runtime/stdlib/si.rb +17 -0
- data/runtime/stdlib/strscan.rb +53 -0
- data/runtime/stdlib/uri.rb +111 -0
- data/runtime/stdlib/uri/common.rb +1014 -0
- data/runtime/stdlib/uri/ftp.rb +261 -0
- data/runtime/stdlib/uri/generic.rb +1599 -0
- data/runtime/stdlib/uri/http.rb +106 -0
- data/runtime/stdlib/uri/https.rb +22 -0
- data/runtime/stdlib/uri/ldap.rb +260 -0
- data/runtime/stdlib/uri/ldaps.rb +20 -0
- data/runtime/stdlib/uri/mailto.rb +280 -0
- data/spec/builder/build_source_spec.rb +52 -0
- data/spec/builder/fixtures/build_source/adam.rb +0 -0
- data/spec/builder/fixtures/build_source/bar/a.rb +0 -0
- data/spec/builder/fixtures/build_source/bar/wow/b.rb +0 -0
- data/spec/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
- data/spec/builder/fixtures/build_source/beynon.rb +0 -0
- data/spec/builder/fixtures/build_source/charles.js +0 -0
- data/spec/builder/fixtures/build_source/foo/a.rb +0 -0
- data/spec/builder/fixtures/build_source/foo/b.rb +0 -0
- data/spec/builder/fixtures/build_source/foo/x.js +0 -0
- data/spec/builder/fixtures/build_source/foo/y.js +0 -0
- data/spec/builder/output_path_spec.rb +50 -0
- data/spec/grammar/alias_spec.rb +26 -0
- data/spec/grammar/and_spec.rb +13 -0
- data/spec/grammar/array_spec.rb +22 -0
- data/spec/grammar/attrasgn_spec.rb +28 -0
- data/spec/grammar/begin_spec.rb +38 -0
- data/spec/grammar/block_spec.rb +12 -0
- data/spec/grammar/break_spec.rb +17 -0
- data/spec/grammar/call_spec.rb +58 -0
- data/spec/grammar/class_spec.rb +35 -0
- data/spec/grammar/const_spec.rb +13 -0
- data/spec/grammar/cvar_spec.rb +11 -0
- data/spec/grammar/def_spec.rb +60 -0
- data/spec/grammar/false_spec.rb +17 -0
- data/spec/grammar/file_spec.rb +7 -0
- data/spec/grammar/gvar_spec.rb +13 -0
- data/spec/grammar/hash_spec.rb +17 -0
- data/spec/grammar/iasgn_spec.rb +9 -0
- data/spec/grammar/if_spec.rb +26 -0
- data/spec/grammar/iter_spec.rb +59 -0
- data/spec/grammar/ivar_spec.rb +9 -0
- data/spec/grammar/lasgn_spec.rb +8 -0
- data/spec/grammar/line_spec.rb +8 -0
- data/spec/grammar/lvar_spec.rb +38 -0
- data/spec/grammar/module_spec.rb +27 -0
- data/spec/grammar/nil_spec.rb +17 -0
- data/spec/grammar/not_spec.rb +27 -0
- data/spec/grammar/op_asgn1_spec.rb +23 -0
- data/spec/grammar/op_asgn2_spec.rb +23 -0
- data/spec/grammar/or_spec.rb +13 -0
- data/spec/grammar/return_spec.rb +17 -0
- data/spec/grammar/sclass_spec.rb +20 -0
- data/spec/grammar/self_spec.rb +17 -0
- data/spec/grammar/str_spec.rb +96 -0
- data/spec/grammar/super_spec.rb +20 -0
- data/spec/grammar/true_spec.rb +17 -0
- data/spec/grammar/undef_spec.rb +15 -0
- data/spec/grammar/unless_spec.rb +13 -0
- data/spec/grammar/while_spec.rb +15 -0
- data/spec/grammar/xstr_spec.rb +116 -0
- data/spec/grammar/yield_spec.rb +20 -0
- data/spec/spec_helper.rb +9 -0
- metadata +346 -21
- data/lib/opal/bundle.rb +0 -34
- data/lib/opal/lexer.rb +0 -902
- data/lib/opal/nodes.rb +0 -2150
- data/lib/opal/parser.rb +0 -4894
- data/lib/opal/rake/bundle_task.rb +0 -63
- data/opal-parser.js +0 -8343
- data/stdlib/strscan.rb +0 -52
- data/templates/init/Rakefile +0 -7
- data/templates/init/index.html +0 -17
- data/templates/init/lib/__NAME__.rb +0 -2
@@ -0,0 +1,66 @@
|
|
1
|
+
class BasicObject
|
2
|
+
def initialize(*)
|
3
|
+
end
|
4
|
+
|
5
|
+
def ==(other)
|
6
|
+
`this === other`
|
7
|
+
end
|
8
|
+
|
9
|
+
def __send__(symbol, *args, &block)
|
10
|
+
%x{
|
11
|
+
var meth = this[mid_to_jsid(symbol)];
|
12
|
+
|
13
|
+
if (meth) {
|
14
|
+
args.unshift(null);
|
15
|
+
|
16
|
+
return meth.apply(this, args);
|
17
|
+
}
|
18
|
+
else {
|
19
|
+
throw new Error("method missing yielder for " + symbol + " in __send__");
|
20
|
+
}
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
alias send __send__
|
25
|
+
|
26
|
+
alias eql? ==
|
27
|
+
alias equal? ==
|
28
|
+
|
29
|
+
def instance_eval(string = nil, &block)
|
30
|
+
%x{
|
31
|
+
if (block === nil) {
|
32
|
+
raise(RubyArgError, 'block not supplied');
|
33
|
+
}
|
34
|
+
|
35
|
+
return block.call(this, null, this);
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def instance_exec(*args, &block)
|
40
|
+
%x{
|
41
|
+
if (block === nil) {
|
42
|
+
raise(RubyArgError, 'block not supplied');
|
43
|
+
}
|
44
|
+
|
45
|
+
args.unshift(null);
|
46
|
+
|
47
|
+
return block.apply(this, args);
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def method_missing(symbol, *args)
|
52
|
+
`raise(RubyNoMethodError, 'undefined method \`' + symbol + '\` for ' + #{inspect})`
|
53
|
+
end
|
54
|
+
|
55
|
+
def singleton_method_added(symbol)
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
|
59
|
+
def singleton_method_removed(symbol)
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def singleton_method_undefined(symbol)
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class Boolean
|
2
|
+
def &(other)
|
3
|
+
`this.valueOf() ? (other !== false && other !== nil) : false`
|
4
|
+
end
|
5
|
+
|
6
|
+
def |(other)
|
7
|
+
`this.valueOf() ? true : (other !== false && other !== nil)`
|
8
|
+
end
|
9
|
+
|
10
|
+
def ^(other)
|
11
|
+
`this.valueOf() ? (other === false || other === nil) : (other !== false && other !== nil)`
|
12
|
+
end
|
13
|
+
|
14
|
+
def ==(other)
|
15
|
+
`this.valueOf() === other.valueOf()`
|
16
|
+
end
|
17
|
+
|
18
|
+
def class
|
19
|
+
`this.valueOf() ? #{TrueClass} : #{FalseClass}`
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_native
|
23
|
+
`this.valueOf()`
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
`this.valueOf() ? 'true' : 'false'`
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class TrueClass
|
32
|
+
def self.===(obj)
|
33
|
+
`obj === true`
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class FalseClass
|
38
|
+
def self.===(obj)
|
39
|
+
`obj === false`
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
TRUE = true
|
44
|
+
FALSE = false
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Class
|
2
|
+
def self.new(sup = Object, &block)
|
3
|
+
%x{
|
4
|
+
var klass = boot_class(sup);
|
5
|
+
klass.__classid__ = "AnonClass";
|
6
|
+
|
7
|
+
make_metaclass(klass, sup.$klass);
|
8
|
+
|
9
|
+
#{sup.inherited `klass`};
|
10
|
+
|
11
|
+
return block !== nil ? block.call(klass, null) : klass;
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def allocate
|
16
|
+
`new this.$allocator()`
|
17
|
+
end
|
18
|
+
|
19
|
+
def new(*args, &block)
|
20
|
+
obj = allocate()
|
21
|
+
obj.initialize *args, &block
|
22
|
+
obj
|
23
|
+
end
|
24
|
+
|
25
|
+
def inherited(cls)
|
26
|
+
end
|
27
|
+
|
28
|
+
def superclass
|
29
|
+
%x{
|
30
|
+
var sup = this.$s;
|
31
|
+
|
32
|
+
if (!sup) {
|
33
|
+
if (this === RubyObject) {
|
34
|
+
return nil;
|
35
|
+
}
|
36
|
+
|
37
|
+
raise(RubyRuntimeError, 'uninitialized class');
|
38
|
+
}
|
39
|
+
|
40
|
+
return sup;
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Comparable
|
2
|
+
def < (other)
|
3
|
+
(self <=> other) == -1
|
4
|
+
end
|
5
|
+
|
6
|
+
def <= (other)
|
7
|
+
(self <=> other) <= 0
|
8
|
+
end
|
9
|
+
|
10
|
+
def == (other)
|
11
|
+
(self <=> other) == 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def > (other)
|
15
|
+
(self <=> other) == 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def >= (other)
|
19
|
+
(self <=> other) >= 0
|
20
|
+
end
|
21
|
+
|
22
|
+
def between? (min, max)
|
23
|
+
self > min && self < max
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Dir
|
2
|
+
def self.getwd
|
3
|
+
`FS_CWD`
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.pwd
|
7
|
+
`FS_CWD`
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.[](*globs)
|
11
|
+
%x{
|
12
|
+
var result = [], files = FACTORIES;
|
13
|
+
|
14
|
+
for (var i = 0, ii = globs.length; i < ii; i++) {
|
15
|
+
var glob = globs[i];
|
16
|
+
|
17
|
+
var re = fs_glob_to_regexp(#{ File.expand_path `glob` });
|
18
|
+
|
19
|
+
for (var file in files) {
|
20
|
+
if (re.exec(file)) {
|
21
|
+
result.push(file);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
return result;
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,316 @@
|
|
1
|
+
module Enumerable
|
2
|
+
def all?(&block)
|
3
|
+
%x{
|
4
|
+
var result = true;
|
5
|
+
|
6
|
+
if (block !== nil) {
|
7
|
+
this.m$each(function (iter, obj) {
|
8
|
+
var value;
|
9
|
+
|
10
|
+
if ((value = $yield.call($context, null, obj)) === $breaker) {
|
11
|
+
return $breaker.$v;
|
12
|
+
}
|
13
|
+
|
14
|
+
if (value === false || value === nil) {
|
15
|
+
result = false;
|
16
|
+
$breaker.$v = nil;
|
17
|
+
|
18
|
+
return $breaker;
|
19
|
+
}
|
20
|
+
});
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
this.m$each(function (iter, obj) {
|
24
|
+
if (obj === false || obj === nil) {
|
25
|
+
result = false;
|
26
|
+
$breaker.$v = nil;
|
27
|
+
|
28
|
+
return $breaker;
|
29
|
+
}
|
30
|
+
});
|
31
|
+
}
|
32
|
+
|
33
|
+
return result;
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def any?(&block)
|
38
|
+
%x{
|
39
|
+
var result = false, proc;
|
40
|
+
|
41
|
+
if (block !== nil) {
|
42
|
+
this.m$each(function (iter, obj) {
|
43
|
+
var value;
|
44
|
+
|
45
|
+
if ((value = $yield.call($context, null, obj)) === $breaker) {
|
46
|
+
return $breaker.$v;
|
47
|
+
}
|
48
|
+
|
49
|
+
if (value !== false && value !== nil) {
|
50
|
+
result = true;
|
51
|
+
$breaker.$v = nil;
|
52
|
+
|
53
|
+
return $breaker;
|
54
|
+
}
|
55
|
+
});
|
56
|
+
}
|
57
|
+
else {
|
58
|
+
this.m$each(function (iter, obj) {
|
59
|
+
if (obj !== false && obj !== nil) {
|
60
|
+
result = true;
|
61
|
+
$breaker.$v = nil;
|
62
|
+
|
63
|
+
return $breaker;
|
64
|
+
}
|
65
|
+
});
|
66
|
+
}
|
67
|
+
|
68
|
+
return result;
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def collect(&block)
|
73
|
+
return enum_for :collect unless block_given?
|
74
|
+
|
75
|
+
%x{
|
76
|
+
var result = [];
|
77
|
+
|
78
|
+
this.m$each(function () {
|
79
|
+
var obj = $slice.call(arguments, 1),
|
80
|
+
value;
|
81
|
+
|
82
|
+
if ((value = $yield.apply($context, [null].concat(obj))) === $breaker) {
|
83
|
+
return $breaker.$v;
|
84
|
+
}
|
85
|
+
|
86
|
+
result.push(value);
|
87
|
+
});
|
88
|
+
|
89
|
+
return result;
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def count(object = undefined, &block)
|
94
|
+
%x{
|
95
|
+
var result = 0;
|
96
|
+
|
97
|
+
if (block === nil) {
|
98
|
+
if (object === undefined) {
|
99
|
+
$yield = function () { return true; };
|
100
|
+
}
|
101
|
+
else {
|
102
|
+
$yield = function (iter, obj) { return #{`obj` == `object`}; };
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
this.m$each(function (iter, obj) {
|
107
|
+
var value;
|
108
|
+
|
109
|
+
if ((value = $yield.call($context, null, obj)) === $breaker) {
|
110
|
+
return $breaker.$v;
|
111
|
+
}
|
112
|
+
|
113
|
+
if (value !== false && value !== nil) {
|
114
|
+
result++;
|
115
|
+
}
|
116
|
+
});
|
117
|
+
|
118
|
+
return result;
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
def detect(ifnone = undefined, &block)
|
123
|
+
return enum_for :detect, ifnone unless block
|
124
|
+
|
125
|
+
%x{
|
126
|
+
var result = nil;
|
127
|
+
|
128
|
+
this.m$each(function(iter, obj) {
|
129
|
+
var value;
|
130
|
+
|
131
|
+
if ((value = $yield.call($context, null, obj)) === $breaker) {
|
132
|
+
return $breaker.$v;
|
133
|
+
}
|
134
|
+
|
135
|
+
if (value !== false && value !== nil) {
|
136
|
+
result = obj;
|
137
|
+
$breaker.$v = nil;
|
138
|
+
|
139
|
+
return $breaker;
|
140
|
+
}
|
141
|
+
});
|
142
|
+
|
143
|
+
if (result !== nil) {
|
144
|
+
return result;
|
145
|
+
}
|
146
|
+
|
147
|
+
if (#{Opal.function?(ifnone)}) {
|
148
|
+
return ifnone.m$call(null);
|
149
|
+
}
|
150
|
+
|
151
|
+
return ifnone === undefined ? nil : ifnone;
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
def drop(number)
|
156
|
+
raise NotImplementedError
|
157
|
+
|
158
|
+
%x{
|
159
|
+
var result = [],
|
160
|
+
current = 0;
|
161
|
+
|
162
|
+
this.m$each(function(iter, obj) {
|
163
|
+
if (number < current) {
|
164
|
+
result.push(e);
|
165
|
+
}
|
166
|
+
|
167
|
+
current++;
|
168
|
+
});
|
169
|
+
|
170
|
+
return result;
|
171
|
+
}
|
172
|
+
end
|
173
|
+
|
174
|
+
def drop_while(&block)
|
175
|
+
return enum_for :drop_while unless block
|
176
|
+
|
177
|
+
%x{
|
178
|
+
var result = [];
|
179
|
+
|
180
|
+
this.m$each(function (iter, obj) {
|
181
|
+
var value;
|
182
|
+
|
183
|
+
if ((value = $yield.call($context, null, obj)) === $breaker) {
|
184
|
+
return $breaker.$v;
|
185
|
+
}
|
186
|
+
|
187
|
+
if (value !== false && value !== nil) {
|
188
|
+
result.push(obj);
|
189
|
+
}
|
190
|
+
else {
|
191
|
+
return $breaker;
|
192
|
+
}
|
193
|
+
});
|
194
|
+
|
195
|
+
return result;
|
196
|
+
}
|
197
|
+
end
|
198
|
+
|
199
|
+
def each_with_index(&block)
|
200
|
+
return enum_for :each_with_index unless block
|
201
|
+
|
202
|
+
%x{
|
203
|
+
var index = 0;
|
204
|
+
|
205
|
+
this.m$each(function (iter, obj) {
|
206
|
+
var value;
|
207
|
+
|
208
|
+
if ((value = $yield.call($context, null, obj, index)) === $breaker) {
|
209
|
+
return $breaker.$v;
|
210
|
+
}
|
211
|
+
|
212
|
+
index++;
|
213
|
+
});
|
214
|
+
|
215
|
+
return nil;
|
216
|
+
}
|
217
|
+
end
|
218
|
+
|
219
|
+
def entries
|
220
|
+
%x{
|
221
|
+
var result = [];
|
222
|
+
|
223
|
+
this.m$each(function (iter, obj) { return result.push(obj); })
|
224
|
+
|
225
|
+
return result;
|
226
|
+
}
|
227
|
+
end
|
228
|
+
|
229
|
+
alias_method :find, :detect
|
230
|
+
|
231
|
+
def find_index(object = undefined, &block)
|
232
|
+
return enum_for :find_index, object unless block
|
233
|
+
|
234
|
+
%x{
|
235
|
+
if (object !== undefined) {
|
236
|
+
$yield = function (iter, obj) { return obj.m$eq$(object); };
|
237
|
+
}
|
238
|
+
|
239
|
+
var result = nil;
|
240
|
+
|
241
|
+
this.m$each_with_index(function(iter, obj, index) {
|
242
|
+
var value;
|
243
|
+
|
244
|
+
if ((value = $yield.call($context, null, obj)) === $breaker) {
|
245
|
+
return $breaker.$v;
|
246
|
+
}
|
247
|
+
|
248
|
+
if (value !== false && value !== nil) {
|
249
|
+
result = obj;
|
250
|
+
breaker.$v = index;
|
251
|
+
|
252
|
+
return $breaker;
|
253
|
+
}
|
254
|
+
});
|
255
|
+
|
256
|
+
return result;
|
257
|
+
}
|
258
|
+
end
|
259
|
+
|
260
|
+
def first(number = undefined)
|
261
|
+
%x{
|
262
|
+
var result = [],
|
263
|
+
current = 0;
|
264
|
+
|
265
|
+
if (number === undefined) {
|
266
|
+
this.m$each(function (iter, obj) { result = obj; return $breaker; });
|
267
|
+
}
|
268
|
+
else {
|
269
|
+
this.m$each(function (iter, obj) {
|
270
|
+
if (number < current) {
|
271
|
+
return $breaker;
|
272
|
+
}
|
273
|
+
|
274
|
+
result.push(obj);
|
275
|
+
|
276
|
+
current++;
|
277
|
+
});
|
278
|
+
}
|
279
|
+
|
280
|
+
return result;
|
281
|
+
}
|
282
|
+
end
|
283
|
+
|
284
|
+
def grep(pattern, &block)
|
285
|
+
%x{
|
286
|
+
var result = [];
|
287
|
+
|
288
|
+
if (block !== nil) {
|
289
|
+
this.m$each(function (iter, obj) {
|
290
|
+
var value = pattern.m$eqq$(obj);
|
291
|
+
|
292
|
+
if (value !== false && value !== nil) {
|
293
|
+
if ((value = $yield.call($context, null, obj)) === $breaker) {
|
294
|
+
return $breaker.$v;
|
295
|
+
}
|
296
|
+
|
297
|
+
result.push(obj);
|
298
|
+
}
|
299
|
+
});
|
300
|
+
}
|
301
|
+
else {
|
302
|
+
this.m$each(function (iter, obj) {
|
303
|
+
var value = pattern.m$eqq$(obj);
|
304
|
+
|
305
|
+
if (value !== false && value !== nil) {
|
306
|
+
ary.push(obj);
|
307
|
+
}
|
308
|
+
});
|
309
|
+
}
|
310
|
+
|
311
|
+
return result;
|
312
|
+
}
|
313
|
+
end
|
314
|
+
|
315
|
+
alias_method :to_a, :entries
|
316
|
+
end
|