opal 0.3.16 → 0.3.17
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +8 -7
- data/README.md +21 -13
- data/Rakefile +64 -78
- data/bin/opal +18 -29
- data/core/alpha.rb +2 -9
- data/core/array.rb +106 -50
- data/core/basic_object.rb +10 -8
- data/core/boolean.rb +2 -0
- data/core/class.rb +25 -13
- data/core/comparable.rb +6 -6
- data/core/enumerable.rb +90 -94
- data/core/enumerator.rb +3 -3
- data/core/hash.rb +86 -46
- data/core/kernel.rb +55 -39
- data/core/load_order +2 -5
- data/core/match_data.rb +1 -1
- data/core/module.rb +45 -20
- data/core/nil_class.rb +6 -2
- data/core/numeric.rb +20 -10
- data/core/proc.rb +2 -2
- data/core/range.rb +72 -13
- data/core/regexp.rb +5 -3
- data/core/runtime.js +228 -287
- data/core/string.rb +345 -37
- data/core/top_self.rb +1 -1
- data/lib/opal.rb +13 -91
- data/lib/opal/builder.rb +47 -120
- data/lib/opal/builder_task.rb +74 -0
- data/lib/opal/{parser/grammar.rb → grammar.rb} +1094 -1083
- data/lib/opal/{parser/grammar.y → grammar.y} +7 -0
- data/lib/opal/{parser/lexer.rb → lexer.rb} +32 -11
- data/lib/opal/{parser/parser.rb → parser.rb} +232 -238
- data/lib/opal/{parser/scope.rb → scope.rb} +72 -9
- data/lib/opal/version.rb +2 -3
- data/opal.gemspec +1 -2
- data/{core_spec → spec}/core/array/allocate_spec.rb +1 -3
- data/{core_spec → spec}/core/array/append_spec.rb +1 -4
- data/{core_spec → spec}/core/array/assoc_spec.rb +1 -4
- data/{core_spec → spec}/core/array/at_spec.rb +1 -3
- data/{core_spec → spec}/core/array/clear_spec.rb +1 -3
- data/spec/core/array/clone_spec.rb +15 -0
- data/{core_spec/core/array/shared/collect.rb → spec/core/array/collect_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/compact_spec.rb +1 -3
- data/{core_spec → spec}/core/array/concat_spec.rb +1 -3
- data/{core_spec → spec}/core/array/constructor_spec.rb +9 -3
- data/{core_spec → spec}/core/array/count_spec.rb +1 -3
- data/{core_spec → spec}/core/array/delete_at_spec.rb +1 -4
- data/{core_spec → spec}/core/array/delete_if_spec.rb +1 -4
- data/{core_spec → spec}/core/array/delete_spec.rb +1 -4
- data/{core_spec → spec}/core/array/each_index_spec.rb +1 -4
- data/{core_spec → spec}/core/array/each_spec.rb +1 -4
- data/{core_spec → spec}/core/array/element_reference_spec.rb +74 -4
- data/{core_spec → spec}/core/array/empty_spec.rb +1 -4
- data/{core_spec/core/array/shared/eql.rb → spec/core/array/eql_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/fetch_spec.rb +1 -4
- data/{core_spec → spec}/core/array/first_spec.rb +1 -3
- data/{core_spec → spec}/core/array/flatten_spec.rb +1 -3
- data/{core_spec → spec}/core/array/include_spec.rb +1 -3
- data/{core_spec → spec}/core/array/insert_spec.rb +1 -4
- data/{core_spec → spec}/core/array/last_spec.rb +1 -4
- data/{core_spec/core/array/shared/length.rb → spec/core/array/length_spec.rb} +1 -1
- data/spec/core/array/map_spec.rb +53 -0
- data/{core_spec → spec}/core/array/plus_spec.rb +1 -4
- data/{core_spec → spec}/core/array/pop_spec.rb +1 -4
- data/{core_spec → spec}/core/array/push_spec.rb +1 -4
- data/{core_spec → spec}/core/array/rassoc_spec.rb +1 -4
- data/{core_spec → spec}/core/array/reject_spec.rb +1 -4
- data/{core_spec/core/array/shared/replace.rb → spec/core/array/replace_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/reverse_each_spec.rb +1 -4
- data/{core_spec → spec}/core/array/reverse_spec.rb +1 -4
- data/spec/core/array/size_spec.rb +6 -0
- data/spec/core/array/to_ary_spec.rb +6 -0
- data/spec/core/array/uniq_spec.rb +22 -0
- data/spec/core/array/zip_spec.rb +20 -0
- data/{core_spec → spec}/core/class/new_spec.rb +1 -4
- data/{core_spec → spec}/core/enumerable/all_spec.rb +1 -4
- data/{core_spec → spec}/core/enumerable/any_spec.rb +1 -4
- data/{core_spec/core/enumerable/shared/collect.rb → spec/core/enumerable/collect_spec.rb} +1 -1
- data/{core_spec → spec}/core/enumerable/count_spec.rb +2 -5
- data/{core_spec → spec}/core/enumerable/fixtures/classes.rb +1 -2
- data/{core_spec → spec}/core/false/and_spec.rb +1 -3
- data/{core_spec → spec}/core/false/inspect_spec.rb +1 -3
- data/{core_spec → spec}/core/false/or_spec.rb +1 -3
- data/{core_spec → spec}/core/false/to_s_spec.rb +1 -3
- data/{core_spec → spec}/core/false/xor_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/allocate_spec.rb +1 -3
- data/spec/core/hash/assoc_spec.rb +25 -0
- data/{core_spec → spec}/core/hash/clear_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/clone_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/default_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/delete_if_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/element_reference_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/element_set_spec.rb +1 -3
- data/spec/core/hash/merge_spec.rb +37 -0
- data/{core_spec → spec}/core/hash/new_spec.rb +1 -3
- data/{core_spec → spec}/core/matchdata/to_a_spec.rb +1 -3
- data/{core_spec → spec}/core/nil/and_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/inspect_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/nil_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/or_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_a_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_f_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_i_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_s_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/xor_spec.rb +1 -4
- data/{core_spec → spec}/core/numeric/equal_value_spec.rb +1 -3
- data/{core_spec → spec}/core/regexp/match_spec.rb +10 -3
- data/{core_spec → spec}/core/symbol/to_proc_spec.rb +1 -3
- data/{core_spec → spec}/core/true/and_spec.rb +1 -3
- data/{core_spec → spec}/core/true/inspect_spec.rb +1 -3
- data/{core_spec → spec}/core/true/or_spec.rb +1 -3
- data/{core_spec → spec}/core/true/to_s_spec.rb +1 -3
- data/{core_spec → spec}/core/true/xor_spec.rb +1 -3
- data/spec/index.html +11 -0
- data/{core_spec → spec}/language/alias_spec.rb +1 -3
- data/{core_spec → spec}/language/and_spec.rb +1 -4
- data/{core_spec → spec}/language/array_spec.rb +1 -4
- data/{core_spec → spec}/language/block_spec.rb +20 -3
- data/{core_spec → spec}/language/break_spec.rb +40 -3
- data/{core_spec → spec}/language/case_spec.rb +1 -4
- data/{core_spec → spec}/language/defined_spec.rb +9 -3
- data/{core_spec → spec}/language/ensure_spec.rb +38 -3
- data/{core_spec → spec}/language/hash_spec.rb +1 -3
- data/{core_spec → spec}/language/if_spec.rb +1 -4
- data/{core_spec → spec}/language/loop_spec.rb +1 -3
- data/spec/language/metaclass_spec.rb +13 -0
- data/{core_spec → spec}/language/next_spec.rb +47 -3
- data/{core_spec → spec}/language/or_spec.rb +1 -4
- data/{core_spec → spec}/language/predefined_spec.rb +1 -3
- data/{core_spec/language/regexp/interpolation_spec.rb → spec/language/regexp_spec.rb} +6 -3
- data/{core_spec → spec}/language/send_spec.rb +38 -4
- data/spec/language/singleton_class_spec.rb +31 -0
- data/spec/language/super_spec.rb +188 -0
- data/{core_spec → spec}/language/symbol_spec.rb +1 -3
- data/{core_spec → spec}/language/undef_spec.rb +1 -3
- data/{core_spec → spec}/language/unless_spec.rb +1 -4
- data/{core_spec → spec}/language/until_spec.rb +1 -3
- data/{core_spec → spec}/language/variables_spec.rb +1 -3
- data/{core_spec → spec}/language/while_spec.rb +1 -3
- data/{spec → test}/builder/build_source_spec.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/adam.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/a.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/wow/b.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/beynon.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/charles.js +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/a.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/b.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/x.js +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/y.js +0 -0
- data/{spec → test}/grammar/alias_spec.rb +0 -0
- data/{spec → test}/grammar/and_spec.rb +0 -0
- data/{spec → test}/grammar/array_spec.rb +0 -0
- data/{spec → test}/grammar/attrasgn_spec.rb +0 -0
- data/{spec → test}/grammar/begin_spec.rb +0 -0
- data/{spec → test}/grammar/block_spec.rb +0 -0
- data/{spec → test}/grammar/break_spec.rb +0 -0
- data/{spec → test}/grammar/call_spec.rb +0 -0
- data/{spec → test}/grammar/class_spec.rb +0 -0
- data/{spec → test}/grammar/const_spec.rb +0 -0
- data/{spec → test}/grammar/cvar_spec.rb +0 -0
- data/{spec → test}/grammar/def_spec.rb +0 -0
- data/{spec → test}/grammar/false_spec.rb +0 -0
- data/{spec → test}/grammar/file_spec.rb +0 -0
- data/{spec → test}/grammar/gvar_spec.rb +0 -0
- data/{spec → test}/grammar/hash_spec.rb +0 -0
- data/{spec → test}/grammar/iasgn_spec.rb +0 -0
- data/{spec → test}/grammar/if_spec.rb +0 -0
- data/{spec → test}/grammar/iter_spec.rb +0 -0
- data/{spec → test}/grammar/ivar_spec.rb +0 -0
- data/{spec → test}/grammar/lasgn_spec.rb +0 -0
- data/{spec → test}/grammar/line_spec.rb +0 -0
- data/{spec → test}/grammar/lvar_spec.rb +0 -0
- data/{spec → test}/grammar/masgn_spec.rb +0 -0
- data/{spec → test}/grammar/module_spec.rb +0 -0
- data/{spec → test}/grammar/nil_spec.rb +0 -0
- data/{spec → test}/grammar/not_spec.rb +0 -0
- data/{spec → test}/grammar/op_asgn1_spec.rb +0 -0
- data/{spec → test}/grammar/op_asgn2_spec.rb +0 -0
- data/{spec → test}/grammar/or_spec.rb +0 -0
- data/{spec → test}/grammar/return_spec.rb +0 -0
- data/{spec → test}/grammar/sclass_spec.rb +0 -0
- data/{spec → test}/grammar/self_spec.rb +0 -0
- data/{spec → test}/grammar/str_spec.rb +0 -0
- data/{spec → test}/grammar/super_spec.rb +0 -0
- data/{spec → test}/grammar/true_spec.rb +0 -0
- data/{spec → test}/grammar/undef_spec.rb +0 -0
- data/{spec → test}/grammar/unless_spec.rb +0 -0
- data/{spec → test}/grammar/while_spec.rb +0 -0
- data/{spec → test}/grammar/xstr_spec.rb +0 -0
- data/{spec → test}/grammar/yield_spec.rb +0 -0
- data/{spec → test}/spec_helper.rb +0 -0
- metadata +330 -264
- data/core/debug.js +0 -59
- data/core/debug.rb +0 -35
- data/core/dir.rb +0 -90
- data/core/file.rb +0 -83
- data/core/gemlib.rb +0 -30
- data/core/io.rb +0 -44
- data/core_spec/README.md +0 -34
- data/core_spec/core/array/collect_spec.rb +0 -3
- data/core_spec/core/array/element_set_spec.rb +0 -7
- data/core_spec/core/array/eql_spec.rb +0 -3
- data/core_spec/core/array/equal_value_spec.rb +0 -3
- data/core_spec/core/array/fixtures/classes.rb +0 -8
- data/core_spec/core/array/length_spec.rb +0 -3
- data/core_spec/core/array/map_spec.rb +0 -3
- data/core_spec/core/array/replace_spec.rb +0 -3
- data/core_spec/core/enumerable/collect_spec.rb +0 -3
- data/core_spec/core/enumerable/detect_spec.rb +0 -3
- data/core_spec/core/enumerable/find_spec.rb +0 -3
- data/core_spec/core/enumerable/first_spec.rb +0 -3
- data/core_spec/core/enumerable/shared/entries.rb +0 -7
- data/core_spec/core/enumerable/shared/find.rb +0 -49
- data/core_spec/core/enumerable/shared/take.rb +0 -31
- data/core_spec/core/enumerable/to_a_spec.rb +0 -7
- data/core_spec/core/hash/assoc_spec.rb +0 -29
- data/core_spec/core/object/is_a_spec.rb +0 -2
- data/core_spec/core/object/shared/kind_of.rb +0 -0
- data/core_spec/core/regexp/shared/match.rb +0 -11
- data/core_spec/language/fixtures/block.rb +0 -19
- data/core_spec/language/fixtures/break.rb +0 -39
- data/core_spec/language/fixtures/defined.rb +0 -9
- data/core_spec/language/fixtures/ensure.rb +0 -37
- data/core_spec/language/fixtures/next.rb +0 -46
- data/core_spec/language/fixtures/send.rb +0 -36
- data/core_spec/language/fixtures/super.rb +0 -43
- data/core_spec/language/regexp_spec.rb +0 -7
- data/core_spec/language/string_spec.rb +0 -4
- data/core_spec/language/super_spec.rb +0 -18
- data/core_spec/language/versions/hash_1.9.rb +0 -20
- data/core_spec/opal/opal/defined_spec.rb +0 -15
- data/core_spec/opal/opal/function_spec.rb +0 -11
- data/core_spec/opal/opal/native_spec.rb +0 -16
- data/core_spec/opal/opal/null_spec.rb +0 -10
- data/core_spec/opal/opal/number_spec.rb +0 -11
- data/core_spec/opal/opal/object_spec.rb +0 -16
- data/core_spec/opal/opal/string_spec.rb +0 -11
- data/core_spec/opal/opal/typeof_spec.rb +0 -9
- data/core_spec/opal/opal/undefined_spec.rb +0 -10
- data/core_spec/opal/true/case_compare_spec.rb +0 -12
- data/core_spec/opal/true/class_spec.rb +0 -10
- data/core_spec/release_runner.html +0 -17
- data/core_spec/runner.html +0 -16
- data/core_spec/spec_helper.rb +0 -23
- data/lib/opal/context.rb +0 -269
- data/lib/opal/dependency_builder.rb +0 -133
- data/lib/opal/environment.rb +0 -87
- data/lib/opal/parser/sexp.rb +0 -17
data/core/enumerator.rb
CHANGED
@@ -77,7 +77,7 @@ class Enumerator
|
|
77
77
|
def each(&block)
|
78
78
|
return self unless block
|
79
79
|
|
80
|
-
@object.__send__ @method,
|
80
|
+
@object.__send__ @method, *@args, &block
|
81
81
|
end
|
82
82
|
|
83
83
|
def each_with_index(&block)
|
@@ -85,7 +85,7 @@ class Enumerator
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def with_index(offset = 0)
|
88
|
-
return
|
88
|
+
return enum_for :with_index, offset unless block_given?
|
89
89
|
|
90
90
|
current = 0
|
91
91
|
|
@@ -99,7 +99,7 @@ class Enumerator
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def with_object(object)
|
102
|
-
return
|
102
|
+
return enum_for :with_object, object unless block_given?
|
103
103
|
|
104
104
|
each {|*args|
|
105
105
|
yield *args, object
|
data/core/hash.rb
CHANGED
@@ -4,19 +4,33 @@ class Hash
|
|
4
4
|
%x{
|
5
5
|
var hash_class = this;
|
6
6
|
|
7
|
-
|
8
|
-
var hash = new hash_class
|
9
|
-
args =
|
10
|
-
assocs = {}
|
11
|
-
key;
|
7
|
+
Opal.hash = function() {
|
8
|
+
var hash = new hash_class._alloc(),
|
9
|
+
args = __slice.call(arguments),
|
10
|
+
assocs = {};
|
12
11
|
|
13
12
|
hash.map = assocs;
|
14
13
|
hash.none = nil;
|
15
14
|
hash.proc = nil;
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
if (args.length == 1 && args[0]._flags & T_ARRAY) {
|
17
|
+
args = args[0];
|
18
|
+
|
19
|
+
for (var i = 0, length = args.length, key; i < length; i++) {
|
20
|
+
key = args[i][0];
|
21
|
+
|
22
|
+
assocs[key] = [key, args[i][1]];
|
23
|
+
}
|
24
|
+
}
|
25
|
+
else if (arguments.length % 2 == 0) {
|
26
|
+
for (var i = 0, length = args.length, key; i < length; i++) {
|
27
|
+
key = args[i];
|
28
|
+
|
29
|
+
assocs[key] = [key, args[++i]];
|
30
|
+
}
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
throw RubyArgError.$new('odd number of arguments for Hash');
|
20
34
|
}
|
21
35
|
|
22
36
|
return hash;
|
@@ -27,14 +41,18 @@ class Hash
|
|
27
41
|
`$opal.hash.apply(null, objs)`
|
28
42
|
end
|
29
43
|
|
44
|
+
def self.allocate
|
45
|
+
`Opal.hash()`
|
46
|
+
end
|
47
|
+
|
30
48
|
def self.new(defaults = undefined, &block)
|
31
49
|
%x{
|
32
|
-
var hash =
|
50
|
+
var hash = Opal.hash();
|
33
51
|
|
34
|
-
if (defaults
|
52
|
+
if (defaults != undefined) {
|
35
53
|
hash.none = defaults;
|
36
54
|
}
|
37
|
-
else if (block
|
55
|
+
else if (block != null) {
|
38
56
|
hash.proc = block;
|
39
57
|
}
|
40
58
|
|
@@ -74,10 +92,9 @@ class Hash
|
|
74
92
|
|
75
93
|
def [](key)
|
76
94
|
%x{
|
77
|
-
var
|
78
|
-
bucket;
|
95
|
+
var bucket;
|
79
96
|
|
80
|
-
if (bucket = this.map[
|
97
|
+
if (bucket = this.map[key]) {
|
81
98
|
return bucket[1];
|
82
99
|
}
|
83
100
|
|
@@ -87,8 +104,7 @@ class Hash
|
|
87
104
|
|
88
105
|
def []=(key, value)
|
89
106
|
%x{
|
90
|
-
|
91
|
-
this.map[hash] = [key, value];
|
107
|
+
this.map[key] = [key, value];
|
92
108
|
|
93
109
|
return value;
|
94
110
|
}
|
@@ -118,7 +134,7 @@ class Hash
|
|
118
134
|
|
119
135
|
def clone
|
120
136
|
%x{
|
121
|
-
var result =
|
137
|
+
var result = Opal.hash(),
|
122
138
|
map = this.map,
|
123
139
|
map2 = result.map;
|
124
140
|
|
@@ -148,14 +164,12 @@ class Hash
|
|
148
164
|
|
149
165
|
def delete(key)
|
150
166
|
%x{
|
151
|
-
var map = this.map,
|
152
|
-
hash = #{key.hash},
|
153
|
-
result;
|
167
|
+
var map = this.map, result;
|
154
168
|
|
155
|
-
if (result = map[
|
169
|
+
if (result = map[key]) {
|
156
170
|
result = bucket[1];
|
157
171
|
|
158
|
-
delete map[
|
172
|
+
delete map[key];
|
159
173
|
}
|
160
174
|
|
161
175
|
return result;
|
@@ -172,11 +186,11 @@ class Hash
|
|
172
186
|
var bucket = map[assoc],
|
173
187
|
value;
|
174
188
|
|
175
|
-
if ((value =
|
189
|
+
if ((value = block.call($context, null, bucket[0], bucket[1])) === $breaker) {
|
176
190
|
return $breaker.$v;
|
177
191
|
}
|
178
192
|
|
179
|
-
if (value !== false && value !==
|
193
|
+
if (value !== false && value !== null) {
|
180
194
|
delete map[assoc];
|
181
195
|
}
|
182
196
|
}
|
@@ -194,7 +208,7 @@ class Hash
|
|
194
208
|
for (var assoc in map) {
|
195
209
|
var bucket = map[assoc];
|
196
210
|
|
197
|
-
if (
|
211
|
+
if (block.call($context, null, bucket[0], bucket[1]) === $breaker) {
|
198
212
|
return $breaker.$v;
|
199
213
|
}
|
200
214
|
}
|
@@ -212,7 +226,7 @@ class Hash
|
|
212
226
|
for (var assoc in map) {
|
213
227
|
var bucket = map[assoc];
|
214
228
|
|
215
|
-
if (
|
229
|
+
if (block.call($context, null, bucket[0]) === $breaker) {
|
216
230
|
return $breaker.$v;
|
217
231
|
}
|
218
232
|
}
|
@@ -232,7 +246,7 @@ class Hash
|
|
232
246
|
for (var assoc in map) {
|
233
247
|
var bucket = map[assoc];
|
234
248
|
|
235
|
-
if (
|
249
|
+
if (block.call($context, null, bucket[1]) === $breaker) {
|
236
250
|
return $breaker.$v;
|
237
251
|
}
|
238
252
|
}
|
@@ -255,12 +269,12 @@ class Hash
|
|
255
269
|
|
256
270
|
def fetch(key, defaults = undefined, &block)
|
257
271
|
%x{
|
258
|
-
var bucket = this.map[
|
272
|
+
var bucket = this.map[key];
|
259
273
|
|
260
|
-
if (block !==
|
274
|
+
if (block !== null) {
|
261
275
|
var value;
|
262
276
|
|
263
|
-
if ((value =
|
277
|
+
if ((value = block.call($context, null, key)) === $breaker) {
|
264
278
|
return $breaker.$v;
|
265
279
|
}
|
266
280
|
|
@@ -271,7 +285,7 @@ class Hash
|
|
271
285
|
return defaults;
|
272
286
|
}
|
273
287
|
|
274
|
-
|
288
|
+
throw RubyKeyError.$new('key not found');
|
275
289
|
}
|
276
290
|
end
|
277
291
|
|
@@ -287,7 +301,7 @@ class Hash
|
|
287
301
|
|
288
302
|
result.push(key);
|
289
303
|
|
290
|
-
if (value
|
304
|
+
if (value._flags & T_ARRAY) {
|
291
305
|
if (level === undefined || level === 1) {
|
292
306
|
result.push(value);
|
293
307
|
}
|
@@ -305,7 +319,7 @@ class Hash
|
|
305
319
|
end
|
306
320
|
|
307
321
|
def has_key?(key)
|
308
|
-
`!!this.map[
|
322
|
+
`!!this.map[key]`
|
309
323
|
end
|
310
324
|
|
311
325
|
def has_value?(value)
|
@@ -321,7 +335,7 @@ class Hash
|
|
321
335
|
end
|
322
336
|
|
323
337
|
def hash
|
324
|
-
`this
|
338
|
+
`this._id`
|
325
339
|
end
|
326
340
|
|
327
341
|
def inspect
|
@@ -347,7 +361,7 @@ class Hash
|
|
347
361
|
for (var assoc in map) {
|
348
362
|
var bucket = map[assoc];
|
349
363
|
|
350
|
-
map2[
|
364
|
+
map2[bucket[1]] = [bucket[0], bucket[1]];
|
351
365
|
}
|
352
366
|
|
353
367
|
return result;
|
@@ -364,7 +378,7 @@ class Hash
|
|
364
378
|
}
|
365
379
|
}
|
366
380
|
|
367
|
-
return
|
381
|
+
return null;
|
368
382
|
}
|
369
383
|
end
|
370
384
|
|
@@ -396,9 +410,9 @@ class Hash
|
|
396
410
|
|
397
411
|
alias member? has_key?
|
398
412
|
|
399
|
-
def merge(other)
|
413
|
+
def merge(other, &block)
|
400
414
|
%x{
|
401
|
-
var result =
|
415
|
+
var result = Opal.hash(),
|
402
416
|
map = this.map,
|
403
417
|
map2 = result.map;
|
404
418
|
|
@@ -410,25 +424,51 @@ class Hash
|
|
410
424
|
|
411
425
|
map = other.map;
|
412
426
|
|
413
|
-
|
414
|
-
var
|
427
|
+
if (block === null) {
|
428
|
+
for (var assoc in map) {
|
429
|
+
var bucket = map[assoc];
|
415
430
|
|
416
|
-
|
431
|
+
map2[assoc] = [bucket[0], bucket[1]];
|
432
|
+
}
|
433
|
+
}
|
434
|
+
else {
|
435
|
+
for (var assoc in map) {
|
436
|
+
var bucket = map[assoc], key = bucket[0], val = bucket[1];
|
437
|
+
|
438
|
+
if (map2.hasOwnProperty(assoc)) {
|
439
|
+
val = block.call(__context, key, map2[assoc][1], val);
|
440
|
+
}
|
441
|
+
|
442
|
+
map2[assoc] = [key, val];
|
443
|
+
}
|
417
444
|
}
|
418
445
|
|
419
446
|
return result;
|
420
447
|
}
|
421
448
|
end
|
422
449
|
|
423
|
-
def merge!(other)
|
450
|
+
def merge!(other, &block)
|
424
451
|
%x{
|
425
452
|
var map = this.map,
|
426
453
|
map2 = other.map;
|
427
454
|
|
428
|
-
|
429
|
-
var
|
455
|
+
if (block === null) {
|
456
|
+
for (var assoc in map2) {
|
457
|
+
var bucket = map2[assoc];
|
430
458
|
|
431
|
-
|
459
|
+
map[assoc] = [bucket[0], bucket[1]];
|
460
|
+
}
|
461
|
+
}
|
462
|
+
else {
|
463
|
+
for (var assoc in map2) {
|
464
|
+
var bucket = map2[assoc], key = bucket[0], val = bucket[1];
|
465
|
+
|
466
|
+
if (map.hasOwnProperty(assoc)) {
|
467
|
+
val = block.call($context, null, key, map[assoc][1], val);
|
468
|
+
}
|
469
|
+
|
470
|
+
map[assoc] = [key, val];
|
471
|
+
}
|
432
472
|
}
|
433
473
|
|
434
474
|
return this;
|
@@ -447,7 +487,7 @@ class Hash
|
|
447
487
|
}
|
448
488
|
}
|
449
489
|
|
450
|
-
return
|
490
|
+
return null;
|
451
491
|
}
|
452
492
|
end
|
453
493
|
|
data/core/kernel.rb
CHANGED
@@ -31,8 +31,8 @@ module Kernel
|
|
31
31
|
|
32
32
|
def at_exit(&block)
|
33
33
|
%x{
|
34
|
-
if (block ===
|
35
|
-
|
34
|
+
if (block === null) {
|
35
|
+
throw RubyArgError.$new('called without a block');
|
36
36
|
}
|
37
37
|
|
38
38
|
end_procs.push(block);
|
@@ -42,16 +42,16 @@ module Kernel
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def class
|
45
|
-
`class_real(this
|
45
|
+
`class_real(this._klass)`
|
46
46
|
end
|
47
47
|
|
48
|
-
def define_singleton_method(&body)
|
48
|
+
def define_singleton_method(name, &body)
|
49
49
|
%x{
|
50
|
-
if (body ===
|
51
|
-
|
50
|
+
if (body === null) {
|
51
|
+
throw RubyLocalJumpError.$new('no block given');
|
52
52
|
}
|
53
53
|
|
54
|
-
|
54
|
+
opal.defs(this, mid_to_jsid(name), body);
|
55
55
|
|
56
56
|
return this;
|
57
57
|
}
|
@@ -71,8 +71,12 @@ module Kernel
|
|
71
71
|
}
|
72
72
|
end
|
73
73
|
|
74
|
+
def format(string, *arguments)
|
75
|
+
raise NotImplementedError
|
76
|
+
end
|
77
|
+
|
74
78
|
def hash
|
75
|
-
`this
|
79
|
+
`this._id`
|
76
80
|
end
|
77
81
|
|
78
82
|
def inspect
|
@@ -80,7 +84,7 @@ module Kernel
|
|
80
84
|
end
|
81
85
|
|
82
86
|
def instance_of?(klass)
|
83
|
-
`this
|
87
|
+
`this._klass === klass`
|
84
88
|
end
|
85
89
|
|
86
90
|
def instance_variable_defined?(name)
|
@@ -91,7 +95,7 @@ module Kernel
|
|
91
95
|
%x{
|
92
96
|
var ivar = this[name.substr(1)];
|
93
97
|
|
94
|
-
return ivar == undefined ?
|
98
|
+
return ivar == undefined ? null : ivar;
|
95
99
|
}
|
96
100
|
end
|
97
101
|
|
@@ -113,14 +117,14 @@ module Kernel
|
|
113
117
|
|
114
118
|
def is_a?(klass)
|
115
119
|
%x{
|
116
|
-
var search = this
|
120
|
+
var search = this._klass;
|
117
121
|
|
118
122
|
while (search) {
|
119
123
|
if (search === klass) {
|
120
124
|
return true;
|
121
125
|
}
|
122
126
|
|
123
|
-
search = search
|
127
|
+
search = search._super;
|
124
128
|
}
|
125
129
|
|
126
130
|
return false;
|
@@ -138,7 +142,7 @@ module Kernel
|
|
138
142
|
|
139
143
|
%x{
|
140
144
|
while (true) {
|
141
|
-
if (
|
145
|
+
if (block.call(__context) === breaker) {
|
142
146
|
return breaker.$v;
|
143
147
|
}
|
144
148
|
}
|
@@ -152,14 +156,15 @@ module Kernel
|
|
152
156
|
end
|
153
157
|
|
154
158
|
def object_id
|
155
|
-
`this
|
159
|
+
`this._id || (this._id = unique_id++)`
|
156
160
|
end
|
157
161
|
|
158
162
|
def print(*strs)
|
159
|
-
|
163
|
+
puts *strs
|
160
164
|
end
|
161
165
|
|
162
166
|
def private(*)
|
167
|
+
# does nothing. here for documenting code
|
163
168
|
end
|
164
169
|
|
165
170
|
def proc(&block)
|
@@ -167,15 +172,24 @@ module Kernel
|
|
167
172
|
end
|
168
173
|
|
169
174
|
def protected(*)
|
175
|
+
# does nothing. here for documenting code
|
170
176
|
end
|
171
177
|
|
172
178
|
def public(*)
|
179
|
+
# does nothing. here for documenting code
|
173
180
|
end
|
174
181
|
|
175
182
|
def puts(*strs)
|
176
|
-
|
183
|
+
%x{
|
184
|
+
for (var i = 0; i < strs.length; i++) {
|
185
|
+
var obj = strs[i];
|
186
|
+
console.log(obj == null ? "nil" : obj.$to_s());
|
187
|
+
}
|
188
|
+
}
|
177
189
|
end
|
178
190
|
|
191
|
+
alias sprintf format
|
192
|
+
|
179
193
|
def raise(exception, string = undefined)
|
180
194
|
%x{
|
181
195
|
if (typeof(exception) === 'string') {
|
@@ -194,42 +208,44 @@ module Kernel
|
|
194
208
|
end
|
195
209
|
|
196
210
|
def require(path)
|
211
|
+
`require_handler(path);`
|
212
|
+
end
|
213
|
+
|
214
|
+
def respond_to?(name)
|
215
|
+
`!!this[mid_to_jsid(name)]`
|
216
|
+
end
|
217
|
+
|
218
|
+
def singleton_class
|
197
219
|
%x{
|
198
|
-
var
|
220
|
+
var obj = this, klass;
|
199
221
|
|
200
|
-
if (
|
201
|
-
|
222
|
+
if (obj._flags & T_OBJECT) {
|
223
|
+
if ((obj._flags & T_NUMBER) || (obj._flags & T_STRING)) {
|
224
|
+
throw RubyTypeError.$new("can't define singleton");
|
225
|
+
}
|
202
226
|
}
|
203
227
|
|
204
|
-
if (
|
205
|
-
|
228
|
+
if ((obj._klass._flags & FL_SINGLETON) && obj._klass.__attached__ == obj) {
|
229
|
+
klass = obj._klass;
|
206
230
|
}
|
231
|
+
else {
|
232
|
+
var class_id = obj._klass._name;
|
207
233
|
|
208
|
-
|
209
|
-
|
210
|
-
$opal.FILE = resolved;
|
211
|
-
FACTORIES[resolved]();
|
234
|
+
klass = make_metaclass(obj, obj._klass);
|
235
|
+
}
|
212
236
|
|
213
|
-
return
|
237
|
+
return klass;
|
214
238
|
}
|
215
239
|
end
|
216
240
|
|
217
|
-
def respond_to?(name)
|
218
|
-
`!!this[mid_to_jsid(name)]`
|
219
|
-
end
|
220
|
-
|
221
|
-
def singleton_class
|
222
|
-
`singleton_class(this)`
|
223
|
-
end
|
224
|
-
|
225
241
|
def tap(&block)
|
226
242
|
%x{
|
227
|
-
if (block ===
|
228
|
-
|
243
|
+
if (block === null) {
|
244
|
+
throw RubyLocalJumpError.$new('no block given');
|
229
245
|
}
|
230
246
|
|
231
|
-
if (
|
232
|
-
return
|
247
|
+
if (block.call(__context, this) === __breaker) {
|
248
|
+
return __breaker.$v;
|
233
249
|
}
|
234
250
|
|
235
251
|
return this;
|
@@ -237,6 +253,6 @@ module Kernel
|
|
237
253
|
end
|
238
254
|
|
239
255
|
def to_s
|
240
|
-
`return "#<" + class_real(this
|
256
|
+
`return "#<" + class_real(this._klass)._name + ":0x" + (this._id * 400487).toString(16) + ">";`
|
241
257
|
end
|
242
258
|
end
|