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
data/corelib/class.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
class Class
|
2
|
+
def self.new(sup = Object, &block)
|
3
|
+
%x{
|
4
|
+
function AnonClass(){};
|
5
|
+
var klass = Opal.boot(sup, AnonClass)
|
6
|
+
klass._name = nil;
|
7
|
+
klass._scope = sup._scope;
|
8
|
+
|
9
|
+
sup.$inherited(klass);
|
10
|
+
|
11
|
+
if (block !== nil) {
|
12
|
+
var block_self = block._s;
|
13
|
+
block._s = null;
|
14
|
+
block.call(klass);
|
15
|
+
block._s = block_self;
|
16
|
+
}
|
17
|
+
|
18
|
+
return klass;
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def allocate
|
23
|
+
%x{
|
24
|
+
var obj = new #{self}._alloc;
|
25
|
+
obj._id = Opal.uid();
|
26
|
+
return obj;
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def inherited(cls)
|
31
|
+
end
|
32
|
+
|
33
|
+
def new(*args, &block)
|
34
|
+
%x{
|
35
|
+
var obj = #{allocate};
|
36
|
+
obj._id = Opal.uid();
|
37
|
+
|
38
|
+
obj.$initialize._p = block;
|
39
|
+
obj.$initialize.apply(obj, args);
|
40
|
+
return obj;
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def superclass
|
45
|
+
`#{self}._super || nil`
|
46
|
+
end
|
47
|
+
end
|
File without changes
|
@@ -6,30 +6,27 @@ module Enumerable
|
|
6
6
|
if (block !== nil) {
|
7
7
|
proc = function(obj) {
|
8
8
|
var value;
|
9
|
-
var args =
|
10
|
-
for(var i = 0; i < arguments.length; i ++) {
|
11
|
-
args[i] = arguments[i];
|
12
|
-
}
|
9
|
+
var args = $slice.call(arguments);
|
13
10
|
|
14
|
-
if ((value = block.apply(#{self}, args)) ===
|
15
|
-
return
|
11
|
+
if ((value = block.apply(#{self}, args)) === $breaker) {
|
12
|
+
return $breaker.$v;
|
16
13
|
}
|
17
14
|
|
18
15
|
if (value === false || value === nil) {
|
19
16
|
result = false;
|
20
|
-
|
17
|
+
$breaker.$v = nil;
|
21
18
|
|
22
|
-
return
|
19
|
+
return $breaker;
|
23
20
|
}
|
24
21
|
}
|
25
22
|
}
|
26
23
|
else {
|
27
24
|
proc = function(obj) {
|
28
25
|
if ((obj === false || obj === nil) && arguments.length < 2) {
|
29
|
-
result
|
30
|
-
|
26
|
+
result = false;
|
27
|
+
$breaker.$v = nil;
|
31
28
|
|
32
|
-
return
|
29
|
+
return $breaker;
|
33
30
|
}
|
34
31
|
}
|
35
32
|
}
|
@@ -48,20 +45,17 @@ module Enumerable
|
|
48
45
|
if (block !== nil) {
|
49
46
|
proc = function(obj) {
|
50
47
|
var value;
|
51
|
-
var args =
|
52
|
-
for(var i = 0; i < arguments.length; i ++) {
|
53
|
-
args[i] = arguments[i];
|
54
|
-
}
|
48
|
+
var args = $slice.call(arguments);
|
55
49
|
|
56
|
-
if ((value = block.apply(#{self}, args)) ===
|
57
|
-
return
|
50
|
+
if ((value = block.apply(#{self}, args)) === $breaker) {
|
51
|
+
return $breaker.$v;
|
58
52
|
}
|
59
53
|
|
60
54
|
if (value !== false && value !== nil) {
|
61
55
|
result = true;
|
62
|
-
|
56
|
+
$breaker.$v = nil;
|
63
57
|
|
64
|
-
return
|
58
|
+
return $breaker;
|
65
59
|
}
|
66
60
|
}
|
67
61
|
}
|
@@ -69,9 +63,9 @@ module Enumerable
|
|
69
63
|
proc = function(obj) {
|
70
64
|
if ((obj !== false && obj !== nil) || arguments.length >= 2) {
|
71
65
|
result = true;
|
72
|
-
|
66
|
+
$breaker.$v = nil;
|
73
67
|
|
74
|
-
return
|
68
|
+
return $breaker;
|
75
69
|
}
|
76
70
|
}
|
77
71
|
}
|
@@ -84,14 +78,16 @@ module Enumerable
|
|
84
78
|
end
|
85
79
|
|
86
80
|
def collect(&block)
|
81
|
+
return enum_for :collect unless block_given?
|
82
|
+
|
87
83
|
%x{
|
88
84
|
var result = [];
|
89
85
|
|
90
86
|
var proc = function() {
|
91
|
-
var
|
87
|
+
var value, args = $slice.call(arguments);
|
92
88
|
|
93
|
-
if ((value = block.apply(
|
94
|
-
return
|
89
|
+
if ((value = block.apply(null, arguments)) === $breaker) {
|
90
|
+
return $breaker.$v;
|
95
91
|
}
|
96
92
|
|
97
93
|
result.push(value);
|
@@ -109,13 +105,13 @@ module Enumerable
|
|
109
105
|
var result = #{object} == undefined ? 0 : #{object};
|
110
106
|
|
111
107
|
var proc = function() {
|
112
|
-
var obj =
|
108
|
+
var obj = $slice.call(arguments), value;
|
113
109
|
|
114
|
-
if ((value = block.apply(nil, [result].concat(obj))) ===
|
115
|
-
result =
|
116
|
-
|
110
|
+
if ((value = block.apply(nil, [result].concat(obj))) === $breaker) {
|
111
|
+
result = $breaker.$v;
|
112
|
+
$breaker.$v = nil;
|
117
113
|
|
118
|
-
return
|
114
|
+
return $breaker;
|
119
115
|
}
|
120
116
|
|
121
117
|
result = value;
|
@@ -133,17 +129,22 @@ module Enumerable
|
|
133
129
|
var result = 0;
|
134
130
|
|
135
131
|
if (object != null) {
|
136
|
-
block = function(
|
132
|
+
block = function() {
|
133
|
+
var param = arguments.length == 1 ?
|
134
|
+
arguments[0] : $slice.call(arguments);
|
135
|
+
|
136
|
+
return #{ `param` == `object` };
|
137
|
+
};
|
137
138
|
}
|
138
139
|
else if (block === nil) {
|
139
140
|
block = function() { return true; };
|
140
141
|
}
|
141
142
|
|
142
|
-
var proc = function(
|
143
|
-
var value;
|
143
|
+
var proc = function() {
|
144
|
+
var value, param = $slice.call(arguments);
|
144
145
|
|
145
|
-
if ((value = block(
|
146
|
-
return
|
146
|
+
if ((value = block.apply(null, param)) === $breaker) {
|
147
|
+
return $breaker.$v;
|
147
148
|
}
|
148
149
|
|
149
150
|
if (value !== false && value !== nil) {
|
@@ -162,18 +163,20 @@ module Enumerable
|
|
162
163
|
%x{
|
163
164
|
var result = nil;
|
164
165
|
|
165
|
-
#{self}.$each._p = function(
|
166
|
+
#{self}.$each._p = function() {
|
166
167
|
var value;
|
168
|
+
var param = arguments.length == 1 ?
|
169
|
+
arguments[0] : $slice.call(arguments);
|
167
170
|
|
168
|
-
if ((value = block(
|
169
|
-
return
|
171
|
+
if ((value = block(param)) === $breaker) {
|
172
|
+
return $breaker.$v;
|
170
173
|
}
|
171
174
|
|
172
175
|
if (value !== false && value !== nil) {
|
173
|
-
result
|
174
|
-
|
176
|
+
result = param;
|
177
|
+
$breaker.$v = nil;
|
175
178
|
|
176
|
-
return
|
179
|
+
return $breaker;
|
177
180
|
}
|
178
181
|
};
|
179
182
|
|
@@ -184,7 +187,7 @@ module Enumerable
|
|
184
187
|
}
|
185
188
|
|
186
189
|
if (typeof(ifnone) === 'function') {
|
187
|
-
return #{
|
190
|
+
return #{ifnone.call};
|
188
191
|
}
|
189
192
|
|
190
193
|
return ifnone == null ? nil : ifnone;
|
@@ -196,7 +199,7 @@ module Enumerable
|
|
196
199
|
var result = [],
|
197
200
|
current = 0;
|
198
201
|
|
199
|
-
#{self}.$each._p = function(
|
202
|
+
#{self}.$each._p = function() {
|
200
203
|
if (number < current) {
|
201
204
|
result.push(e);
|
202
205
|
}
|
@@ -214,19 +217,21 @@ module Enumerable
|
|
214
217
|
%x{
|
215
218
|
var result = [];
|
216
219
|
|
217
|
-
#{self}.$each._p = function(
|
220
|
+
#{self}.$each._p = function() {
|
218
221
|
var value;
|
222
|
+
var param = arguments.length == 1 ?
|
223
|
+
arguments[0] : $slice.call(arguments);
|
219
224
|
|
220
|
-
if ((value = block(
|
221
|
-
return
|
225
|
+
if ((value = block(param)) === $breaker) {
|
226
|
+
return $breaker;
|
222
227
|
}
|
223
228
|
|
224
229
|
if (value === false || value === nil) {
|
225
|
-
result.push(
|
230
|
+
result.push(param);
|
226
231
|
return value;
|
227
232
|
}
|
228
233
|
|
229
|
-
return
|
234
|
+
return $breaker;
|
230
235
|
};
|
231
236
|
|
232
237
|
#{self}.$each();
|
@@ -239,8 +244,11 @@ module Enumerable
|
|
239
244
|
%x{
|
240
245
|
var all = [];
|
241
246
|
|
242
|
-
#{self}.$each._p = function(
|
243
|
-
|
247
|
+
#{self}.$each._p = function() {
|
248
|
+
var param = arguments.length == 1 ?
|
249
|
+
arguments[0] : $slice.call(arguments);
|
250
|
+
|
251
|
+
all.push(param);
|
244
252
|
|
245
253
|
if (all.length == n) {
|
246
254
|
block(all.slice(0));
|
@@ -263,11 +271,13 @@ module Enumerable
|
|
263
271
|
%x{
|
264
272
|
var index = 0;
|
265
273
|
|
266
|
-
#{self}.$each._p = function(
|
274
|
+
#{self}.$each._p = function() {
|
267
275
|
var value;
|
276
|
+
var param = arguments.length == 1 ?
|
277
|
+
arguments[0] : $slice.call(arguments);
|
268
278
|
|
269
|
-
if ((value = block(
|
270
|
-
return
|
279
|
+
if ((value = block(param, index)) === $breaker) {
|
280
|
+
return $breaker.$v;
|
271
281
|
}
|
272
282
|
|
273
283
|
index++;
|
@@ -280,11 +290,13 @@ module Enumerable
|
|
280
290
|
|
281
291
|
def each_with_object(object, &block)
|
282
292
|
%x{
|
283
|
-
#{self}.$each._p = function(
|
293
|
+
#{self}.$each._p = function() {
|
284
294
|
var value;
|
295
|
+
var param = arguments.length == 1 ?
|
296
|
+
arguments[0] : $slice.call(arguments);
|
285
297
|
|
286
|
-
if ((value = block(
|
287
|
-
return
|
298
|
+
if ((value = block(param, object)) === $breaker) {
|
299
|
+
return $breaker.$v;
|
288
300
|
}
|
289
301
|
};
|
290
302
|
|
@@ -298,8 +310,13 @@ module Enumerable
|
|
298
310
|
%x{
|
299
311
|
var result = [];
|
300
312
|
|
301
|
-
#{self}.$each._p = function(
|
302
|
-
|
313
|
+
#{self}.$each._p = function() {
|
314
|
+
if (arguments.length == 1) {
|
315
|
+
result.push(arguments[0]);
|
316
|
+
}
|
317
|
+
else {
|
318
|
+
result.push($slice.call(arguments));
|
319
|
+
}
|
303
320
|
};
|
304
321
|
|
305
322
|
#{self}.$each();
|
@@ -314,15 +331,17 @@ module Enumerable
|
|
314
331
|
%x{
|
315
332
|
var result = [];
|
316
333
|
|
317
|
-
#{self}.$each._p = function(
|
334
|
+
#{self}.$each._p = function() {
|
318
335
|
var value;
|
336
|
+
var param = arguments.length == 1 ?
|
337
|
+
arguments[0] : $slice.call(arguments);
|
319
338
|
|
320
|
-
if ((value = block(
|
321
|
-
return
|
339
|
+
if ((value = block(param)) === $breaker) {
|
340
|
+
return $breaker.$v;
|
322
341
|
}
|
323
342
|
|
324
343
|
if (value !== false && value !== nil) {
|
325
|
-
result.push(
|
344
|
+
result.push(param);
|
326
345
|
}
|
327
346
|
};
|
328
347
|
|
@@ -337,28 +356,35 @@ module Enumerable
|
|
337
356
|
var proc, result = nil, index = 0;
|
338
357
|
|
339
358
|
if (object != null) {
|
340
|
-
proc = function
|
341
|
-
|
359
|
+
proc = function() {
|
360
|
+
var param = arguments.length == 1 ?
|
361
|
+
arguments[0] : $slice.call(arguments);
|
362
|
+
|
363
|
+
if (#{ `param` == `object` }) {
|
342
364
|
result = index;
|
343
|
-
return
|
365
|
+
return $breaker;
|
344
366
|
}
|
367
|
+
|
345
368
|
index += 1;
|
346
369
|
};
|
347
370
|
}
|
348
371
|
else {
|
349
|
-
proc = function(
|
372
|
+
proc = function() {
|
350
373
|
var value;
|
374
|
+
var param = arguments.length == 1 ?
|
375
|
+
arguments[0] : $slice.call(arguments);
|
351
376
|
|
352
|
-
if ((value = block(
|
353
|
-
return
|
377
|
+
if ((value = block(param)) === $breaker) {
|
378
|
+
return $breaker.$v;
|
354
379
|
}
|
355
380
|
|
356
381
|
if (value !== false && value !== nil) {
|
357
|
-
result
|
358
|
-
|
382
|
+
result = index;
|
383
|
+
$breaker.$v = index;
|
359
384
|
|
360
|
-
return
|
385
|
+
return $breaker;
|
361
386
|
}
|
387
|
+
|
362
388
|
index += 1;
|
363
389
|
};
|
364
390
|
}
|
@@ -372,25 +398,32 @@ module Enumerable
|
|
372
398
|
|
373
399
|
def first(number = undefined)
|
374
400
|
%x{
|
375
|
-
var result
|
401
|
+
var result = [],
|
376
402
|
current = 0,
|
377
403
|
proc;
|
378
404
|
|
379
405
|
if (number == null) {
|
380
406
|
result = nil;
|
381
|
-
proc
|
382
|
-
|
383
|
-
|
384
|
-
} else {
|
385
|
-
proc = function(obj) {
|
386
|
-
if (number <= current) {
|
387
|
-
return __breaker;
|
388
|
-
}
|
407
|
+
proc = function() {
|
408
|
+
result = arguments.length == 1 ?
|
409
|
+
arguments[0] : $slice.call(arguments);
|
389
410
|
|
390
|
-
|
411
|
+
return $breaker;
|
412
|
+
};
|
413
|
+
}
|
414
|
+
else {
|
415
|
+
proc = function() {
|
416
|
+
if (number <= current) {
|
417
|
+
return $breaker;
|
418
|
+
}
|
419
|
+
|
420
|
+
var param = arguments.length == 1 ?
|
421
|
+
arguments[0] : $slice.call(arguments);
|
391
422
|
|
392
|
-
|
393
|
-
|
423
|
+
result.push(param);
|
424
|
+
|
425
|
+
current++;
|
426
|
+
};
|
394
427
|
}
|
395
428
|
|
396
429
|
#{self}.$each._p = proc;
|
@@ -402,28 +435,39 @@ module Enumerable
|
|
402
435
|
|
403
436
|
def grep(pattern, &block)
|
404
437
|
%x{
|
405
|
-
var result = []
|
438
|
+
var result = [],
|
439
|
+
proc;
|
406
440
|
|
407
|
-
|
408
|
-
|
409
|
-
|
441
|
+
if (block !== nil) {
|
442
|
+
proc = function() {
|
443
|
+
var param = arguments.length == 1 ?
|
444
|
+
arguments[0] : $slice.call(arguments);
|
410
445
|
|
411
|
-
|
412
|
-
if ((value = block(obj)) === __breaker) {
|
413
|
-
return __breaker.$v;
|
414
|
-
}
|
446
|
+
var value = #{pattern === `param`};
|
415
447
|
|
416
|
-
|
448
|
+
if (value !== false && value !== nil) {
|
449
|
+
if ((value = block(param)) === $breaker) {
|
450
|
+
return $breaker.$v;
|
417
451
|
}
|
452
|
+
|
453
|
+
result.push(value);
|
418
454
|
}
|
419
|
-
|
420
|
-
|
455
|
+
};
|
456
|
+
}
|
457
|
+
else {
|
458
|
+
proc = function() {
|
459
|
+
var param = arguments.length == 1 ?
|
460
|
+
arguments[0] : $slice.call(arguments);
|
421
461
|
|
422
|
-
|
423
|
-
result.push(obj);
|
424
|
-
}
|
425
|
-
});
|
462
|
+
var value = #{pattern === `param`};
|
426
463
|
|
464
|
+
if (value !== false && value !== nil) {
|
465
|
+
result.push(param);
|
466
|
+
}
|
467
|
+
};
|
468
|
+
}
|
469
|
+
|
470
|
+
#{self}.$each._p = proc;
|
427
471
|
#{self}.$each();
|
428
472
|
|
429
473
|
return result;
|
@@ -446,32 +490,44 @@ module Enumerable
|
|
446
490
|
%x{
|
447
491
|
var proc, result;
|
448
492
|
var arg_error = false;
|
493
|
+
|
449
494
|
if (block !== nil) {
|
450
|
-
proc = function(
|
495
|
+
proc = function() {
|
496
|
+
var param = arguments.length == 1 ?
|
497
|
+
arguments[0] : $slice.call(arguments);
|
498
|
+
|
451
499
|
if (result == undefined) {
|
452
|
-
result =
|
500
|
+
result = param;
|
453
501
|
}
|
454
|
-
else if ((value = block(
|
455
|
-
result =
|
456
|
-
|
502
|
+
else if ((value = block(param, result)) === $breaker) {
|
503
|
+
result = $breaker.$v;
|
504
|
+
|
505
|
+
return $breaker;
|
457
506
|
}
|
458
507
|
else {
|
459
508
|
if (value > 0) {
|
460
|
-
result =
|
509
|
+
result = param;
|
461
510
|
}
|
462
|
-
|
511
|
+
|
512
|
+
$breaker.$v = nil;
|
463
513
|
}
|
464
514
|
}
|
465
515
|
}
|
466
516
|
else {
|
467
|
-
proc = function(
|
468
|
-
var
|
517
|
+
proc = function() {
|
518
|
+
var param = arguments.length == 1 ?
|
519
|
+
arguments[0] : $slice.call(arguments);
|
520
|
+
|
521
|
+
var modules = param.$class().$included_modules;
|
522
|
+
|
469
523
|
if (modules == undefined || modules.length == 0 || modules.indexOf(Opal.Comparable) == -1) {
|
470
524
|
arg_error = true;
|
471
|
-
|
525
|
+
|
526
|
+
return $breaker;
|
472
527
|
}
|
473
|
-
|
474
|
-
|
528
|
+
|
529
|
+
if (result == undefined || #{`param` > `result`}) {
|
530
|
+
result = param;
|
475
531
|
}
|
476
532
|
}
|
477
533
|
}
|
@@ -489,34 +545,47 @@ module Enumerable
|
|
489
545
|
|
490
546
|
def min(&block)
|
491
547
|
%x{
|
492
|
-
var proc,
|
493
|
-
|
548
|
+
var proc,
|
549
|
+
result,
|
550
|
+
arg_error = false;
|
551
|
+
|
494
552
|
if (block !== nil) {
|
495
|
-
proc = function(
|
553
|
+
proc = function() {
|
554
|
+
var param = arguments.length == 1 ?
|
555
|
+
arguments[0] : $slice.call(arguments);
|
556
|
+
|
496
557
|
if (result == undefined) {
|
497
|
-
result =
|
558
|
+
result = param;
|
498
559
|
}
|
499
|
-
else if ((value = block(
|
500
|
-
result =
|
501
|
-
|
560
|
+
else if ((value = block(param, result)) === $breaker) {
|
561
|
+
result = $breaker.$v;
|
562
|
+
|
563
|
+
return $breaker;
|
502
564
|
}
|
503
565
|
else {
|
504
566
|
if (value < 0) {
|
505
|
-
result =
|
567
|
+
result = param;
|
506
568
|
}
|
507
|
-
|
569
|
+
|
570
|
+
$breaker.$v = nil;
|
508
571
|
}
|
509
572
|
}
|
510
573
|
}
|
511
574
|
else {
|
512
575
|
proc = function(obj) {
|
513
|
-
var
|
576
|
+
var param = arguments.length == 1 ?
|
577
|
+
arguments[0] : $slice.call(arguments);
|
578
|
+
|
579
|
+
var modules = param.$class().$included_modules;
|
580
|
+
|
514
581
|
if (modules == undefined || modules.length == 0 || modules.indexOf(Opal.Comparable) == -1) {
|
515
582
|
arg_error = true;
|
516
|
-
|
583
|
+
|
584
|
+
return $breaker;
|
517
585
|
}
|
518
|
-
|
519
|
-
|
586
|
+
|
587
|
+
if (result == undefined || #{`param` < `result`}) {
|
588
|
+
result = param;
|
520
589
|
}
|
521
590
|
}
|
522
591
|
}
|
@@ -528,49 +597,47 @@ module Enumerable
|
|
528
597
|
#{raise ArgumentError, "Array#min"};
|
529
598
|
}
|
530
599
|
|
531
|
-
return
|
600
|
+
return result == undefined ? nil : result;
|
532
601
|
}
|
533
602
|
end
|
534
603
|
|
535
604
|
def none?(&block)
|
536
605
|
%x{
|
537
|
-
var result = true,
|
606
|
+
var result = true,
|
607
|
+
proc;
|
538
608
|
|
539
609
|
if (block !== nil) {
|
540
610
|
proc = function(obj) {
|
541
|
-
var value
|
542
|
-
|
543
|
-
for(var i = 0; i < arguments.length; i ++) {
|
544
|
-
args[i] = arguments[i];
|
545
|
-
}
|
611
|
+
var value,
|
612
|
+
args = $slice.call(arguments);
|
546
613
|
|
547
|
-
if ((value = block.apply(#{self}, args)) ===
|
548
|
-
return
|
614
|
+
if ((value = block.apply(#{self}, args)) === $breaker) {
|
615
|
+
return $breaker.$v;
|
549
616
|
}
|
550
617
|
|
551
618
|
if (value !== false && value !== nil) {
|
552
|
-
result
|
553
|
-
|
619
|
+
result = false;
|
620
|
+
$breaker.$v = nil;
|
554
621
|
|
555
|
-
return
|
622
|
+
return $breaker;
|
556
623
|
}
|
557
624
|
}
|
558
625
|
}
|
559
626
|
else {
|
560
627
|
proc = function(obj) {
|
561
628
|
if (arguments.length == 1 && (obj !== false && obj !== nil)) {
|
562
|
-
result
|
563
|
-
|
629
|
+
result = false;
|
630
|
+
$breaker.$v = nil;
|
564
631
|
|
565
|
-
return
|
632
|
+
return $breaker;
|
566
633
|
}
|
567
634
|
else {
|
568
635
|
for (var i = 0, length = arguments.length; i < length; i++) {
|
569
636
|
if (arguments[i] !== false && arguments[i] !== nil) {
|
570
|
-
result
|
571
|
-
|
637
|
+
result = false;
|
638
|
+
$breaker.$v = nil;
|
572
639
|
|
573
|
-
return
|
640
|
+
return $breaker;
|
574
641
|
}
|
575
642
|
}
|
576
643
|
}
|
@@ -584,7 +651,7 @@ module Enumerable
|
|
584
651
|
}
|
585
652
|
end
|
586
653
|
|
587
|
-
def sort_by
|
654
|
+
def sort_by(&block)
|
588
655
|
map { |*f|
|
589
656
|
# FIXME: this should probably belongs to somewhere more
|
590
657
|
f = `#{f}.length === 1 ? #{f}[0] : #{f}`
|