opal 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +3 -0
- data/.travis.yml +0 -4
- data/README.md +6 -0
- data/Rakefile +30 -6
- data/bin/opal +6 -82
- data/corelib/{opal/array.rb → array.rb} +40 -56
- data/corelib/{opal/basic_object.rb → basic_object.rb} +2 -2
- data/corelib/{opal/boolean.rb → boolean.rb} +0 -8
- data/corelib/class.rb +47 -0
- data/corelib/{opal/comparable.rb → comparable.rb} +0 -0
- data/corelib/{opal/enumerable.rb → enumerable.rb} +208 -141
- data/corelib/{opal/enumerator.rb → enumerator.rb} +3 -3
- data/corelib/{opal/error.rb → error.rb} +1 -0
- data/corelib/{opal/hash.rb → hash.rb} +67 -56
- data/corelib/io.rb +39 -0
- data/corelib/{opal/kernel.rb → kernel.rb} +35 -31
- data/corelib/{opal/class.rb → module.rb} +29 -57
- data/corelib/native.rb +148 -0
- data/corelib/{opal/nil_class.rb → nil_class.rb} +2 -10
- data/corelib/{opal/numeric.rb → numeric.rb} +39 -14
- data/corelib/opal.rb +42 -25
- data/corelib/{opal/proc.rb → proc.rb} +3 -3
- data/corelib/{opal/range.rb → range.rb} +5 -1
- data/corelib/{opal/regexp.rb → regexp.rb} +0 -0
- data/corelib/{opal/runtime.js → runtime.js} +96 -188
- data/corelib/{opal/string.rb → string.rb} +20 -15
- data/corelib/struct.rb +139 -0
- data/corelib/{opal/time.rb → time.rb} +0 -0
- data/lib/opal.rb +4 -0
- data/lib/opal/cli.rb +79 -32
- data/lib/opal/cli_options.rb +91 -0
- data/lib/opal/erb.rb +41 -8
- data/lib/opal/grammar.rb +24 -10
- data/lib/opal/grammar.y +15 -4
- data/lib/opal/grammar_helpers.rb +4 -0
- data/lib/opal/lexer.rb +214 -143
- data/lib/opal/parser.rb +596 -562
- data/lib/opal/require_parser.rb +1 -1
- data/lib/opal/source_map.rb +15 -30
- data/lib/opal/target_scope.rb +24 -5
- data/lib/opal/version.rb +1 -1
- data/mri_spec/cli_spec.rb +18 -0
- data/mri_spec/fixtures/opal_file.rb +2 -0
- data/mri_spec/spec_helper.rb +17 -0
- data/opal.gemspec +5 -2
- data/spec/{rubyspec/filters → filters}/bugs/alias.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/ancestors.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array.rb +0 -0
- data/spec/filters/bugs/array/combination.rb +11 -0
- data/spec/filters/bugs/array/count.rb +3 -0
- data/spec/filters/bugs/array/delete_if.rb +3 -0
- data/spec/filters/bugs/array/drop.rb +3 -0
- data/spec/filters/bugs/array/drop_while.rb +5 -0
- data/spec/filters/bugs/array/eql.rb +3 -0
- data/spec/filters/bugs/array/flatten.rb +9 -0
- data/spec/filters/bugs/array/minus.rb +5 -0
- data/spec/filters/bugs/array/multipliy.rb +9 -0
- data/spec/filters/bugs/array/new.rb +3 -0
- data/spec/filters/bugs/array/pop.rb +6 -0
- data/spec/filters/bugs/array/rassoc.rb +4 -0
- data/spec/filters/bugs/array/rindex.rb +6 -0
- data/spec/filters/bugs/array/select.rb +3 -0
- data/spec/filters/bugs/array/shift.rb +7 -0
- data/spec/filters/bugs/array/shuffle.rb +11 -0
- data/spec/filters/bugs/array/slice.rb +7 -0
- data/spec/filters/bugs/array/take.rb +3 -0
- data/spec/filters/bugs/array/to_a.rb +3 -0
- data/spec/filters/bugs/array/try_convert.rb +7 -0
- data/spec/filters/bugs/array/uniq.rb +10 -0
- data/spec/filters/bugs/array/zip.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_delete.rb +1 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_fetch.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_first.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_flatten.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_intersection.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_join.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/break.rb +0 -0
- data/spec/filters/bugs/case.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/coerce_integer.rb +0 -0
- data/spec/filters/bugs/enumerable_sort_by.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/kernel/instance_variables.rb +0 -0
- data/spec/filters/bugs/kernel/rand.rb +4 -0
- data/spec/filters/bugs/language/array.rb +3 -0
- data/spec/filters/bugs/language/block.rb +6 -0
- data/spec/filters/bugs/language/break.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class_variables.rb +0 -0
- data/spec/filters/bugs/language/def.rb +27 -0
- data/spec/filters/bugs/language/defined.rb +3 -0
- data/spec/filters/bugs/language/ensure.rb +4 -0
- data/spec/filters/bugs/language/execution.rb +4 -0
- data/spec/filters/bugs/language/for.rb +18 -0
- data/spec/filters/bugs/language/if.rb +13 -0
- data/spec/filters/bugs/language/loop.rb +4 -0
- data/spec/filters/bugs/language/metaclass.rb +14 -0
- data/spec/filters/bugs/language/module.rb +6 -0
- data/spec/filters/bugs/language/next.rb +3 -0
- data/spec/filters/bugs/language/or.rb +3 -0
- data/spec/filters/bugs/language/order.rb +4 -0
- data/spec/filters/bugs/language/precedence.rb +10 -0
- data/spec/filters/bugs/language/proc.rb +24 -0
- data/spec/filters/bugs/language/redo.rb +5 -0
- data/spec/filters/bugs/language/rescue.rb +9 -0
- data/spec/filters/bugs/language/retry.rb +5 -0
- data/spec/filters/bugs/language/send.rb +10 -0
- data/spec/filters/bugs/language/super.rb +9 -0
- data/spec/filters/bugs/language/until.rb +8 -0
- data/spec/filters/bugs/language/variables.rb +37 -0
- data/spec/filters/bugs/language/while.rb +6 -0
- data/spec/filters/bugs/language/yield.rb +5 -0
- data/spec/{rubyspec/filters → filters}/bugs/module/class_variables.rb +0 -0
- data/spec/filters/bugs/module/method_defined.rb +6 -0
- data/spec/filters/bugs/parser.rb +10 -0
- data/spec/{rubyspec/filters → filters}/bugs/public_methods.rb +1 -0
- data/spec/filters/bugs/return.rb +7 -0
- data/spec/filters/bugs/singleton/instance.rb +4 -0
- data/spec/filters/bugs/source_map.rb +3 -0
- data/spec/filters/bugs/string/center.rb +4 -0
- data/spec/filters/bugs/string/lines.rb +3 -0
- data/spec/{rubyspec/filters → filters}/mspec/mocks.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/ruby_exe.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/should_receive.rb +0 -0
- data/spec/{rubyspec/filters → filters}/parser/block_args.rb +0 -0
- data/spec/{rubyspec/filters → filters}/unsupported/array_subclasses.rb +1 -0
- data/spec/filters/unsupported/frozen.rb +32 -0
- data/spec/filters/unsupported/immutable_strings.rb +3 -0
- data/spec/filters/unsupported/tainted.rb +17 -0
- data/spec/filters/unsupported/trusted.rb +15 -0
- data/spec/opal/class/constants_spec.rb +7 -0
- data/spec/opal/erb/erb_spec.rb +7 -1
- data/spec/opal/erb/inline_block.opalerb +3 -0
- data/spec/opal/hash/allocate_spec.rb +16 -0
- data/spec/opal/hash/new_spec.rb +10 -0
- data/spec/opal/hash/to_s_spec.rb +9 -0
- data/spec/opal/kernel/instance_variable_defined_spec.rb +15 -0
- data/spec/opal/kernel/rand_spec.rb +5 -5
- data/spec/opal/kernel/respond_to_spec.rb +14 -1
- data/spec/opal/language/block_spec.rb +13 -0
- data/spec/opal/language/rescue_spec.rb +27 -0
- data/spec/opal/language/return_spec.rb +38 -0
- data/spec/opal/language/singleton_class_spec.rb +13 -0
- data/spec/opal/language/super_spec.rb +99 -0
- data/spec/opal/language/variables_spec.rb +20 -0
- data/spec/opal/module/attr_accessor_spec.rb +8 -0
- data/spec/opal/module/constants_spec.rb +2 -2
- data/spec/opal/native/alias_native_spec.rb +18 -0
- data/spec/opal/native/each_spec.rb +14 -0
- data/spec/opal/native/element_reference_spec.rb +14 -0
- data/spec/opal/native/method_missing_spec.rb +39 -0
- data/spec/opal/native/new_spec.rb +19 -0
- data/spec/opal/native/nil_spec.rb +14 -0
- data/spec/opal/runtime2/class_hierarchy_spec.rb +2 -2
- data/spec/opal/source_map_spec.rb +3 -7
- data/spec/ospec/main.rb.erb +2 -5
- data/spec/parser/alias_spec.rb +4 -4
- data/spec/parser/and_spec.rb +2 -2
- data/spec/parser/array_spec.rb +6 -6
- data/spec/parser/attrasgn_spec.rb +8 -8
- data/spec/parser/begin_spec.rb +11 -11
- data/spec/parser/block_spec.rb +3 -3
- data/spec/parser/break_spec.rb +4 -4
- data/spec/parser/call_spec.rb +50 -48
- data/spec/parser/class_spec.rb +2 -2
- data/spec/parser/const_spec.rb +1 -1
- data/spec/parser/cvar_spec.rb +1 -1
- data/spec/parser/def_spec.rb +5 -5
- data/spec/parser/gvar_spec.rb +2 -2
- data/spec/parser/hash_spec.rb +4 -4
- data/spec/parser/iasgn_spec.rb +3 -3
- data/spec/parser/if_spec.rb +6 -6
- data/spec/parser/iter_spec.rb +6 -6
- data/spec/parser/lambda_spec.rb +5 -5
- data/spec/parser/lasgn_spec.rb +2 -2
- data/spec/parser/line_spec.rb +2 -2
- data/spec/parser/lvar_spec.rb +5 -5
- data/spec/parser/masgn_spec.rb +1 -1
- data/spec/parser/module_spec.rb +2 -2
- data/spec/parser/not_spec.rb +4 -4
- data/spec/parser/op_asgn1_spec.rb +2 -2
- data/spec/parser/op_asgn2_spec.rb +2 -2
- data/spec/parser/or_spec.rb +2 -2
- data/spec/parser/parse_spec.rb +66 -0
- data/spec/parser/parser_spec.rb +32 -38
- data/spec/parser/regexp_spec.rb +4 -4
- data/spec/parser/return_spec.rb +4 -4
- data/spec/parser/sclass_spec.rb +4 -4
- data/spec/parser/str_spec.rb +3 -3
- data/spec/parser/super_spec.rb +6 -6
- data/spec/parser/undef_spec.rb +3 -3
- data/spec/parser/unless_spec.rb +4 -4
- data/spec/parser/while_spec.rb +3 -3
- data/spec/parser/xstr_spec.rb +3 -3
- data/spec/parser/yield_spec.rb +6 -6
- data/spec/rubyspec/core/array/drop_spec.rb +1 -1
- data/spec/rubyspec/core/array/keep_if_spec.rb +1 -3
- data/spec/rubyspec/core/array/length_spec.rb +1 -3
- data/spec/rubyspec/core/array/map_spec.rb +2 -6
- data/spec/rubyspec/core/array/minus_spec.rb +3 -3
- data/spec/rubyspec/core/array/multiply_spec.rb +14 -16
- data/spec/rubyspec/core/array/new_spec.rb +3 -5
- data/spec/rubyspec/core/array/plus_spec.rb +2 -2
- data/spec/rubyspec/core/array/pop_spec.rb +4 -4
- data/spec/rubyspec/core/array/rassoc_spec.rb +2 -2
- data/spec/rubyspec/core/array/reject_spec.rb +2 -6
- data/spec/rubyspec/core/array/replace_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_each_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_spec.rb +4 -4
- data/spec/rubyspec/core/array/rindex_spec.rb +1 -1
- data/spec/rubyspec/core/array/select_spec.rb +3 -7
- data/spec/rubyspec/core/array/shared/collect.rb +7 -0
- data/spec/rubyspec/core/array/shared/index.rb +1 -1
- data/spec/rubyspec/core/array/shared/keep_if.rb +3 -0
- data/spec/rubyspec/core/array/shared/length.rb +3 -0
- data/spec/rubyspec/core/array/shared/replace.rb +3 -0
- data/spec/rubyspec/core/array/shared/slice.rb +3 -0
- data/spec/rubyspec/core/array/shuffle_spec.rb +1 -1
- data/spec/rubyspec/core/array/size_spec.rb +1 -3
- data/spec/rubyspec/core/array/slice_spec.rb +4 -6
- data/spec/rubyspec/core/array/sort_spec.rb +2 -2
- data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
- data/spec/rubyspec/core/array/try_convert_spec.rb +7 -7
- data/spec/rubyspec/core/array/uniq_spec.rb +7 -7
- data/spec/rubyspec/core/array/zip_spec.rb +1 -1
- data/spec/rubyspec/core/enumerable/collect_spec.rb +24 -0
- data/spec/rubyspec/core/enumerable/count_spec.rb +35 -19
- data/spec/rubyspec/core/enumerable/find_spec.rb +5 -0
- data/spec/rubyspec/core/hash/each_pair_spec.rb +7 -7
- data/spec/rubyspec/core/hash/each_spec.rb +13 -7
- data/spec/rubyspec/core/module/method_defined_spec.rb +4 -4
- data/spec/rubyspec/core/module/public_method_defined_spec.rb +19 -0
- data/spec/rubyspec/core/module/remove_const_spec.rb +23 -0
- data/spec/rubyspec/core/numeric/step_spec.rb +14 -0
- data/spec/rubyspec/core/string/center_spec.rb +43 -65
- data/spec/rubyspec/core/string/lines_spec.rb +1 -1
- data/spec/rubyspec/core/string/ljust_spec.rb +25 -9
- data/spec/rubyspec/core/string/rjust_spec.rb +26 -10
- data/spec/rubyspec/core/struct/fixtures/classes.rb +26 -0
- data/spec/rubyspec/core/struct/initialize_spec.rb +11 -0
- data/spec/rubyspec/core/struct/new_spec.rb +24 -0
- data/spec/rubyspec/fixtures/constants.rb +7 -0
- data/spec/rubyspec/language/break_spec.rb +1 -1
- data/spec/rubyspec/language/case_spec.rb +30 -30
- data/spec/rubyspec/language/def_spec.rb +34 -34
- data/spec/rubyspec/language/defined_spec.rb +2 -2
- data/spec/rubyspec/language/ensure_spec.rb +2 -2
- data/spec/rubyspec/language/execution_spec.rb +2 -2
- data/spec/rubyspec/language/for_spec.rb +17 -17
- data/spec/rubyspec/language/hash_spec.rb +3 -3
- data/spec/rubyspec/language/if_spec.rb +11 -11
- data/spec/rubyspec/language/loop_spec.rb +3 -3
- data/spec/rubyspec/language/metaclass_spec.rb +14 -14
- data/spec/rubyspec/language/module_spec.rb +6 -6
- data/spec/rubyspec/language/next_spec.rb +5 -5
- data/spec/rubyspec/language/not_spec.rb +1 -1
- data/spec/rubyspec/language/or_spec.rb +1 -1
- data/spec/rubyspec/language/order_spec.rb +3 -5
- data/spec/rubyspec/language/precedence_spec.rb +19 -19
- data/spec/rubyspec/language/proc_spec.rb +29 -29
- data/spec/rubyspec/language/redo_spec.rb +3 -5
- data/spec/rubyspec/language/rescue_spec.rb +7 -7
- data/spec/rubyspec/language/retry_spec.rb +2 -2
- data/spec/rubyspec/language/return_spec.rb +12 -12
- data/spec/rubyspec/language/send_spec.rb +9 -9
- data/spec/rubyspec/language/singleton_class_spec.rb +3 -4
- data/spec/rubyspec/language/super_spec.rb +7 -11
- data/spec/rubyspec/language/until_spec.rb +10 -10
- data/spec/rubyspec/language/variables_spec.rb +59 -67
- data/spec/rubyspec/language/versions/array_1.9.rb +1 -1
- data/spec/rubyspec/language/versions/block_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/break_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/literal_lambda_1.9.rb +12 -12
- data/spec/rubyspec/language/versions/send_1.9.rb +23 -23
- data/spec/rubyspec/language/versions/symbol_1.9.rb +2 -2
- data/spec/rubyspec/language/versions/variables_1.9.rb +1 -1
- data/spec/rubyspec/language/while_spec.rb +4 -4
- data/spec/rubyspec/language/yield_spec.rb +3 -3
- data/spec/rubyspec/library/erb/util/html_escape_spec.rb +10 -0
- data/spec/rubyspec/library/singleton/clone_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/dup_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/fixtures/classes.rb +18 -0
- data/spec/rubyspec/library/singleton/instance_spec.rb +30 -0
- data/spec/spec_helper.rb +214 -0
- data/stdlib/buffer.rb +40 -0
- data/stdlib/buffer/array.rb +66 -0
- data/stdlib/buffer/view.rb +70 -0
- data/stdlib/erb.rb +11 -20
- data/stdlib/forwardable.rb +71 -0
- data/stdlib/json.rb +78 -0
- data/stdlib/ostruct.rb +69 -0
- data/stdlib/rbconfig.rb +1 -0
- data/stdlib/singleton.rb +40 -0
- data/stdlib/stringio.rb +173 -0
- data/stdlib/template.rb +44 -0
- metadata +285 -79
- data/corelib/opal/native.rb +0 -31
- data/spec/opal/class/bridge_class_spec.rb +0 -39
- data/spec/opal/native_spec.rb +0 -209
- data/spec/ospec/runner.rb +0 -223
- data/spec/rubyspec/filters/bugs/block_args.rb +0 -3
- data/spec/rubyspec/filters/bugs/case.rb +0 -8
- data/spec/rubyspec/filters/bugs/language/module.rb +0 -3
- data/spec/rubyspec/filters/unsupported/frozen.rb +0 -4
- data/spec/rubyspec/filters/unsupported/tainted.rb +0 -7
@@ -1,12 +1,11 @@
|
|
1
|
-
class
|
2
|
-
def self.new(
|
1
|
+
class Module
|
2
|
+
def self.new(&block)
|
3
3
|
%x{
|
4
|
-
function
|
5
|
-
var klass
|
4
|
+
function AnonModule(){}
|
5
|
+
var klass = Opal.boot(Module, AnonModule);
|
6
6
|
klass._name = nil;
|
7
|
-
klass._scope =
|
8
|
-
|
9
|
-
sup.$inherited(klass);
|
7
|
+
klass._scope = Module._scope;
|
8
|
+
klass._klass = Module;
|
10
9
|
|
11
10
|
if (block !== nil) {
|
12
11
|
var block_self = block._s;
|
@@ -19,10 +18,6 @@ class Class
|
|
19
18
|
}
|
20
19
|
end
|
21
20
|
|
22
|
-
def self.bridge_class(name, constructor)
|
23
|
-
`__opal.bridge(name, constructor)`
|
24
|
-
end
|
25
|
-
|
26
21
|
def ===(object)
|
27
22
|
%x{
|
28
23
|
if (object == null) {
|
@@ -43,14 +38,6 @@ class Class
|
|
43
38
|
}
|
44
39
|
end
|
45
40
|
|
46
|
-
def allocate
|
47
|
-
%x{
|
48
|
-
var obj = new #{self}._alloc;
|
49
|
-
obj._id = Opal.uid();
|
50
|
-
return obj;
|
51
|
-
}
|
52
|
-
end
|
53
|
-
|
54
41
|
def alias_method(newname, oldname)
|
55
42
|
`#{self}._proto['$' + newname] = #{self}._proto['$' + oldname]`
|
56
43
|
self
|
@@ -110,7 +97,7 @@ class Class
|
|
110
97
|
//}
|
111
98
|
|
112
99
|
if (klass._included_in) {
|
113
|
-
|
100
|
+
$opal.donate(klass, methods.slice(), true);
|
114
101
|
}
|
115
102
|
}
|
116
103
|
|
@@ -175,13 +162,13 @@ class Class
|
|
175
162
|
var name_re = /^[A-Z][A-Za-z0-9_]+$/;
|
176
163
|
var scopes = [#{self}._scope];
|
177
164
|
var own_only;
|
178
|
-
if (#{self} === Opal.Class) {
|
165
|
+
if (#{self} === Opal.Class || #{self} === Opal.Module) {
|
179
166
|
own_only = false;
|
180
167
|
}
|
181
168
|
else {
|
182
169
|
own_only = true;
|
183
170
|
var parent = #{self}._super;
|
184
|
-
while (parent !== Opal.Object) {
|
171
|
+
while (parent && (parent !== Opal.Object)) {
|
185
172
|
scopes.push(parent._scope);
|
186
173
|
parent = parent._super;
|
187
174
|
}
|
@@ -242,7 +229,7 @@ class Class
|
|
242
229
|
return scopes[i][name];
|
243
230
|
}
|
244
231
|
}
|
245
|
-
|
232
|
+
|
246
233
|
return #{const_missing name};
|
247
234
|
}
|
248
235
|
end
|
@@ -261,6 +248,11 @@ class Class
|
|
261
248
|
end
|
262
249
|
%x{
|
263
250
|
#{self}._scope[name] = #{value};
|
251
|
+
|
252
|
+
if (value._isClass && value._name === nil) {
|
253
|
+
value._name = #{self.name} + '::' + name;
|
254
|
+
}
|
255
|
+
|
264
256
|
return #{value}
|
265
257
|
}
|
266
258
|
end
|
@@ -272,7 +264,7 @@ class Class
|
|
272
264
|
}
|
273
265
|
|
274
266
|
if (block === nil) {
|
275
|
-
|
267
|
+
throw new Error("no block given");
|
276
268
|
}
|
277
269
|
|
278
270
|
var jsid = '$' + name;
|
@@ -281,7 +273,7 @@ class Class
|
|
281
273
|
block._s = null;
|
282
274
|
|
283
275
|
#{self}._proto[jsid] = block;
|
284
|
-
|
276
|
+
$opal.donate(#{self}, [jsid]);
|
285
277
|
|
286
278
|
return null;
|
287
279
|
}
|
@@ -327,13 +319,10 @@ class Class
|
|
327
319
|
def included(mod)
|
328
320
|
end
|
329
321
|
|
330
|
-
def inherited(cls)
|
331
|
-
end
|
332
|
-
|
333
322
|
def module_eval(&block)
|
334
323
|
%x{
|
335
324
|
if (block === nil) {
|
336
|
-
|
325
|
+
throw new Error("no block given");
|
337
326
|
}
|
338
327
|
|
339
328
|
var block_self = block._s, result;
|
@@ -350,11 +339,8 @@ class Class
|
|
350
339
|
|
351
340
|
def method_defined?(method)
|
352
341
|
%x{
|
353
|
-
|
354
|
-
|
355
|
-
}
|
356
|
-
|
357
|
-
return false;
|
342
|
+
var body = #{self}._proto['$' + method];
|
343
|
+
return (!!body) && !body.rb_stub;
|
358
344
|
}
|
359
345
|
end
|
360
346
|
|
@@ -374,34 +360,20 @@ class Class
|
|
374
360
|
`#{self}._name`
|
375
361
|
end
|
376
362
|
|
377
|
-
def new(*args, &block)
|
378
|
-
%x{
|
379
|
-
if (#{self}._proto.$initialize) {
|
380
|
-
var obj = new #{self}._alloc;
|
381
|
-
obj._id = Opal.uid();
|
382
|
-
|
383
|
-
obj.$initialize._p = block;
|
384
|
-
obj.$initialize.apply(obj, args);
|
385
|
-
return obj;
|
386
|
-
}
|
387
|
-
else {
|
388
|
-
var cons = function() {};
|
389
|
-
cons.prototype = #{self}.prototype;
|
390
|
-
var obj = new cons;
|
391
|
-
#{self}.apply(obj, args);
|
392
|
-
return obj;
|
393
|
-
}
|
394
|
-
}
|
395
|
-
end
|
396
|
-
|
397
363
|
def public(*)
|
398
364
|
end
|
399
365
|
|
400
366
|
alias private public
|
401
367
|
alias protected public
|
402
368
|
|
403
|
-
|
404
|
-
|
369
|
+
alias public_method_defined? method_defined?
|
370
|
+
|
371
|
+
def remove_const(name)
|
372
|
+
%x{
|
373
|
+
var old = #{self}._scope[name];
|
374
|
+
delete #{self}._scope[name];
|
375
|
+
return old;
|
376
|
+
}
|
405
377
|
end
|
406
378
|
|
407
379
|
def to_s
|
@@ -409,7 +381,7 @@ class Class
|
|
409
381
|
end
|
410
382
|
|
411
383
|
def undef_method(symbol)
|
412
|
-
|
384
|
+
`$opal.add_stub_for(#{self}._proto, "$" + symbol)`
|
413
385
|
self
|
414
386
|
end
|
415
387
|
end
|
data/corelib/native.rb
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
module Kernel
|
2
|
+
def native?(value)
|
3
|
+
`value == null || !value._klass`
|
4
|
+
end
|
5
|
+
|
6
|
+
def Native(obj)
|
7
|
+
if native?(obj)
|
8
|
+
Native.new(obj)
|
9
|
+
else
|
10
|
+
obj
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Native < BasicObject
|
16
|
+
module Base
|
17
|
+
module Helpers
|
18
|
+
def alias_native(new, old)
|
19
|
+
define_method new do |*args|
|
20
|
+
Native.call(@native, old, *args)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.included(klass)
|
26
|
+
klass.instance_eval {
|
27
|
+
extend Helpers
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(native)
|
32
|
+
unless native?(native)
|
33
|
+
raise ArgumentError, "the passed value isn't native"
|
34
|
+
end
|
35
|
+
|
36
|
+
@native = native
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_n
|
40
|
+
@native
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.try_convert(value)
|
45
|
+
%x{
|
46
|
+
if (#{native?(value)}) {
|
47
|
+
return #{value}.valueOf();
|
48
|
+
}
|
49
|
+
else if (#{value.respond_to? :to_n}) {
|
50
|
+
return #{value.to_n};
|
51
|
+
}
|
52
|
+
else {
|
53
|
+
return nil;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.convert(value)
|
59
|
+
native = try_convert(value)
|
60
|
+
|
61
|
+
if `#{native} === nil`
|
62
|
+
raise ArgumentError, "the passed value isn't a native"
|
63
|
+
end
|
64
|
+
|
65
|
+
native
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.call(obj, key, *args, &block)
|
69
|
+
args << block if block
|
70
|
+
|
71
|
+
%x{
|
72
|
+
var prop = #{obj}[#{key}];
|
73
|
+
|
74
|
+
if (prop == null) {
|
75
|
+
return nil;
|
76
|
+
}
|
77
|
+
else if (prop instanceof Function) {
|
78
|
+
var result = prop.apply(#{obj}, #{args});
|
79
|
+
|
80
|
+
return result == null ? nil : result;
|
81
|
+
}
|
82
|
+
else if (#{native?(`prop`)}) {
|
83
|
+
return #{Native(`prop`)};
|
84
|
+
}
|
85
|
+
else {
|
86
|
+
return prop;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
include Base
|
92
|
+
|
93
|
+
def nil?
|
94
|
+
`#@native == null`
|
95
|
+
end
|
96
|
+
|
97
|
+
def each
|
98
|
+
return Enumerator.new(self, :each) unless block_given?
|
99
|
+
|
100
|
+
%x{
|
101
|
+
for (var key in #@native) {
|
102
|
+
#{yield `key`, `#@native[key]`}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
self
|
107
|
+
end
|
108
|
+
|
109
|
+
def [](key)
|
110
|
+
raise 'cannot get value from nil native' if nil?
|
111
|
+
|
112
|
+
%x{
|
113
|
+
var prop = #@native[key];
|
114
|
+
|
115
|
+
if (prop instanceof Function) {
|
116
|
+
return prop;
|
117
|
+
}
|
118
|
+
else {
|
119
|
+
return #{::Native.call(@native, key)}
|
120
|
+
}
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
def []=(key, value)
|
125
|
+
raise 'cannot set value on nil native' if nil?
|
126
|
+
|
127
|
+
native = Native.try_convert(value)
|
128
|
+
|
129
|
+
if `#{native} === nil`
|
130
|
+
`#@native[key] = #{value}`
|
131
|
+
else
|
132
|
+
`#@native[key] = #{native}`
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def method_missing(mid, *args, &block)
|
137
|
+
raise 'cannot call method from nil native' if nil?
|
138
|
+
|
139
|
+
%x{
|
140
|
+
if (mid.charAt(mid.length - 1) === '=') {
|
141
|
+
return #{self[mid.slice(0, mid.length - 1)] = args[0]};
|
142
|
+
}
|
143
|
+
else {
|
144
|
+
return #{::Native.call(@native, mid, *args, &block)};
|
145
|
+
}
|
146
|
+
}
|
147
|
+
end
|
148
|
+
end
|
@@ -15,10 +15,6 @@ class NilClass
|
|
15
15
|
`other === nil`
|
16
16
|
end
|
17
17
|
|
18
|
-
def as_json
|
19
|
-
self
|
20
|
-
end
|
21
|
-
|
22
18
|
def dup
|
23
19
|
raise TypeError
|
24
20
|
end
|
@@ -40,7 +36,7 @@ class NilClass
|
|
40
36
|
end
|
41
37
|
|
42
38
|
def to_h
|
43
|
-
|
39
|
+
`$opal.hash()`
|
44
40
|
end
|
45
41
|
|
46
42
|
def to_i
|
@@ -49,10 +45,6 @@ class NilClass
|
|
49
45
|
|
50
46
|
alias to_f to_i
|
51
47
|
|
52
|
-
def to_json
|
53
|
-
'null'
|
54
|
-
end
|
55
|
-
|
56
48
|
def to_n
|
57
49
|
`null`
|
58
50
|
end
|
@@ -62,7 +54,7 @@ class NilClass
|
|
62
54
|
end
|
63
55
|
|
64
56
|
def object_id
|
65
|
-
`#{NilClass}._id || (#{NilClass}._id =
|
57
|
+
`#{NilClass}._id || (#{NilClass}._id = $opal.uid())`
|
66
58
|
end
|
67
59
|
alias hash object_id
|
68
60
|
end
|
@@ -93,10 +93,6 @@ class Numeric
|
|
93
93
|
`Math.abs(#{self})`
|
94
94
|
end
|
95
95
|
|
96
|
-
def as_json
|
97
|
-
self
|
98
|
-
end
|
99
|
-
|
100
96
|
def ceil
|
101
97
|
`Math.ceil(#{self})`
|
102
98
|
end
|
@@ -108,8 +104,8 @@ class Numeric
|
|
108
104
|
def downto(finish, &block)
|
109
105
|
%x{
|
110
106
|
for (var i = #{self}; i >= finish; i--) {
|
111
|
-
if (block(i) ===
|
112
|
-
return
|
107
|
+
if (block(i) === $breaker) {
|
108
|
+
return $breaker.$v;
|
113
109
|
}
|
114
110
|
}
|
115
111
|
|
@@ -159,13 +155,34 @@ class Numeric
|
|
159
155
|
`#{self} - 1`
|
160
156
|
end
|
161
157
|
|
158
|
+
def step(limit, step = 1, &block)
|
159
|
+
%x{
|
160
|
+
var working = #{self};
|
161
|
+
|
162
|
+
if (step > 0) {
|
163
|
+
while (working <= limit) {
|
164
|
+
block(working);
|
165
|
+
working += step;
|
166
|
+
}
|
167
|
+
}
|
168
|
+
else {
|
169
|
+
while (working >= limit) {
|
170
|
+
block(working);
|
171
|
+
working += step;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
return #{self};
|
176
|
+
}
|
177
|
+
end
|
178
|
+
|
162
179
|
alias succ next
|
163
180
|
|
164
181
|
def times(&block)
|
165
182
|
%x{
|
166
183
|
for (var i = 0; i < #{self}; i++) {
|
167
|
-
if (block(i) ===
|
168
|
-
return
|
184
|
+
if (block(i) === $breaker) {
|
185
|
+
return $breaker.$v;
|
169
186
|
}
|
170
187
|
}
|
171
188
|
|
@@ -181,10 +198,6 @@ class Numeric
|
|
181
198
|
`parseInt(#{self})`
|
182
199
|
end
|
183
200
|
|
184
|
-
def to_json
|
185
|
-
`#{self}.toString()`
|
186
|
-
end
|
187
|
-
|
188
201
|
def to_s(base = 10)
|
189
202
|
`#{self}.toString()`
|
190
203
|
end
|
@@ -198,8 +211,8 @@ class Numeric
|
|
198
211
|
|
199
212
|
%x{
|
200
213
|
for (var i = #{self}; i <= finish; i++) {
|
201
|
-
if (block(i) ===
|
202
|
-
return
|
214
|
+
if (block(i) === $breaker) {
|
215
|
+
return $breaker.$v;
|
203
216
|
}
|
204
217
|
}
|
205
218
|
|
@@ -218,3 +231,15 @@ class Numeric
|
|
218
231
|
end
|
219
232
|
|
220
233
|
Fixnum = Numeric
|
234
|
+
|
235
|
+
class Integer < Numeric
|
236
|
+
def self.===(other)
|
237
|
+
other.is_a?(Numeric) && `(other % 1) == 0`
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
class Float < Numeric
|
242
|
+
def self.===(other)
|
243
|
+
other.is_a?(Numeric) && `(other % 1) != 0`
|
244
|
+
end
|
245
|
+
end
|