opal 0.3.21 → 0.3.22
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/.travis.yml +1 -4
- data/Gemfile +9 -4
- data/README.md +10 -589
- data/Rakefile +51 -19
- data/config.ru +17 -0
- data/core/array.rb +42 -34
- data/core/basic_object.rb +4 -4
- data/core/browser.js +31 -0
- data/core/class.rb +7 -7
- data/core/enumerable.rb +65 -69
- data/core/erb.rb +30 -0
- data/core/error.rb +2 -3
- data/core/hash.rb +47 -18
- data/core/kernel.rb +15 -16
- data/core/load_order +2 -1
- data/core/module.rb +19 -37
- data/core/numeric.rb +4 -2
- data/core/object.rb +4 -0
- data/core/proc.rb +6 -3
- data/core/racc.rb +215 -0
- data/core/regexp.rb +16 -21
- data/core/runtime.js +141 -153
- data/core/string.rb +41 -19
- data/core/strscan.rb +61 -0
- data/core/time.rb +1 -5
- data/docs/index.md +616 -0
- data/docs/post.html +2 -8
- data/docs/pre.html +29 -26
- data/docs/try.html +52 -0
- data/lib/opal.rb +33 -3
- data/lib/opal/builder.rb +14 -34
- data/lib/opal/erb_parser.rb +19 -0
- data/lib/opal/grammar.rb +7 -3
- data/lib/opal/grammar.y +3 -0
- data/lib/opal/lexer.rb +16 -8
- data/lib/opal/parser.rb +156 -119
- data/lib/opal/rake_task.rb +2 -2
- data/lib/opal/scope.rb +9 -10
- data/lib/opal/version.rb +1 -1
- data/{test → spec}/core/array/allocate_spec.rb +0 -0
- data/{test → spec}/core/array/append_spec.rb +0 -0
- data/{test → spec}/core/array/assoc_spec.rb +0 -0
- data/{test → spec}/core/array/at_spec.rb +0 -0
- data/{test → spec}/core/array/clear_spec.rb +0 -0
- data/{test → spec}/core/array/clone_spec.rb +0 -0
- data/{test → spec}/core/array/collect_spec.rb +0 -0
- data/{test → spec}/core/array/compact_spec.rb +0 -0
- data/{test → spec}/core/array/concat_spec.rb +0 -0
- data/{test → spec}/core/array/constructor_spec.rb +0 -0
- data/{test → spec}/core/array/count_spec.rb +0 -0
- data/{test → spec}/core/array/delete_at_spec.rb +0 -0
- data/{test → spec}/core/array/delete_if_spec.rb +0 -0
- data/{test → spec}/core/array/delete_spec.rb +0 -0
- data/{test → spec}/core/array/each_index_spec.rb +0 -0
- data/{test → spec}/core/array/each_spec.rb +0 -0
- data/{test → spec}/core/array/element_reference_spec.rb +0 -0
- data/{test → spec}/core/array/empty_spec.rb +0 -0
- data/{test → spec}/core/array/eql_spec.rb +0 -0
- data/{test → spec}/core/array/fetch_spec.rb +0 -0
- data/{test → spec}/core/array/first_spec.rb +0 -0
- data/{test → spec}/core/array/flatten_spec.rb +0 -0
- data/{test → spec}/core/array/include_spec.rb +0 -0
- data/{test → spec}/core/array/insert_spec.rb +0 -0
- data/{test → spec}/core/array/last_spec.rb +0 -0
- data/{test → spec}/core/array/length_spec.rb +0 -0
- data/{test → spec}/core/array/map_spec.rb +0 -0
- data/{test → spec}/core/array/minus_spec.rb +0 -0
- data/{test → spec}/core/array/plus_spec.rb +0 -0
- data/{test → spec}/core/array/pop_spec.rb +0 -0
- data/{test → spec}/core/array/push_spec.rb +0 -0
- data/{test → spec}/core/array/rassoc_spec.rb +0 -0
- data/{test → spec}/core/array/reject_spec.rb +0 -0
- data/{test → spec}/core/array/replace_spec.rb +0 -0
- data/{test → spec}/core/array/reverse_each_spec.rb +0 -0
- data/{test → spec}/core/array/reverse_spec.rb +0 -0
- data/{test → spec}/core/array/size_spec.rb +0 -0
- data/{test → spec}/core/array/to_ary_spec.rb +0 -0
- data/{test → spec}/core/array/uniq_spec.rb +0 -0
- data/{test → spec}/core/array/zip_spec.rb +0 -0
- data/{test → spec}/core/class/fixtures/classes.rb +0 -0
- data/{test → spec}/core/class/new_spec.rb +3 -0
- data/{test → spec}/core/enumerable/all_spec.rb +3 -0
- data/{test → spec}/core/enumerable/any_spec.rb +0 -0
- data/{test → spec}/core/enumerable/collect_spec.rb +0 -0
- data/{test → spec}/core/enumerable/count_spec.rb +0 -0
- data/{test → spec}/core/enumerable/detect_spec.rb +0 -0
- data/{test → spec}/core/enumerable/drop_spec.rb +0 -0
- data/{test → spec}/core/enumerable/drop_while_spec.rb +0 -0
- data/{test → spec}/core/enumerable/each_with_index_spec.rb +0 -0
- data/{test → spec}/core/enumerable/each_with_object_spec.rb +0 -0
- data/{test → spec}/core/enumerable/entries_spec.rb +0 -0
- data/{test → spec}/core/enumerable/find_all_spec.rb +0 -0
- data/{test → spec}/core/enumerable/find_index_spec.rb +0 -0
- data/{test → spec}/core/enumerable/find_spec.rb +0 -0
- data/{test → spec}/core/enumerable/first_spec.rb +0 -0
- data/{test → spec}/core/enumerable/fixtures/classes.rb +0 -0
- data/{test → spec}/core/enumerable/grep_spec.rb +0 -0
- data/{test → spec}/core/enumerable/take_spec.rb +0 -0
- data/{test → spec}/core/enumerable/to_a_spec.rb +0 -0
- data/{test → spec}/core/false/and_spec.rb +0 -0
- data/{test → spec}/core/false/inspect_spec.rb +0 -0
- data/{test → spec}/core/false/or_spec.rb +0 -0
- data/{test → spec}/core/false/to_s_spec.rb +0 -0
- data/{test → spec}/core/false/xor_spec.rb +0 -0
- data/{test → spec}/core/hash/allocate_spec.rb +0 -0
- data/{test → spec}/core/hash/assoc_spec.rb +0 -0
- data/{test → spec}/core/hash/clear_spec.rb +0 -0
- data/{test → spec}/core/hash/clone_spec.rb +0 -0
- data/{test → spec}/core/hash/default_spec.rb +0 -0
- data/{test → spec}/core/hash/delete_if_spec.rb +0 -0
- data/{test → spec}/core/hash/each_key_spec.rb +0 -0
- data/{test → spec}/core/hash/each_pair_spec.rb +0 -0
- data/{test → spec}/core/hash/each_spec.rb +0 -0
- data/{test → spec}/core/hash/each_value_spec.rb +0 -0
- data/{test → spec}/core/hash/element_reference_spec.rb +14 -1
- data/{test → spec}/core/hash/element_set_spec.rb +0 -0
- data/{test → spec}/core/hash/empty_spec.rb +0 -0
- data/{test → spec}/core/hash/fetch_spec.rb +0 -0
- data/{test → spec}/core/hash/flatten_spec.rb +0 -0
- data/{test → spec}/core/hash/has_key_spec.rb +0 -0
- data/{test → spec}/core/hash/has_value_spec.rb +0 -0
- data/{test → spec}/core/hash/include_spec.rb +0 -0
- data/{test → spec}/core/hash/index_spec.rb +0 -0
- data/{test → spec}/core/hash/indexes_spec.rb +0 -0
- data/{test → spec}/core/hash/indices_spec.rb +0 -0
- data/{test → spec}/core/hash/invert_spec.rb +0 -0
- data/{test → spec}/core/hash/keep_if_spec.rb +0 -0
- data/{test → spec}/core/hash/key_spec.rb +0 -0
- data/{test → spec}/core/hash/keys_spec.rb +0 -0
- data/{test → spec}/core/hash/length_spec.rb +0 -0
- data/{test → spec}/core/hash/member_spec.rb +0 -0
- data/{test → spec}/core/hash/merge_spec.rb +0 -0
- data/{test → spec}/core/hash/new_spec.rb +8 -0
- data/{test → spec}/core/hash/rassoc_spec.rb +0 -0
- data/{test → spec}/core/hash/replace_spec.rb +0 -0
- data/{test → spec}/core/hash/select_spec.rb +0 -0
- data/{test → spec}/core/hash/shift_spec.rb +0 -0
- data/{test → spec}/core/hash/size_spec.rb +0 -0
- data/{test → spec}/core/hash/update_spec.rb +0 -0
- data/{test → spec}/core/hash/value_spec.rb +0 -0
- data/{test → spec}/core/hash/values_at_spec.rb +0 -0
- data/{test → spec}/core/hash/values_spec.rb +0 -0
- data/{test → spec}/core/kernel/define_singleton_method_spec.rb +0 -0
- data/{test → spec}/core/kernel/eql_spec.rb +0 -0
- data/{test → spec}/core/kernel/equal_value_spec.rb +0 -0
- data/{test → spec}/core/kernel/loop_spec.rb +0 -0
- data/{test → spec}/core/kernel/nil_spec.rb +0 -0
- data/{test → spec}/core/kernel/proc_spec.rb +4 -0
- data/{test → spec}/core/kernel/rand_spec.rb +0 -0
- data/{test → spec}/core/kernel/respond_to_spec.rb +0 -0
- data/{test → spec}/core/kernel/send_spec.rb +0 -0
- data/{test → spec}/core/kernel/tap_spec.rb +0 -0
- data/{test → spec}/core/kernel/to_s_spec.rb +0 -0
- data/{test → spec}/core/matchdata/to_a_spec.rb +0 -0
- data/{test → spec}/core/nil/and_spec.rb +0 -0
- data/{test → spec}/core/nil/inspect_spec.rb +0 -0
- data/{test → spec}/core/nil/nil_spec.rb +0 -0
- data/{test → spec}/core/nil/or_spec.rb +0 -0
- data/{test → spec}/core/nil/to_a_spec.rb +0 -0
- data/{test → spec}/core/nil/to_f_spec.rb +0 -0
- data/{test → spec}/core/nil/to_i_spec.rb +0 -0
- data/{test → spec}/core/nil/to_s_spec.rb +0 -0
- data/{test → spec}/core/nil/xor_spec.rb +0 -0
- data/{test → spec}/core/numeric/equal_value_spec.rb +0 -0
- data/spec/core/proc/proc_tricks_spec.rb +7 -0
- data/{test → spec}/core/range/begin_spec.rb +0 -0
- data/{test → spec}/core/range/case_compare_spec.rb +0 -0
- data/{test → spec}/core/range/end_spec.rb +0 -0
- data/{test → spec}/core/regexp/match_spec.rb +0 -0
- data/{test → spec}/core/string/capitalize_spec.rb +0 -0
- data/{test → spec}/core/string/casecmp_spec.rb +0 -0
- data/{test → spec}/core/string/chomp_spec.rb +0 -0
- data/{test → spec}/core/string/chop_spec.rb +0 -0
- data/{test → spec}/core/string/chr_spec.rb +0 -0
- data/{test → spec}/core/string/comparison_spec.rb +0 -0
- data/{test → spec}/core/string/downcase_spec.rb +0 -0
- data/{test → spec}/core/string/element_reference_spec.rb +14 -2
- data/{test → spec}/core/string/empty_spec.rb +0 -0
- data/{test → spec}/core/string/end_with_spec.rb +0 -0
- data/{test → spec}/core/string/fixtures/classes.rb +0 -0
- data/{test → spec}/core/string/gsub_spec.rb +0 -0
- data/{test → spec}/core/string/include_spec.rb +0 -0
- data/{test → spec}/core/string/intern_spec.rb +0 -0
- data/{test → spec}/core/string/length_spec.rb +0 -0
- data/{test → spec}/core/string/lstrip_spec.rb +0 -0
- data/{test → spec}/core/string/match_spec.rb +0 -0
- data/{test → spec}/core/string/next_spec.rb +0 -0
- data/{test → spec}/core/string/ord_spec.rb +0 -0
- data/{test → spec}/core/string/partition_spec.rb +0 -0
- data/{test → spec}/core/string/reverse_spec.rb +0 -0
- data/{test → spec}/core/string/rstrip_spec.rb +0 -0
- data/{test → spec}/core/string/size_spec.rb +0 -0
- data/{test → spec}/core/string/slice_spec.rb +4 -1
- data/{test → spec}/core/string/split_spec.rb +0 -0
- data/{test → spec}/core/string/start_with_spec.rb +0 -0
- data/{test → spec}/core/string/strip_spec.rb +0 -0
- data/{test → spec}/core/string/sub_spec.rb +0 -0
- data/{test → spec}/core/string/succ_spec.rb +0 -0
- data/{test → spec}/core/string/sum_spec.rb +0 -0
- data/{test → spec}/core/string/swapcase_spec.rb +0 -0
- data/{test → spec}/core/string/to_a_spec.rb +0 -0
- data/{test → spec}/core/string/to_f_spec.rb +0 -0
- data/{test → spec}/core/string/to_i_spec.rb +0 -0
- data/{test → spec}/core/string/to_s_spec.rb +0 -0
- data/{test → spec}/core/string/to_str_spec.rb +0 -0
- data/{test → spec}/core/string/to_sym_spec.rb +0 -0
- data/{test → spec}/core/string/upcase_spec.rb +0 -0
- data/{test → spec}/core/symbol/to_proc_spec.rb +0 -0
- data/{test → spec}/core/time/at_spec.rb +0 -0
- data/{test → spec}/core/time/day_spec.rb +0 -0
- data/{test → spec}/core/time/friday_spec.rb +0 -0
- data/{test → spec}/core/time/hour_spec.rb +0 -0
- data/{test → spec}/core/time/min_spec.rb +0 -0
- data/{test → spec}/core/time/monday_spec.rb +0 -0
- data/{test → spec}/core/time/month_spec.rb +0 -0
- data/{test → spec}/core/time/now_spec.rb +0 -0
- data/{test → spec}/core/time/saturday_spec.rb +0 -0
- data/{test → spec}/core/true/and_spec.rb +0 -0
- data/{test → spec}/core/true/inspect_spec.rb +0 -0
- data/{test → spec}/core/true/or_spec.rb +0 -0
- data/{test → spec}/core/true/to_s_spec.rb +0 -0
- data/{test → spec}/core/true/xor_spec.rb +0 -0
- data/spec/grammar/lvar_spec.rb +2 -1
- data/spec/grammar/str_spec.rb +1 -1
- data/spec/grammar/xstr_spec.rb +1 -1
- data/{test → spec}/index.html +3 -3
- data/{test → spec}/language/alias_spec.rb +0 -0
- data/{test → spec}/language/and_spec.rb +0 -0
- data/{test → spec}/language/array_spec.rb +0 -0
- data/{test → spec}/language/block_spec.rb +0 -0
- data/{test → spec}/language/break_spec.rb +0 -0
- data/{test → spec}/language/case_spec.rb +0 -0
- data/{test → spec}/language/defined_spec.rb +0 -0
- data/{test → spec}/language/ensure_spec.rb +2 -2
- data/{test → spec}/language/fixtures/next.rb +0 -0
- data/{test → spec}/language/fixtures/yield.rb +0 -0
- data/{test → spec}/language/hash_spec.rb +0 -0
- data/{test → spec}/language/if_spec.rb +0 -0
- data/{test → spec}/language/literal_lambda_spec.rb +0 -0
- data/{test → spec}/language/loop_spec.rb +0 -0
- data/{test → spec}/language/metaclass_spec.rb +0 -0
- data/{test → spec}/language/next_spec.rb +2 -0
- data/{test → spec}/language/or_spec.rb +0 -0
- data/{test → spec}/language/predefined_spec.rb +0 -0
- data/{test → spec}/language/regexp_spec.rb +0 -0
- data/{test → spec}/language/send_spec.rb +0 -0
- data/{test → spec}/language/singleton_class_spec.rb +0 -0
- data/{test → spec}/language/super_spec.rb +0 -0
- data/{test → spec}/language/symbol_spec.rb +0 -0
- data/{test → spec}/language/undef_spec.rb +0 -0
- data/{test → spec}/language/unless_spec.rb +0 -0
- data/{test → spec}/language/until_spec.rb +0 -0
- data/{test → spec}/language/variables_spec.rb +0 -0
- data/{test → spec}/language/while_spec.rb +0 -0
- data/{test → spec}/language/yield_spec.rb +2 -0
- data/{test → spec}/opal/array/subclassing_spec.rb +0 -0
- data/{test → spec}/opal/array/to_json_spec.rb +0 -0
- data/{test → spec}/opal/boolean/singleton_class_spec.rb +0 -0
- data/{test → spec}/opal/boolean/to_json_spec.rb +0 -0
- data/{test → spec}/opal/class/bridge_class_spec.rb +0 -0
- data/spec/opal/erb/erb_spec.rb +15 -0
- data/{test → spec}/opal/exception/subclassing_spec.rb +0 -0
- data/{test → spec}/opal/hash/to_json_spec.rb +0 -0
- data/spec/opal/hash/to_native_spec.rb +5 -0
- data/{test → spec}/opal/json/parse_spec.rb +0 -0
- data/{test → spec}/opal/kernel/to_json_spec.rb +0 -0
- data/{test → spec}/opal/nil/to_json_spec.rb +0 -0
- data/{test → spec}/opal/numeric/to_json_spec.rb +0 -0
- data/{test → spec}/opal/runtime/call_spec.rb +0 -0
- data/{test → spec}/opal/runtime/class_hierarchy_spec.rb +0 -0
- data/{test → spec}/opal/runtime/def_spec.rb +0 -0
- data/{test → spec}/opal/runtime/defined_spec.rb +0 -0
- data/{test → spec}/opal/runtime/method_missing_spec.rb +3 -3
- data/{test → spec}/opal/runtime/super_spec.rb +0 -0
- data/{test → spec}/opal/string/subclassing_spec.rb +0 -0
- data/{test → spec}/opal/string/to_json_spec.rb +0 -0
- data/spec/opal/strscan/check_spec.rb +13 -0
- data/spec/opal/strscan/scan_spec.rb +33 -0
- data/spec/parser/simple_spec.rb +44 -0
- data/spec/spec_helper.rb +7 -7
- metadata +487 -497
- data/core/dir.rb +0 -89
- data/core/file.rb +0 -85
- data/spec/browser_spec.rb +0 -28
- data/spec/builder/fixtures/build_source/adam.rb +0 -0
- data/spec/builder/fixtures/build_source/bar/a.rb +0 -0
- data/spec/builder/fixtures/build_source/bar/wow/b.rb +0 -0
- data/spec/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
- data/spec/builder/fixtures/build_source/beynon.rb +0 -0
- data/spec/builder/fixtures/build_source/charles.js +0 -0
- data/spec/builder/fixtures/build_source/foo/a.rb +0 -0
- data/spec/builder/fixtures/build_source/foo/b.rb +0 -0
- data/spec/builder/fixtures/build_source/foo/x.js +0 -0
- data/spec/builder/fixtures/build_source/foo/y.js +0 -0
- data/spec/builder/lib_name_for_spec.rb +0 -19
- data/test/index.min.html +0 -12
- data/test/spec_helper.rb +0 -4
data/core/erb.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# A really small ERB implementation for Opal.
|
2
|
+
class ERB
|
3
|
+
|
4
|
+
# @private Stores all registered instances
|
5
|
+
@templates = {}
|
6
|
+
def self.[]=(name, instance)
|
7
|
+
@templates[name] = instance
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.[](name)
|
11
|
+
@templates[name]
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(name, &body)
|
15
|
+
ERB[name] = self
|
16
|
+
@body = body
|
17
|
+
end
|
18
|
+
|
19
|
+
# Run this erb template against the given context. Unlike ERB, opals
|
20
|
+
# implementation uses a normal object as a context.
|
21
|
+
#
|
22
|
+
# view = UserView.new
|
23
|
+
# ERB[:user_view].result(view)
|
24
|
+
#
|
25
|
+
# @param [Object] context
|
26
|
+
# @result [String]
|
27
|
+
def result(context)
|
28
|
+
context.instance_eval &@body
|
29
|
+
end
|
30
|
+
end
|
data/core/error.rb
CHANGED
data/core/hash.rb
CHANGED
@@ -8,8 +8,6 @@ class Hash
|
|
8
8
|
assocs = {};
|
9
9
|
|
10
10
|
hash.map = assocs;
|
11
|
-
hash.none = nil;
|
12
|
-
hash.proc = nil;
|
13
11
|
|
14
12
|
for (var i = 0, length = args.length, key; i < length; i++) {
|
15
13
|
key = args[i];
|
@@ -28,6 +26,18 @@ class Hash
|
|
28
26
|
`__hash()`
|
29
27
|
end
|
30
28
|
|
29
|
+
def self.from_native(obj)
|
30
|
+
%x{
|
31
|
+
var hash = __hash(), map = hash.map;
|
32
|
+
|
33
|
+
for (var key in obj) {
|
34
|
+
map[key] = [key, obj[key]]
|
35
|
+
}
|
36
|
+
|
37
|
+
return hash;
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
31
41
|
def self.new(defaults, &block)
|
32
42
|
%x{
|
33
43
|
var hash = __hash();
|
@@ -81,7 +91,13 @@ class Hash
|
|
81
91
|
return bucket[1];
|
82
92
|
}
|
83
93
|
|
84
|
-
|
94
|
+
var proc = #{@proc};
|
95
|
+
|
96
|
+
if (proc !== nil) {
|
97
|
+
return #{ `proc`.call self, key };
|
98
|
+
}
|
99
|
+
|
100
|
+
return #{@none};
|
85
101
|
}
|
86
102
|
end
|
87
103
|
|
@@ -130,19 +146,19 @@ class Hash
|
|
130
146
|
end
|
131
147
|
|
132
148
|
def default
|
133
|
-
|
149
|
+
@none
|
134
150
|
end
|
135
151
|
|
136
152
|
def default=(object)
|
137
|
-
|
153
|
+
@none = object
|
138
154
|
end
|
139
155
|
|
140
156
|
def default_proc
|
141
|
-
|
157
|
+
@proc
|
142
158
|
end
|
143
159
|
|
144
160
|
def default_proc=(proc)
|
145
|
-
|
161
|
+
@proc = proc
|
146
162
|
end
|
147
163
|
|
148
164
|
def delete(key)
|
@@ -169,7 +185,7 @@ class Hash
|
|
169
185
|
var bucket = map[assoc],
|
170
186
|
value;
|
171
187
|
|
172
|
-
if ((value = block(__context, bucket[0], bucket[1])) === __breaker) {
|
188
|
+
if ((value = block.call(__context, bucket[0], bucket[1])) === __breaker) {
|
173
189
|
return __breaker.$v;
|
174
190
|
}
|
175
191
|
|
@@ -193,7 +209,7 @@ class Hash
|
|
193
209
|
for (var assoc in map) {
|
194
210
|
var bucket = map[assoc];
|
195
211
|
|
196
|
-
if (block(__context, bucket[0], bucket[1]) === __breaker) {
|
212
|
+
if (block.call(__context, bucket[0], bucket[1]) === __breaker) {
|
197
213
|
return __breaker.$v;
|
198
214
|
}
|
199
215
|
}
|
@@ -211,7 +227,7 @@ class Hash
|
|
211
227
|
for (var assoc in map) {
|
212
228
|
var bucket = map[assoc];
|
213
229
|
|
214
|
-
if (block(__context, bucket[0]) === __breaker) {
|
230
|
+
if (block.call(__context, bucket[0]) === __breaker) {
|
215
231
|
return __breaker.$v;
|
216
232
|
}
|
217
233
|
}
|
@@ -231,7 +247,7 @@ class Hash
|
|
231
247
|
for (var assoc in map) {
|
232
248
|
var bucket = map[assoc];
|
233
249
|
|
234
|
-
if (block(__context, bucket[1]) === __breaker) {
|
250
|
+
if (block.call(__context, bucket[1]) === __breaker) {
|
235
251
|
return __breaker.$v;
|
236
252
|
}
|
237
253
|
}
|
@@ -263,7 +279,7 @@ class Hash
|
|
263
279
|
if (block !== nil) {
|
264
280
|
var value;
|
265
281
|
|
266
|
-
if ((value = block(__context, key)) === __breaker) {
|
282
|
+
if ((value = block.call(__context, key)) === __breaker) {
|
267
283
|
return __breaker.$v;
|
268
284
|
}
|
269
285
|
|
@@ -403,7 +419,7 @@ class Hash
|
|
403
419
|
for (var assoc in map) {
|
404
420
|
var bucket = map[assoc];
|
405
421
|
|
406
|
-
if ((value = block(__context, bucket[0], bucket[1])) === __breaker) {
|
422
|
+
if ((value = block.call(__context, bucket[0], bucket[1])) === __breaker) {
|
407
423
|
return __breaker.$v;
|
408
424
|
}
|
409
425
|
|
@@ -472,7 +488,7 @@ class Hash
|
|
472
488
|
var bucket = map[assoc], key = bucket[0], val = bucket[1];
|
473
489
|
|
474
490
|
if (__hasOwn.call(map2, assoc)) {
|
475
|
-
val = block(__context, key, map2[assoc][1], val);
|
491
|
+
val = block.call(__context, key, map2[assoc][1], val);
|
476
492
|
}
|
477
493
|
|
478
494
|
map2[assoc] = [key, val];
|
@@ -500,7 +516,7 @@ class Hash
|
|
500
516
|
var bucket = map2[assoc], key = bucket[0], val = bucket[1];
|
501
517
|
|
502
518
|
if (__hasOwn.call(map, assoc)) {
|
503
|
-
val = block(__context, key, map[assoc][1], val);
|
519
|
+
val = block.call(__context, key, map[assoc][1], val);
|
504
520
|
}
|
505
521
|
|
506
522
|
map[assoc] = [key, val];
|
@@ -537,7 +553,7 @@ class Hash
|
|
537
553
|
var bucket = map[assoc],
|
538
554
|
value;
|
539
555
|
|
540
|
-
if ((value = block(__context, bucket[0], bucket[1])) === __breaker) {
|
556
|
+
if ((value = block.call(__context, bucket[0], bucket[1])) === __breaker) {
|
541
557
|
return __breaker.$v;
|
542
558
|
}
|
543
559
|
|
@@ -574,7 +590,7 @@ class Hash
|
|
574
590
|
var bucket = map[assoc],
|
575
591
|
value;
|
576
592
|
|
577
|
-
if ((value = block(__context, bucket[0], bucket[1])) === __breaker) {
|
593
|
+
if ((value = block.call(__context, bucket[0], bucket[1])) === __breaker) {
|
578
594
|
return __breaker.$v;
|
579
595
|
}
|
580
596
|
|
@@ -597,7 +613,7 @@ class Hash
|
|
597
613
|
var bucket = map[assoc],
|
598
614
|
value;
|
599
615
|
|
600
|
-
if ((value = block(__context, bucket[0], bucket[1])) === __breaker) {
|
616
|
+
if ((value = block.call(__context, bucket[0], bucket[1])) === __breaker) {
|
601
617
|
return __breaker.$v;
|
602
618
|
}
|
603
619
|
|
@@ -659,6 +675,19 @@ class Hash
|
|
659
675
|
}
|
660
676
|
end
|
661
677
|
|
678
|
+
def to_native
|
679
|
+
%x{
|
680
|
+
var result = {}, map = #{self}.map, bucket;
|
681
|
+
|
682
|
+
for (var assoc in map) {
|
683
|
+
bucket = map[assoc];
|
684
|
+
result[bucket[0]] = #{ `bucket[1]`.to_json };
|
685
|
+
}
|
686
|
+
|
687
|
+
return result;
|
688
|
+
}
|
689
|
+
end
|
690
|
+
|
662
691
|
alias to_s inspect
|
663
692
|
|
664
693
|
alias update merge!
|
data/core/kernel.rb
CHANGED
@@ -34,7 +34,7 @@ module Kernel
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def class
|
37
|
-
`return #{self}
|
37
|
+
`return #{self}._klass`
|
38
38
|
end
|
39
39
|
|
40
40
|
def define_singleton_method(name, &body)
|
@@ -43,12 +43,11 @@ module Kernel
|
|
43
43
|
no_block_given();
|
44
44
|
}
|
45
45
|
|
46
|
-
|
46
|
+
var jsid = '$' + name;
|
47
|
+
body._jsid = jsid;
|
48
|
+
body._sup = #{self}[jsid]
|
47
49
|
|
48
|
-
|
49
|
-
body._sup = #{self}.$m[name]
|
50
|
-
|
51
|
-
#{self}.$m[name] = body;
|
50
|
+
#{self}[jsid] = body;
|
52
51
|
|
53
52
|
return #{self};
|
54
53
|
}
|
@@ -77,7 +76,7 @@ module Kernel
|
|
77
76
|
end
|
78
77
|
|
79
78
|
def instance_of?(klass)
|
80
|
-
`#{self}
|
79
|
+
`#{self}._klass === klass`
|
81
80
|
end
|
82
81
|
|
83
82
|
def instance_variable_defined?(name)
|
@@ -110,14 +109,14 @@ module Kernel
|
|
110
109
|
|
111
110
|
def is_a?(klass)
|
112
111
|
%x{
|
113
|
-
var search = #{self}
|
112
|
+
var search = #{self}._klass;
|
114
113
|
|
115
114
|
while (search) {
|
116
115
|
if (search === klass) {
|
117
116
|
return true;
|
118
117
|
}
|
119
118
|
|
120
|
-
search = search
|
119
|
+
search = search._super;
|
121
120
|
}
|
122
121
|
|
123
122
|
return false;
|
@@ -153,7 +152,7 @@ module Kernel
|
|
153
152
|
if (block === nil) {
|
154
153
|
no_block_given();
|
155
154
|
}
|
156
|
-
|
155
|
+
block.is_lambda = false;
|
157
156
|
return block;
|
158
157
|
}
|
159
158
|
end
|
@@ -187,13 +186,13 @@ module Kernel
|
|
187
186
|
end
|
188
187
|
|
189
188
|
def respond_to?(name)
|
190
|
-
`!!#{self}
|
189
|
+
`!!#{self}['$' + name]`
|
191
190
|
end
|
192
191
|
|
193
192
|
def singleton_class
|
194
193
|
%x{
|
195
194
|
if (!#{self}._isObject) {
|
196
|
-
return #{self}
|
195
|
+
return #{self}._klass;
|
197
196
|
}
|
198
197
|
|
199
198
|
if (#{self}._singleton) {
|
@@ -201,16 +200,16 @@ module Kernel
|
|
201
200
|
}
|
202
201
|
|
203
202
|
else {
|
204
|
-
var orig_class = #{self}
|
203
|
+
var orig_class = #{self}._klass,
|
205
204
|
class_id = "#<Class:#<" + orig_class._name + ":" + orig_class._id + ">>";
|
206
205
|
|
207
206
|
function Singleton() {};
|
208
207
|
var meta = boot_class(orig_class, Singleton);
|
209
208
|
meta._name = class_id;
|
210
209
|
|
211
|
-
#{self}
|
210
|
+
meta.prototype = #{self};
|
212
211
|
#{self}._singleton = meta;
|
213
|
-
meta
|
212
|
+
meta._klass = orig_class._klass;
|
214
213
|
|
215
214
|
return meta;
|
216
215
|
}
|
@@ -233,7 +232,7 @@ module Kernel
|
|
233
232
|
end
|
234
233
|
|
235
234
|
def to_s
|
236
|
-
`return "#<" + #{self}
|
235
|
+
`return "#<" + #{self}._klass._name + ":" + #{self}._id + ">";`
|
237
236
|
end
|
238
237
|
|
239
238
|
def enum_for (method = :each, *args)
|
data/core/load_order
CHANGED
data/core/module.rb
CHANGED
@@ -1,26 +1,7 @@
|
|
1
1
|
class Module
|
2
|
-
def ===(object)
|
3
|
-
%x{
|
4
|
-
if (object == null) {
|
5
|
-
return false;
|
6
|
-
}
|
7
|
-
|
8
|
-
var search = object.$k;
|
9
|
-
|
10
|
-
while (search) {
|
11
|
-
if (search === #{self}) {
|
12
|
-
return true;
|
13
|
-
}
|
14
|
-
|
15
|
-
search = search._super;
|
16
|
-
}
|
17
|
-
|
18
|
-
return false;
|
19
|
-
}
|
20
|
-
end
|
21
2
|
|
22
3
|
def alias_method(newname, oldname)
|
23
|
-
`#{self}
|
4
|
+
`#{self}.prototype['$' + newname] = #{self}.prototype['$' + oldname]`
|
24
5
|
self
|
25
6
|
end
|
26
7
|
|
@@ -60,15 +41,17 @@ class Module
|
|
60
41
|
|
61
42
|
module.$included_in.push(klass);
|
62
43
|
|
63
|
-
var donator = module
|
64
|
-
|
44
|
+
var donator = module.prototype,
|
45
|
+
prototype = klass.prototype,
|
46
|
+
methods = module._methods;
|
65
47
|
|
66
|
-
for (var
|
67
|
-
|
48
|
+
for (var i = 0, length = methods.length; i < length; i++) {
|
49
|
+
var method = methods[i];
|
50
|
+
prototype[method] = donator[method];
|
68
51
|
}
|
69
52
|
|
70
53
|
if (klass.$included_in) {
|
71
|
-
|
54
|
+
klass._donate(methods.slice(), true);
|
72
55
|
}
|
73
56
|
}
|
74
57
|
|
@@ -79,8 +62,8 @@ class Module
|
|
79
62
|
%x{
|
80
63
|
function define_attr(klass, name, getter, setter) {
|
81
64
|
if (getter) {
|
82
|
-
klass
|
83
|
-
var res =
|
65
|
+
klass.prototype['$' + name] = function() {
|
66
|
+
var res = this[name];
|
84
67
|
return res == null ? nil : res;
|
85
68
|
};
|
86
69
|
|
@@ -88,8 +71,8 @@ class Module
|
|
88
71
|
}
|
89
72
|
|
90
73
|
if (setter) {
|
91
|
-
klass
|
92
|
-
return
|
74
|
+
klass.prototype['$' + name + '='] = function(val) {
|
75
|
+
return this[name] = val;
|
93
76
|
};
|
94
77
|
|
95
78
|
klass._donate([name]);
|
@@ -139,11 +122,12 @@ class Module
|
|
139
122
|
no_block_given();
|
140
123
|
}
|
141
124
|
|
142
|
-
|
143
|
-
block.
|
125
|
+
var jsid = '$' + name;
|
126
|
+
block._jsid = jsid;
|
127
|
+
block._sup = #{self}.prototype[jsid];
|
144
128
|
|
145
|
-
#{self}
|
146
|
-
#{self}._donate([
|
129
|
+
#{self}.prototype[jsid] = block;
|
130
|
+
#{self}._donate([jsid]);
|
147
131
|
|
148
132
|
return nil;
|
149
133
|
}
|
@@ -182,7 +166,7 @@ class Module
|
|
182
166
|
no_block_given();
|
183
167
|
}
|
184
168
|
|
185
|
-
return block(#{self});
|
169
|
+
return block.call(#{self});
|
186
170
|
}
|
187
171
|
end
|
188
172
|
|
@@ -202,11 +186,9 @@ class Module
|
|
202
186
|
|
203
187
|
var meta = new __opal.Class;
|
204
188
|
#{self}._singleton = meta;
|
205
|
-
meta
|
189
|
+
meta.prototype = #{self};
|
206
190
|
|
207
191
|
return meta;
|
208
192
|
}
|
209
193
|
end
|
210
|
-
|
211
|
-
alias to_s name
|
212
194
|
end
|
data/core/numeric.rb
CHANGED
@@ -144,7 +144,7 @@ class Numeric < `Number`
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def nonzero?
|
147
|
-
`#{self}
|
147
|
+
`#{self} === 0 ? nil : #{self}`
|
148
148
|
end
|
149
149
|
|
150
150
|
def odd?
|
@@ -208,4 +208,6 @@ class Numeric < `Number`
|
|
208
208
|
def zero?
|
209
209
|
`#{self} == 0`
|
210
210
|
end
|
211
|
-
end
|
211
|
+
end
|
212
|
+
|
213
|
+
Fixnum = Numeric
|