opal 0.3.16 → 0.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/load_order
CHANGED
data/core/match_data.rb
CHANGED
data/core/module.rb
CHANGED
@@ -1,10 +1,22 @@
|
|
1
1
|
class Module
|
2
2
|
def ===(object)
|
3
|
-
|
3
|
+
%x{
|
4
|
+
var search = object._klass;
|
5
|
+
|
6
|
+
while (search) {
|
7
|
+
if (search === this) {
|
8
|
+
return true;
|
9
|
+
}
|
10
|
+
|
11
|
+
search = search._super;
|
12
|
+
}
|
13
|
+
|
14
|
+
return false;
|
15
|
+
}
|
4
16
|
end
|
5
17
|
|
6
18
|
def alias_method(newname, oldname)
|
7
|
-
|
19
|
+
`opal.alias(this, newname, oldname)`
|
8
20
|
|
9
21
|
self
|
10
22
|
end
|
@@ -15,11 +27,16 @@ class Module
|
|
15
27
|
result = [];
|
16
28
|
|
17
29
|
while (parent) {
|
18
|
-
if (
|
30
|
+
if (parent._flags & FL_SINGLETON) {
|
31
|
+
continue;
|
32
|
+
}
|
33
|
+
else if (parent._flags & T_ICLASS)
|
34
|
+
result.push(parent._klass);
|
35
|
+
else {
|
19
36
|
result.push(parent);
|
20
37
|
}
|
21
38
|
|
22
|
-
parent = parent
|
39
|
+
parent = parent._super;
|
23
40
|
}
|
24
41
|
|
25
42
|
return result;
|
@@ -46,8 +63,8 @@ class Module
|
|
46
63
|
|
47
64
|
module.$included_in.push(klass);
|
48
65
|
|
49
|
-
var donator = module
|
50
|
-
prototype = klass
|
66
|
+
var donator = module._alloc.prototype,
|
67
|
+
prototype = klass._proto,
|
51
68
|
methods = [];
|
52
69
|
|
53
70
|
for (var method in donator) {
|
@@ -74,12 +91,12 @@ class Module
|
|
74
91
|
define_method(klass, mid_to_jsid(name), function() {
|
75
92
|
var res = this[name];
|
76
93
|
|
77
|
-
return res == null ?
|
94
|
+
return res == null ? null : res;
|
78
95
|
});
|
79
96
|
}
|
80
97
|
|
81
98
|
if (setter) {
|
82
|
-
define_method(klass, mid_to_jsid(name + '='), function(
|
99
|
+
define_method(klass, mid_to_jsid(name + '='), function(val) {
|
83
100
|
return this[name] = val;
|
84
101
|
});
|
85
102
|
}
|
@@ -92,7 +109,7 @@ class Module
|
|
92
109
|
define_attr(this, attrs[i], true, true);
|
93
110
|
}
|
94
111
|
|
95
|
-
return
|
112
|
+
return null;
|
96
113
|
}
|
97
114
|
end
|
98
115
|
|
@@ -102,7 +119,7 @@ class Module
|
|
102
119
|
define_attr(this, attrs[i], true, false);
|
103
120
|
}
|
104
121
|
|
105
|
-
return
|
122
|
+
return null;
|
106
123
|
}
|
107
124
|
end
|
108
125
|
|
@@ -112,7 +129,7 @@ class Module
|
|
112
129
|
define_attr(this, attrs[i], false, true);
|
113
130
|
}
|
114
131
|
|
115
|
-
return
|
132
|
+
return null;
|
116
133
|
}
|
117
134
|
end
|
118
135
|
|
@@ -124,25 +141,28 @@ class Module
|
|
124
141
|
|
125
142
|
def define_method(name, &body)
|
126
143
|
%x{
|
127
|
-
if (body ===
|
128
|
-
|
144
|
+
if (body === null) {
|
145
|
+
throw RubyLocalJumpError.$new('no block given');
|
129
146
|
}
|
130
147
|
|
131
|
-
|
148
|
+
var jsid = mid_to_jsid(name);
|
149
|
+
|
150
|
+
body.o$jsid = jsid;
|
151
|
+
define_method(this, jsid, body);
|
132
152
|
|
133
|
-
return
|
153
|
+
return null;
|
134
154
|
}
|
135
155
|
end
|
136
156
|
|
137
157
|
# FIXME: this could do with a better name
|
138
158
|
def donate(methods)
|
139
159
|
%x{
|
140
|
-
var included_in = this.$included_in, includee, method, table = this
|
160
|
+
var included_in = this.$included_in, includee, method, table = this._proto, dest;
|
141
161
|
|
142
162
|
if (included_in) {
|
143
163
|
for (var i = 0, length = included_in.length; i < length; i++) {
|
144
164
|
includee = included_in[i];
|
145
|
-
dest = includee
|
165
|
+
dest = includee._proto;
|
146
166
|
for (var j = 0, jj = methods.length; j < jj; j++) {
|
147
167
|
method = methods[j];
|
148
168
|
// if (!dest[method]) {
|
@@ -161,9 +181,14 @@ class Module
|
|
161
181
|
|
162
182
|
def include(*mods)
|
163
183
|
%x{
|
184
|
+
console.log("including " + this._name);
|
164
185
|
var i = mods.length - 1, mod;
|
165
186
|
while (i >= 0) {
|
166
187
|
#{mod = `mods[i]`};
|
188
|
+
console.log("include: " + mod._name);
|
189
|
+
|
190
|
+
define_iclass(this, mod);
|
191
|
+
|
167
192
|
#{mod.append_features self};
|
168
193
|
#{mod.included self};
|
169
194
|
|
@@ -184,8 +209,8 @@ class Module
|
|
184
209
|
|
185
210
|
def module_eval(&block)
|
186
211
|
%x{
|
187
|
-
if (block ===
|
188
|
-
|
212
|
+
if (block === null) {
|
213
|
+
throw RubyLocalJumpError.$new('no block given');
|
189
214
|
}
|
190
215
|
|
191
216
|
return block.call(this, null);
|
@@ -195,7 +220,7 @@ class Module
|
|
195
220
|
alias class_eval module_eval
|
196
221
|
|
197
222
|
def name
|
198
|
-
`this
|
223
|
+
`this._name`
|
199
224
|
end
|
200
225
|
|
201
226
|
alias public_instance_methods instance_methods
|
data/core/nil_class.rb
CHANGED
@@ -12,7 +12,7 @@ class NilClass
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def ==(other)
|
15
|
-
`
|
15
|
+
`other === nil`
|
16
16
|
end
|
17
17
|
|
18
18
|
def inspect
|
@@ -23,6 +23,10 @@ class NilClass
|
|
23
23
|
true
|
24
24
|
end
|
25
25
|
|
26
|
+
def singleton_class
|
27
|
+
NilClass
|
28
|
+
end
|
29
|
+
|
26
30
|
def to_a
|
27
31
|
[]
|
28
32
|
end
|
@@ -38,4 +42,4 @@ class NilClass
|
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
41
|
-
NIL = nil
|
45
|
+
NIL = nil
|
data/core/numeric.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class Numeric
|
2
|
+
include Comparable
|
3
|
+
|
2
4
|
def +(other)
|
3
5
|
`this + other`
|
4
6
|
end
|
@@ -72,13 +74,13 @@ class Numeric
|
|
72
74
|
end
|
73
75
|
|
74
76
|
def ==(other)
|
75
|
-
`this
|
77
|
+
`this == other`
|
76
78
|
end
|
77
79
|
|
78
80
|
def <=>(other)
|
79
81
|
%x{
|
80
82
|
if (typeof(other) !== 'number') {
|
81
|
-
return
|
83
|
+
return null;
|
82
84
|
}
|
83
85
|
|
84
86
|
return this < other ? -1 : (this > other ? 1 : 0);
|
@@ -93,13 +95,17 @@ class Numeric
|
|
93
95
|
`Math.ceil(this)`
|
94
96
|
end
|
95
97
|
|
98
|
+
def chr
|
99
|
+
`String.fromCharCode(this)`
|
100
|
+
end
|
101
|
+
|
96
102
|
def downto(finish, &block)
|
97
103
|
return enum_for :downto, finish unless block_given?
|
98
104
|
|
99
105
|
%x{
|
100
106
|
for (var i = this; i >= finish; i--) {
|
101
|
-
if (
|
102
|
-
return
|
107
|
+
if (block.call(__context, i) === __breaker) {
|
108
|
+
return __breaker.$v;
|
103
109
|
}
|
104
110
|
}
|
105
111
|
|
@@ -132,13 +138,17 @@ class Numeric
|
|
132
138
|
end
|
133
139
|
|
134
140
|
def nonzero?
|
135
|
-
`this.valueOf() === 0 ?
|
141
|
+
`this.valueOf() === 0 ? null : this`
|
136
142
|
end
|
137
143
|
|
138
144
|
def odd?
|
139
145
|
`this % 2 !== 0`
|
140
146
|
end
|
141
147
|
|
148
|
+
def ord
|
149
|
+
self
|
150
|
+
end
|
151
|
+
|
142
152
|
def pred
|
143
153
|
`this - 1`
|
144
154
|
end
|
@@ -150,8 +160,8 @@ class Numeric
|
|
150
160
|
|
151
161
|
%x{
|
152
162
|
for (var i = 0; i <= this; i++) {
|
153
|
-
if (
|
154
|
-
return
|
163
|
+
if (block.call(__context, i) === __breaker) {
|
164
|
+
return __breaker.$v;
|
155
165
|
}
|
156
166
|
}
|
157
167
|
|
@@ -168,7 +178,7 @@ class Numeric
|
|
168
178
|
end
|
169
179
|
|
170
180
|
def to_s(base = 10)
|
171
|
-
`this.toString(
|
181
|
+
`this.toString()`
|
172
182
|
end
|
173
183
|
|
174
184
|
def upto(finish, &block)
|
@@ -176,8 +186,8 @@ class Numeric
|
|
176
186
|
|
177
187
|
%x{
|
178
188
|
for (var i = 0; i <= finish; i++) {
|
179
|
-
if (
|
180
|
-
return
|
189
|
+
if (block.call(__context, i) === __breaker) {
|
190
|
+
return __breaker.$v;
|
181
191
|
}
|
182
192
|
}
|
183
193
|
|
data/core/proc.rb
CHANGED
data/core/range.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Helper function on runtime for creating range literals
|
2
2
|
%x{
|
3
|
-
|
4
|
-
var range = new RubyRange
|
3
|
+
Opal.range = function(beg, end, exc) {
|
4
|
+
var range = new RubyRange._alloc();
|
5
5
|
range.begin = beg;
|
6
6
|
range.end = end;
|
7
7
|
range.exclude = exc;
|
@@ -11,33 +11,92 @@
|
|
11
11
|
}
|
12
12
|
|
13
13
|
class Range
|
14
|
+
include Enumerable
|
15
|
+
|
16
|
+
def initialize(min, max, exclude = false)
|
17
|
+
@begin = min
|
18
|
+
@end = max
|
19
|
+
@exclude = exclude
|
20
|
+
end
|
21
|
+
|
22
|
+
def ==(other)
|
23
|
+
return false unless Range === other
|
24
|
+
|
25
|
+
exclude_end? == other.exclude_end? && `this.begin` == other.begin && `this.end` == other.end
|
26
|
+
end
|
27
|
+
|
28
|
+
# FIXME: currently hardcoded to assume range holds numerics
|
29
|
+
def ===(obj)
|
30
|
+
`return obj >= this.begin && obj <= this.end`
|
31
|
+
end
|
32
|
+
|
14
33
|
def begin
|
15
34
|
`this.begin`
|
16
35
|
end
|
17
36
|
|
37
|
+
def cover?(value)
|
38
|
+
`this.begin` <= value && value <= (exclude_end? ? `this.end` - 1 : `this.end`)
|
39
|
+
end
|
40
|
+
|
41
|
+
def each
|
42
|
+
return enum_for :each unless block_given?
|
43
|
+
|
44
|
+
current = min
|
45
|
+
|
46
|
+
while current != max
|
47
|
+
yield current
|
48
|
+
|
49
|
+
current = current.succ
|
50
|
+
end
|
51
|
+
|
52
|
+
yield current unless exclude_end?
|
53
|
+
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
18
57
|
def end
|
19
58
|
`this.end`
|
20
59
|
end
|
21
60
|
|
22
|
-
|
23
|
-
|
61
|
+
def eql?(other)
|
62
|
+
return false unless Range === other
|
24
63
|
|
25
|
-
|
26
|
-
|
64
|
+
exclude_end? == other.exclude_end? && `this.begin`.eql?(other.begin) && `this.end`.eql?(other.end)
|
65
|
+
end
|
27
66
|
|
28
|
-
def
|
29
|
-
|
30
|
-
@end = max
|
31
|
-
@exclude = exclude
|
67
|
+
def exclude_end?
|
68
|
+
`this.exclude`
|
32
69
|
end
|
33
70
|
|
34
71
|
# FIXME: currently hardcoded to assume range holds numerics
|
35
|
-
def
|
72
|
+
def include?(val)
|
36
73
|
`return obj >= this.begin && obj <= this.end`
|
37
74
|
end
|
38
75
|
|
39
|
-
def
|
40
|
-
|
76
|
+
def max
|
77
|
+
if block_given?
|
78
|
+
# I actually don't get what this should do
|
79
|
+
raise NotImplementedError
|
80
|
+
else
|
81
|
+
`this.end`
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def min
|
86
|
+
if block_given?
|
87
|
+
# I actually don't get what this should do
|
88
|
+
raise NotImplementedError
|
89
|
+
else
|
90
|
+
`this.begin`
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
alias member? include?
|
95
|
+
|
96
|
+
def step(n = 1)
|
97
|
+
return enum_for :step, n unless block_given?
|
98
|
+
|
99
|
+
raise NotImplementedError
|
41
100
|
end
|
42
101
|
|
43
102
|
def to_s
|
data/core/regexp.rb
CHANGED
@@ -20,8 +20,9 @@ class Regexp
|
|
20
20
|
var result = this.exec(string);
|
21
21
|
|
22
22
|
if (result) {
|
23
|
-
var match
|
24
|
-
|
23
|
+
var match = new RubyMatch._alloc();
|
24
|
+
match.$data = result;
|
25
|
+
|
25
26
|
#{$~ = `match`};
|
26
27
|
}
|
27
28
|
else {
|
@@ -43,8 +44,9 @@ class Regexp
|
|
43
44
|
var result = this.exec(pattern);
|
44
45
|
|
45
46
|
if (result) {
|
46
|
-
var match = new RubyMatch
|
47
|
+
var match = new RubyMatch._alloc();
|
47
48
|
match.$data = result;
|
49
|
+
|
48
50
|
return #{$~ = `match`};
|
49
51
|
}
|
50
52
|
else {
|