opal 0.3.18 → 0.3.19
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 +1 -1
- data/Gemfile +1 -3
- data/README.md +472 -10
- data/Rakefile +10 -52
- data/core/array.rb +9 -14
- data/core/basic_object.rb +7 -10
- data/core/boolean.rb +5 -1
- data/core/class.rb +15 -38
- data/core/dir.rb +89 -0
- data/core/enumerable.rb +133 -57
- data/core/error.rb +15 -1
- data/core/file.rb +85 -0
- data/core/hash.rb +186 -32
- data/core/kernel.rb +30 -31
- data/core/load_order +4 -2
- data/core/module.rb +42 -62
- data/core/numeric.rb +7 -1
- data/core/object.rb +1 -1
- data/core/proc.rb +6 -2
- data/core/range.rb +16 -28
- data/core/regexp.rb +3 -3
- data/core/runtime.js +281 -350
- data/core/string.rb +100 -110
- data/docs/CNAME +1 -0
- data/docs/Rakefile +55 -0
- data/docs/css/styles.css +50 -0
- data/docs/css/syntax.css +63 -0
- data/docs/layout/post.html +3 -0
- data/docs/layout/pre.html +11 -0
- data/examples/dependencies/app.rb +3 -0
- data/lib/opal.rb +2 -1
- data/lib/opal/builder.rb +36 -10
- data/lib/opal/builder_task.rb +51 -24
- data/lib/opal/grammar.rb +2509 -2439
- data/lib/opal/grammar.y +38 -5
- data/lib/opal/lexer.rb +18 -2
- data/lib/opal/parser.rb +375 -349
- data/lib/opal/scope.rb +24 -2
- data/lib/opal/version.rb +1 -1
- data/spec/builder/build_order_spec.rb +20 -0
- data/spec/builder/lib_name_for_spec.rb +24 -0
- data/spec/grammar/call_spec.rb +9 -6
- data/spec/grammar/lambda_spec.rb +64 -0
- data/spec/grammar/sclass_spec.rb +5 -3
- data/{core/spec → test}/core/array/allocate_spec.rb +0 -0
- data/{core/spec → test}/core/array/append_spec.rb +0 -0
- data/{core/spec → test}/core/array/assoc_spec.rb +0 -0
- data/{core/spec → test}/core/array/at_spec.rb +0 -0
- data/{core/spec → test}/core/array/clear_spec.rb +0 -0
- data/{core/spec → test}/core/array/clone_spec.rb +0 -0
- data/{core/spec → test}/core/array/collect_spec.rb +0 -0
- data/{core/spec → test}/core/array/compact_spec.rb +0 -0
- data/{core/spec → test}/core/array/concat_spec.rb +0 -0
- data/{core/spec → test}/core/array/constructor_spec.rb +0 -0
- data/{core/spec → test}/core/array/count_spec.rb +0 -0
- data/{core/spec → test}/core/array/delete_at_spec.rb +0 -0
- data/{core/spec → test}/core/array/delete_if_spec.rb +0 -0
- data/{core/spec → test}/core/array/delete_spec.rb +0 -0
- data/{core/spec → test}/core/array/each_index_spec.rb +0 -0
- data/{core/spec → test}/core/array/each_spec.rb +0 -0
- data/{core/spec → test}/core/array/element_reference_spec.rb +0 -0
- data/{core/spec → test}/core/array/empty_spec.rb +0 -0
- data/{core/spec → test}/core/array/eql_spec.rb +0 -0
- data/{core/spec → test}/core/array/fetch_spec.rb +0 -0
- data/{core/spec → test}/core/array/first_spec.rb +0 -0
- data/{core/spec → test}/core/array/flatten_spec.rb +0 -0
- data/{core/spec → test}/core/array/include_spec.rb +0 -0
- data/{core/spec → test}/core/array/insert_spec.rb +0 -0
- data/{core/spec → test}/core/array/last_spec.rb +0 -0
- data/{core/spec → test}/core/array/length_spec.rb +0 -0
- data/{core/spec → test}/core/array/map_spec.rb +0 -0
- data/{core/spec → test}/core/array/plus_spec.rb +0 -0
- data/{core/spec → test}/core/array/pop_spec.rb +0 -0
- data/{core/spec → test}/core/array/push_spec.rb +0 -0
- data/{core/spec → test}/core/array/rassoc_spec.rb +0 -0
- data/{core/spec → test}/core/array/reject_spec.rb +0 -0
- data/{core/spec → test}/core/array/replace_spec.rb +0 -0
- data/{core/spec → test}/core/array/reverse_each_spec.rb +0 -0
- data/{core/spec → test}/core/array/reverse_spec.rb +0 -0
- data/{core/spec → test}/core/array/size_spec.rb +0 -0
- data/{core/spec → test}/core/array/to_ary_spec.rb +0 -0
- data/{core/spec → test}/core/array/uniq_spec.rb +0 -0
- data/{core/spec → test}/core/array/zip_spec.rb +0 -0
- data/test/core/class/fixtures/classes.rb +9 -0
- data/test/core/class/new_spec.rb +108 -0
- data/{core/spec → test}/core/enumerable/all_spec.rb +0 -0
- data/{core/spec → test}/core/enumerable/any_spec.rb +0 -0
- data/{core/spec → test}/core/enumerable/collect_spec.rb +0 -0
- data/{core/spec → test}/core/enumerable/count_spec.rb +0 -0
- data/test/core/enumerable/detect_spec.rb +48 -0
- data/test/core/enumerable/drop_spec.rb +17 -0
- data/test/core/enumerable/drop_while_spec.rb +24 -0
- data/test/core/enumerable/each_with_index_spec.rb +11 -0
- data/test/core/enumerable/each_with_object_spec.rb +17 -0
- data/test/core/enumerable/entries_spec.rb +6 -0
- data/test/core/enumerable/find_all_spec.rb +13 -0
- data/test/core/enumerable/find_index_spec.rb +45 -0
- data/test/core/enumerable/find_spec.rb +48 -0
- data/test/core/enumerable/first_spec.rb +40 -0
- data/{core/spec → test}/core/enumerable/fixtures/classes.rb +19 -0
- data/test/core/enumerable/grep_spec.rb +21 -0
- data/test/core/enumerable/take_spec.rb +40 -0
- data/test/core/enumerable/to_a_spec.rb +6 -0
- data/{core/spec → test}/core/false/and_spec.rb +0 -0
- data/{core/spec → test}/core/false/inspect_spec.rb +0 -0
- data/{core/spec → test}/core/false/or_spec.rb +0 -0
- data/{core/spec → test}/core/false/to_s_spec.rb +0 -0
- data/{core/spec → test}/core/false/xor_spec.rb +0 -0
- data/test/core/file/expand_path_spec.rb +20 -0
- data/{core/spec → test}/core/hash/allocate_spec.rb +0 -0
- data/{core/spec → test}/core/hash/assoc_spec.rb +0 -0
- data/{core/spec → test}/core/hash/clear_spec.rb +0 -0
- data/{core/spec → test}/core/hash/clone_spec.rb +0 -0
- data/test/core/hash/default_spec.rb +9 -0
- data/{core/spec → test}/core/hash/delete_if_spec.rb +0 -0
- data/test/core/hash/each_key_spec.rb +15 -0
- data/test/core/hash/each_pair_spec.rb +30 -0
- data/test/core/hash/each_spec.rb +30 -0
- data/test/core/hash/each_value_spec.rb +15 -0
- data/{core/spec → test}/core/hash/element_reference_spec.rb +14 -0
- data/{core/spec → test}/core/hash/element_set_spec.rb +1 -0
- data/test/core/hash/empty_spec.rb +10 -0
- data/test/core/hash/fetch_spec.rb +24 -0
- data/test/core/hash/flatten_spec.rb +46 -0
- data/test/core/hash/has_key_spec.rb +24 -0
- data/test/core/hash/has_value_spec.rb +12 -0
- data/test/core/hash/include_spec.rb +24 -0
- data/test/core/hash/index_spec.rb +13 -0
- data/test/core/hash/indexes_spec.rb +9 -0
- data/test/core/hash/indices_spec.rb +9 -0
- data/test/core/hash/invert_spec.rb +12 -0
- data/test/core/hash/keep_if_spec.rb +18 -0
- data/test/core/hash/key_spec.rb +24 -0
- data/test/core/hash/keys_spec.rb +10 -0
- data/test/core/hash/length_spec.rb +10 -0
- data/test/core/hash/member_spec.rb +24 -0
- data/{core/spec → test}/core/hash/merge_spec.rb +0 -0
- data/{core/spec → test}/core/hash/new_spec.rb +0 -0
- data/test/core/hash/rassoc_spec.rb +34 -0
- data/test/core/hash/replace_spec.rb +7 -0
- data/test/core/hash/select_spec.rb +52 -0
- data/test/core/hash/shift_spec.rb +19 -0
- data/test/core/hash/size_spec.rb +10 -0
- data/test/core/hash/update_spec.rb +17 -0
- data/test/core/hash/value_spec.rb +12 -0
- data/test/core/hash/values_at_spec.rb +9 -0
- data/test/core/hash/values_spec.rb +7 -0
- data/test/core/kernel/eql_spec.rb +15 -0
- data/test/core/kernel/equal_value_spec.rb +12 -0
- data/test/core/kernel/loop_spec.rb +23 -0
- data/test/core/kernel/nil_spec.rb +7 -0
- data/test/core/kernel/proc_spec.rb +9 -0
- data/test/core/kernel/rand_spec.rb +14 -0
- data/test/core/kernel/respond_to_spec.rb +24 -0
- data/test/core/kernel/send_spec.rb +56 -0
- data/test/core/kernel/tap_spec.rb +10 -0
- data/test/core/kernel/to_s_spec.rb +5 -0
- data/{core/spec → test}/core/matchdata/to_a_spec.rb +0 -0
- data/{core/spec → test}/core/nil/and_spec.rb +0 -0
- data/{core/spec → test}/core/nil/inspect_spec.rb +0 -0
- data/{core/spec → test}/core/nil/nil_spec.rb +0 -0
- data/{core/spec → test}/core/nil/or_spec.rb +0 -0
- data/{core/spec → test}/core/nil/to_a_spec.rb +0 -0
- data/{core/spec → test}/core/nil/to_f_spec.rb +0 -0
- data/{core/spec → test}/core/nil/to_i_spec.rb +0 -0
- data/{core/spec → test}/core/nil/to_s_spec.rb +0 -0
- data/{core/spec → test}/core/nil/xor_spec.rb +0 -0
- data/{core/spec → test}/core/numeric/equal_value_spec.rb +0 -0
- data/test/core/range/begin_spec.rb +9 -0
- data/test/core/range/case_compare_spec.rb +16 -0
- data/test/core/range/end_spec.rb +9 -0
- data/{core/spec → test}/core/regexp/match_spec.rb +0 -0
- data/test/core/string/capitalize_spec.rb +10 -0
- data/test/core/string/casecmp_spec.rb +16 -0
- data/test/core/string/chomp_spec.rb +43 -0
- data/test/core/string/chop_spec.rb +10 -0
- data/test/core/string/chr_spec.rb +13 -0
- data/test/core/string/comparison_spec.rb +13 -0
- data/test/core/string/downcase_spec.rb +6 -0
- data/test/core/string/element_reference_spec.rb +72 -0
- data/test/core/string/empty_spec.rb +8 -0
- data/test/core/string/end_with_spec.rb +12 -0
- data/test/core/string/fixtures/classes.rb +3 -0
- data/test/core/string/gsub_spec.rb +17 -0
- data/test/core/string/include_spec.rb +12 -0
- data/test/core/string/intern_spec.rb +9 -0
- data/test/core/string/length_spec.rb +9 -0
- data/test/core/string/lstrip_spec.rb +7 -0
- data/test/core/string/match_spec.rb +27 -0
- data/test/core/string/next_spec.rb +10 -0
- data/test/core/string/ord_spec.rb +9 -0
- data/test/core/string/partition_spec.rb +10 -0
- data/test/core/string/reverse_spec.rb +7 -0
- data/test/core/string/rstrip_spec.rb +7 -0
- data/test/core/string/size_spec.rb +9 -0
- data/test/core/string/slice_spec.rb +72 -0
- data/test/core/string/split_spec.rb +5 -0
- data/test/core/string/start_with_spec.rb +12 -0
- data/test/core/string/strip_spec.rb +6 -0
- data/test/core/string/sub_spec.rb +22 -0
- data/test/core/string/succ_spec.rb +10 -0
- data/test/core/string/sum_spec.rb +5 -0
- data/test/core/string/swapcase_spec.rb +18 -0
- data/test/core/string/to_a_spec.rb +9 -0
- data/test/core/string/to_f_spec.rb +14 -0
- data/test/core/string/to_i_spec.rb +25 -0
- data/test/core/string/to_s_spec.rb +13 -0
- data/test/core/string/to_str_spec.rb +13 -0
- data/test/core/string/to_sym_spec.rb +9 -0
- data/test/core/string/upcase_spec.rb +6 -0
- data/test/core/symbol/to_proc_spec.rb +12 -0
- data/{core/spec → test}/core/true/and_spec.rb +0 -0
- data/{core/spec → test}/core/true/inspect_spec.rb +0 -0
- data/{core/spec → test}/core/true/or_spec.rb +0 -0
- data/{core/spec → test}/core/true/to_s_spec.rb +0 -0
- data/{core/spec → test}/core/true/xor_spec.rb +0 -0
- data/test/index.html +11 -0
- data/{core/spec → test}/language/alias_spec.rb +4 -0
- data/{core/spec → test}/language/and_spec.rb +0 -0
- data/{core/spec → test}/language/array_spec.rb +0 -0
- data/{core/spec → test}/language/block_spec.rb +0 -0
- data/{core/spec → test}/language/break_spec.rb +0 -0
- data/{core/spec → test}/language/case_spec.rb +0 -0
- data/{core/spec → test}/language/defined_spec.rb +0 -0
- data/{core/spec → test}/language/ensure_spec.rb +0 -0
- data/test/language/fixtures/yield.rb +23 -0
- data/{core/spec → test}/language/hash_spec.rb +0 -0
- data/{core/spec → test}/language/if_spec.rb +0 -0
- data/test/language/literal_lambda_spec.rb +47 -0
- data/{core/spec → test}/language/loop_spec.rb +0 -0
- data/{core/spec → test}/language/metaclass_spec.rb +0 -0
- data/{core/spec → test}/language/next_spec.rb +0 -0
- data/{core/spec → test}/language/or_spec.rb +0 -0
- data/{core/spec → test}/language/predefined_spec.rb +0 -0
- data/{core/spec → test}/language/regexp_spec.rb +0 -0
- data/{core/spec → test}/language/send_spec.rb +0 -0
- data/{core/spec → test}/language/singleton_class_spec.rb +0 -0
- data/{core/spec → test}/language/super_spec.rb +0 -0
- data/{core/spec → test}/language/symbol_spec.rb +0 -0
- data/{core/spec → test}/language/undef_spec.rb +0 -0
- data/{core/spec → test}/language/unless_spec.rb +0 -0
- data/{core/spec → test}/language/until_spec.rb +0 -0
- data/{core/spec → test}/language/variables_spec.rb +0 -0
- data/{core/spec → test}/language/while_spec.rb +0 -0
- data/test/language/yield_spec.rb +100 -0
- data/test/opal/array/subclassing_spec.rb +32 -0
- data/test/opal/class/bridge_class_spec.rb +37 -0
- data/test/opal/exception/subclassing_spec.rb +17 -0
- data/test/opal/runtime/_methods_spec.rb +48 -0
- data/test/opal/runtime/class_hierarchy_spec.rb +22 -0
- data/test/opal/runtime/def_spec.rb +23 -0
- data/test/opal/string/subclassing_spec.rb +26 -0
- data/test/spec_helper.rb +3 -0
- metadata +437 -111
- data/core/spec/core/class/new_spec.rb +0 -16
- data/core/spec/core/hash/default_spec.rb +0 -4
- data/core/spec/core/symbol/to_proc_spec.rb +0 -6
- data/core/spec/index.html +0 -11
- data/spec/builder/build_source_spec.rb +0 -52
data/core/kernel.rb
CHANGED
@@ -29,29 +29,18 @@ module Kernel
|
|
29
29
|
}
|
30
30
|
end
|
31
31
|
|
32
|
-
def at_exit(&block)
|
33
|
-
%x{
|
34
|
-
if (block === null) {
|
35
|
-
throw RubyArgError.$new('called without a block');
|
36
|
-
}
|
37
|
-
|
38
|
-
end_procs.push(block);
|
39
|
-
|
40
|
-
return block;
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
32
|
def class
|
45
|
-
`
|
33
|
+
`return this._real`
|
46
34
|
end
|
47
35
|
|
48
36
|
def define_singleton_method(name, &body)
|
49
37
|
%x{
|
50
|
-
if (body ===
|
51
|
-
|
38
|
+
if (body === nil) {
|
39
|
+
no_block_given();
|
52
40
|
}
|
53
41
|
|
54
|
-
|
42
|
+
// FIXME: need to donate()
|
43
|
+
this.$singleton_class()._proto[mid_to_jsid(name)] = body;
|
55
44
|
|
56
45
|
return this;
|
57
46
|
}
|
@@ -88,14 +77,14 @@ module Kernel
|
|
88
77
|
end
|
89
78
|
|
90
79
|
def instance_variable_defined?(name)
|
91
|
-
`
|
80
|
+
`__hasOwn.call(this, name.substr(1))`
|
92
81
|
end
|
93
82
|
|
94
83
|
def instance_variable_get(name)
|
95
84
|
%x{
|
96
85
|
var ivar = this[name.substr(1)];
|
97
86
|
|
98
|
-
return ivar ==
|
87
|
+
return ivar == null ? nil : ivar;
|
99
88
|
}
|
100
89
|
end
|
101
90
|
|
@@ -142,7 +131,7 @@ module Kernel
|
|
142
131
|
|
143
132
|
%x{
|
144
133
|
while (true) {
|
145
|
-
if (block.call(__context) ===
|
134
|
+
if (block.call(__context) === __breaker) {
|
146
135
|
return breaker.$v;
|
147
136
|
}
|
148
137
|
}
|
@@ -168,7 +157,13 @@ module Kernel
|
|
168
157
|
end
|
169
158
|
|
170
159
|
def proc(&block)
|
171
|
-
|
160
|
+
%x{
|
161
|
+
if (block === nil) {
|
162
|
+
no_block_given();
|
163
|
+
}
|
164
|
+
|
165
|
+
return block;
|
166
|
+
}
|
172
167
|
end
|
173
168
|
|
174
169
|
def protected(*)
|
@@ -183,9 +178,10 @@ module Kernel
|
|
183
178
|
%x{
|
184
179
|
for (var i = 0; i < strs.length; i++) {
|
185
180
|
var obj = strs[i];
|
186
|
-
console.log(
|
181
|
+
console.log(#{ `obj`.to_s });
|
187
182
|
}
|
188
183
|
}
|
184
|
+
nil
|
189
185
|
end
|
190
186
|
|
191
187
|
alias sprintf format
|
@@ -193,9 +189,9 @@ module Kernel
|
|
193
189
|
def raise(exception, string = undefined)
|
194
190
|
%x{
|
195
191
|
if (typeof(exception) === 'string') {
|
196
|
-
exception = #{
|
192
|
+
exception = #{RuntimeError.new exception};
|
197
193
|
}
|
198
|
-
else if (#{!exception.is_a?
|
194
|
+
else if (#{!exception.is_a? Exception}) {
|
199
195
|
exception = #{`exception`.new string};
|
200
196
|
}
|
201
197
|
|
@@ -208,7 +204,7 @@ module Kernel
|
|
208
204
|
end
|
209
205
|
|
210
206
|
def require(path)
|
211
|
-
`
|
207
|
+
`Opal.require(path)`
|
212
208
|
end
|
213
209
|
|
214
210
|
def respond_to?(name)
|
@@ -219,18 +215,17 @@ module Kernel
|
|
219
215
|
%x{
|
220
216
|
var obj = this, klass;
|
221
217
|
|
222
|
-
if (obj.
|
223
|
-
if (
|
218
|
+
if (obj._isObject) {
|
219
|
+
if (obj._isNumber || obj._isString) {
|
224
220
|
throw RubyTypeError.$new("can't define singleton");
|
225
221
|
}
|
226
222
|
}
|
227
223
|
|
228
|
-
if ((obj._klass.
|
224
|
+
if ((obj._klass._isSingleton) && obj._klass.__attached__ == obj) {
|
229
225
|
klass = obj._klass;
|
230
226
|
}
|
231
227
|
else {
|
232
228
|
var class_id = obj._klass._name;
|
233
|
-
|
234
229
|
klass = make_metaclass(obj, obj._klass);
|
235
230
|
}
|
236
231
|
|
@@ -240,8 +235,8 @@ module Kernel
|
|
240
235
|
|
241
236
|
def tap(&block)
|
242
237
|
%x{
|
243
|
-
if (block ===
|
244
|
-
|
238
|
+
if (block === nil) {
|
239
|
+
no_block_given();
|
245
240
|
}
|
246
241
|
|
247
242
|
if (block.call(__context, this) === __breaker) {
|
@@ -252,7 +247,11 @@ module Kernel
|
|
252
247
|
}
|
253
248
|
end
|
254
249
|
|
250
|
+
def to_proc
|
251
|
+
self
|
252
|
+
end
|
253
|
+
|
255
254
|
def to_s
|
256
|
-
`return "#<" +
|
255
|
+
`return "#<" + this._klass._real._name + ":0x" + (this._id * 400487).toString(16) + ">";`
|
257
256
|
end
|
258
257
|
end
|
data/core/load_order
CHANGED
data/core/module.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
class Module
|
2
2
|
def ===(object)
|
3
3
|
%x{
|
4
|
+
|
5
|
+
if (object == null) {
|
6
|
+
return false;
|
7
|
+
}
|
8
|
+
|
4
9
|
var search = object._klass;
|
5
10
|
|
6
11
|
while (search) {
|
@@ -16,8 +21,7 @@ class Module
|
|
16
21
|
end
|
17
22
|
|
18
23
|
def alias_method(newname, oldname)
|
19
|
-
`
|
20
|
-
|
24
|
+
`this._proto[mid_to_jsid(newname)] = this._proto[mid_to_jsid(oldname)]`
|
21
25
|
self
|
22
26
|
end
|
23
27
|
|
@@ -27,10 +31,10 @@ class Module
|
|
27
31
|
result = [];
|
28
32
|
|
29
33
|
while (parent) {
|
30
|
-
if (parent.
|
34
|
+
if (parent._isSingleton) {
|
31
35
|
continue;
|
32
36
|
}
|
33
|
-
else if (parent.
|
37
|
+
else if (parent._isIClass)
|
34
38
|
result.push(parent._klass);
|
35
39
|
else {
|
36
40
|
result.push(parent);
|
@@ -65,19 +69,15 @@ class Module
|
|
65
69
|
|
66
70
|
var donator = module._alloc.prototype,
|
67
71
|
prototype = klass._proto,
|
68
|
-
methods =
|
69
|
-
|
70
|
-
for (var
|
71
|
-
|
72
|
-
|
73
|
-
prototype[method] = donator[method];
|
74
|
-
methods.push(method);
|
75
|
-
}
|
76
|
-
}
|
72
|
+
methods = module._methods;
|
73
|
+
|
74
|
+
for (var i = 0, length = methods.length; i < length; i++) {
|
75
|
+
var method = methods[i];
|
76
|
+
prototype[method] = donator[method];
|
77
77
|
}
|
78
78
|
|
79
79
|
if (klass.$included_in) {
|
80
|
-
klass
|
80
|
+
__donate(klass, methods.slice(), true);
|
81
81
|
}
|
82
82
|
}
|
83
83
|
|
@@ -88,17 +88,24 @@ class Module
|
|
88
88
|
%x{
|
89
89
|
function define_attr(klass, name, getter, setter) {
|
90
90
|
if (getter) {
|
91
|
-
|
91
|
+
var get_jsid = mid_to_jsid(name);
|
92
|
+
|
93
|
+
klass._alloc.prototype[get_jsid] = function() {
|
92
94
|
var res = this[name];
|
95
|
+
return res == null ? nil : res;
|
96
|
+
};
|
93
97
|
|
94
|
-
|
95
|
-
});
|
98
|
+
__donate(klass, [get_jsid]);
|
96
99
|
}
|
97
100
|
|
98
101
|
if (setter) {
|
99
|
-
|
102
|
+
var set_jsid = mid_to_jsid(name + '=');
|
103
|
+
|
104
|
+
klass._alloc.prototype[set_jsid] = function(val) {
|
100
105
|
return this[name] = val;
|
101
|
-
}
|
106
|
+
};
|
107
|
+
|
108
|
+
__donate(klass, [set_jsid]);
|
102
109
|
}
|
103
110
|
}
|
104
111
|
}
|
@@ -109,7 +116,7 @@ class Module
|
|
109
116
|
define_attr(this, attrs[i], true, true);
|
110
117
|
}
|
111
118
|
|
112
|
-
return
|
119
|
+
return nil;
|
113
120
|
}
|
114
121
|
end
|
115
122
|
|
@@ -119,7 +126,7 @@ class Module
|
|
119
126
|
define_attr(this, attrs[i], true, false);
|
120
127
|
}
|
121
128
|
|
122
|
-
return
|
129
|
+
return nil;
|
123
130
|
}
|
124
131
|
end
|
125
132
|
|
@@ -129,7 +136,7 @@ class Module
|
|
129
136
|
define_attr(this, attrs[i], false, true);
|
130
137
|
}
|
131
138
|
|
132
|
-
return
|
139
|
+
return nil;
|
133
140
|
}
|
134
141
|
end
|
135
142
|
|
@@ -139,43 +146,19 @@ class Module
|
|
139
146
|
self
|
140
147
|
end
|
141
148
|
|
142
|
-
def define_method(name, &
|
149
|
+
def define_method(name, &block)
|
143
150
|
%x{
|
144
|
-
if (
|
145
|
-
|
151
|
+
if (block === nil) {
|
152
|
+
no_block_given();
|
146
153
|
}
|
147
154
|
|
148
155
|
var jsid = mid_to_jsid(name);
|
156
|
+
block._jsid = jsid;
|
149
157
|
|
150
|
-
|
151
|
-
|
158
|
+
this._alloc.prototype[jsid] = block;
|
159
|
+
__donate(this, [jsid]);
|
152
160
|
|
153
|
-
return
|
154
|
-
}
|
155
|
-
end
|
156
|
-
|
157
|
-
# FIXME: this could do with a better name
|
158
|
-
def donate(methods)
|
159
|
-
%x{
|
160
|
-
var included_in = this.$included_in, includee, method, table = this._proto, dest;
|
161
|
-
|
162
|
-
if (included_in) {
|
163
|
-
for (var i = 0, length = included_in.length; i < length; i++) {
|
164
|
-
includee = included_in[i];
|
165
|
-
dest = includee._proto;
|
166
|
-
for (var j = 0, jj = methods.length; j < jj; j++) {
|
167
|
-
method = methods[j];
|
168
|
-
// if (!dest[method]) {
|
169
|
-
dest[method] = table[method];
|
170
|
-
// }
|
171
|
-
}
|
172
|
-
// if our includee is itself included in another module/class then it
|
173
|
-
// should also donate its new methods
|
174
|
-
if (includee.$included_in) {
|
175
|
-
includee.$donate(methods);
|
176
|
-
}
|
177
|
-
}
|
178
|
-
}
|
161
|
+
return nil;
|
179
162
|
}
|
180
163
|
end
|
181
164
|
|
@@ -183,13 +166,10 @@ class Module
|
|
183
166
|
%x{
|
184
167
|
var i = mods.length - 1, mod;
|
185
168
|
while (i >= 0) {
|
186
|
-
|
187
|
-
|
169
|
+
mod = mods[i];
|
188
170
|
define_iclass(this, mod);
|
189
|
-
|
190
|
-
|
191
|
-
#{mod.included self};
|
192
|
-
|
171
|
+
mod.$append_features(this);
|
172
|
+
mod.$included(this);
|
193
173
|
i--;
|
194
174
|
}
|
195
175
|
|
@@ -207,11 +187,11 @@ class Module
|
|
207
187
|
|
208
188
|
def module_eval(&block)
|
209
189
|
%x{
|
210
|
-
if (block ===
|
211
|
-
|
190
|
+
if (block === nil) {
|
191
|
+
no_block_given();
|
212
192
|
}
|
213
193
|
|
214
|
-
return block.call(this
|
194
|
+
return block.call(this);
|
215
195
|
}
|
216
196
|
end
|
217
197
|
|
data/core/numeric.rb
CHANGED
data/core/object.rb
CHANGED
data/core/proc.rb
CHANGED
data/core/range.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
# Helper function on runtime for creating range literals
|
2
|
-
%x{
|
3
|
-
Opal.range = function(beg, end, exc) {
|
4
|
-
var range = new RubyRange._alloc();
|
5
|
-
range.begin = beg;
|
6
|
-
range.end = end;
|
7
|
-
range.exclude = exc;
|
8
|
-
|
9
|
-
return range;
|
10
|
-
};
|
11
|
-
}
|
12
|
-
|
13
1
|
class Range
|
14
2
|
include Enumerable
|
15
3
|
|
4
|
+
%x{
|
5
|
+
var range_class = this;
|
6
|
+
def._isRange = true;
|
7
|
+
|
8
|
+
Opal.range = function(beg, end, exc) {
|
9
|
+
var range = new range_class._alloc();
|
10
|
+
range.begin = beg;
|
11
|
+
range.end = end;
|
12
|
+
range.exclude = exc;
|
13
|
+
|
14
|
+
return range;
|
15
|
+
};
|
16
|
+
}
|
17
|
+
|
16
18
|
def initialize(min, max, exclude = false)
|
17
19
|
@begin = min
|
18
20
|
@end = max
|
@@ -73,23 +75,9 @@ class Range
|
|
73
75
|
`return obj >= this.begin && obj <= this.end`
|
74
76
|
end
|
75
77
|
|
76
|
-
|
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
|
78
|
+
alias max end
|
84
79
|
|
85
|
-
|
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
|
80
|
+
alias min begin
|
93
81
|
|
94
82
|
alias member? include?
|
95
83
|
|