opal 0.3.15 → 0.3.16
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 +8 -2
- data/README.md +1 -1
- data/Rakefile +51 -57
- data/bin/opal +50 -2
- data/{runtime/corelib → core}/alpha.rb +6 -1
- data/{runtime/corelib → core}/array.rb +38 -42
- data/{runtime/corelib → core}/basic_object.rb +6 -17
- data/core/boolean.rb +40 -0
- data/core/class.rb +69 -0
- data/{runtime/corelib → core}/comparable.rb +0 -0
- data/core/debug.js +59 -0
- data/core/debug.rb +35 -0
- data/core/dir.rb +90 -0
- data/core/enumerable.rb +331 -0
- data/core/enumerator.rb +126 -0
- data/core/error.rb +40 -0
- data/{runtime/corelib → core}/file.rb +6 -3
- data/core/gemlib.rb +30 -0
- data/{runtime/corelib → core}/hash.rb +37 -35
- data/{runtime/corelib → core}/io.rb +0 -0
- data/{runtime/corelib → core}/kernel.rb +26 -21
- data/{runtime/corelib → core}/load_order +2 -5
- data/{runtime/corelib → core}/match_data.rb +2 -4
- data/core/module.rb +204 -0
- data/{runtime/corelib → core}/nil_class.rb +1 -7
- data/{runtime/corelib → core}/numeric.rb +9 -13
- data/core/object.rb +17 -0
- data/{runtime/corelib → core}/proc.rb +2 -13
- data/{runtime/corelib → core}/range.rb +19 -7
- data/{runtime/corelib → core}/rational.rb +0 -0
- data/{runtime/corelib → core}/regexp.rb +2 -6
- data/core/runtime.js +672 -0
- data/{runtime/corelib → core}/string.rb +25 -9
- data/{runtime/corelib → core}/struct.rb +0 -0
- data/core/time.rb +111 -0
- data/{runtime/corelib → core}/top_self.rb +0 -0
- data/{runtime/spec → core_spec}/README.md +0 -0
- data/{runtime/spec → core_spec}/core/array/allocate_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/append_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/assoc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/at_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/clear_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/collect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/compact_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/concat_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/constructor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/count_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/delete_at_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/delete_if_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/delete_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/each_index_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/each_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/element_reference_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/element_set_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/empty_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/eql_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/equal_value_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/fetch_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/first_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/fixtures/classes.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/flatten_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/include_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/insert_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/last_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/length_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/map_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/plus_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/pop_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/push_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/rassoc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/reject_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/replace_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/reverse_each_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/reverse_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/collect.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/eql.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/length.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/replace.rb +0 -0
- data/{runtime/spec → core_spec}/core/class/new_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/all_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/any_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/collect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/count_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/detect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/find_spec.rb +0 -0
- data/core_spec/core/enumerable/first_spec.rb +3 -0
- data/{runtime/spec → core_spec}/core/enumerable/fixtures/classes.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/shared/collect.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/shared/entries.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/shared/find.rb +0 -0
- data/core_spec/core/enumerable/shared/take.rb +31 -0
- data/{runtime/spec → core_spec}/core/enumerable/to_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/inspect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/to_s_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/xor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/allocate_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/assoc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/clear_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/clone_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/default_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/delete_if_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/element_reference_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/element_set_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/new_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/matchdata/to_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/inspect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/nil_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_f_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_i_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_s_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/xor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/numeric/equal_value_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/object/is_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/object/shared/kind_of.rb +0 -0
- data/{runtime/spec → core_spec}/core/regexp/match_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/regexp/shared/match.rb +0 -0
- data/{runtime/spec → core_spec}/core/symbol/to_proc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/inspect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/to_s_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/xor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/alias_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/array_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/block_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/break_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/case_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/defined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/ensure_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/block.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/break.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/defined.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/ensure.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/next.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/send.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/super.rb +0 -0
- data/{runtime/spec → core_spec}/language/hash_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/if_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/loop_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/next_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/predefined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/regexp/interpolation_spec.rb +8 -0
- data/{runtime/spec → core_spec}/language/regexp_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/send_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/string_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/super_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/symbol_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/undef_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/unless_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/until_spec.rb +0 -0
- data/core_spec/language/variables_spec.rb +112 -0
- data/{runtime/spec → core_spec}/language/versions/hash_1.9.rb +0 -0
- data/{runtime/spec → core_spec}/language/while_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/defined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/function_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/native_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/null_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/number_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/object_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/string_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/typeof_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/undefined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/true/case_compare_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/true/class_spec.rb +0 -0
- data/{docs/spec_runner.html → core_spec/release_runner.html} +4 -3
- data/core_spec/runner.html +16 -0
- data/core_spec/spec_helper.rb +23 -0
- data/lib/opal.rb +85 -2
- data/lib/opal/builder.rb +129 -46
- data/lib/opal/context.rb +47 -26
- data/lib/opal/dependency_builder.rb +113 -14
- data/lib/opal/environment.rb +40 -45
- data/lib/opal/parser/grammar.rb +2296 -2254
- data/lib/opal/parser/grammar.y +27 -8
- data/lib/opal/parser/lexer.rb +12 -3
- data/lib/opal/parser/parser.rb +117 -30
- data/lib/opal/parser/scope.rb +2 -2
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +3 -8
- data/spec/grammar/masgn_spec.rb +37 -0
- metadata +177 -227
- data/index.html +0 -434
- data/lib/opal/command.rb +0 -73
- data/runtime/README.md +0 -25
- data/runtime/corelib/boolean.rb +0 -44
- data/runtime/corelib/class.rb +0 -43
- data/runtime/corelib/complex.rb +0 -2
- data/runtime/corelib/dir.rb +0 -29
- data/runtime/corelib/enumerable.rb +0 -316
- data/runtime/corelib/enumerator.rb +0 -80
- data/runtime/corelib/error.rb +0 -25
- data/runtime/corelib/module.rb +0 -171
- data/runtime/corelib/native.rb +0 -50
- data/runtime/corelib/object.rb +0 -21
- data/runtime/corelib/time.rb +0 -196
- data/runtime/gemlib/alpha.rb +0 -5
- data/runtime/gemlib/kernel.rb +0 -17
- data/runtime/gemlib/load_order +0 -2
- data/runtime/kernel/class.js +0 -256
- data/runtime/kernel/debug.js +0 -42
- data/runtime/kernel/init.js +0 -114
- data/runtime/kernel/load_order +0 -5
- data/runtime/kernel/loader.js +0 -151
- data/runtime/kernel/runtime.js +0 -414
- data/runtime/spec/language/variables_spec.rb +0 -28
- data/runtime/spec/library/stringscanner/scan_spec.rb +0 -36
- data/runtime/spec/opal/forwardable/def_instance_delegator_spec.rb +0 -49
- data/runtime/spec/spec_helper.rb +0 -25
- data/runtime/stdlib/base64.rb +0 -91
- data/runtime/stdlib/date.rb +0 -4
- data/runtime/stdlib/dev.rb +0 -171
- data/runtime/stdlib/forwardable.rb +0 -33
- data/runtime/stdlib/optparse.rb +0 -0
- data/runtime/stdlib/pp.rb +0 -6
- data/runtime/stdlib/racc/parser.rb +0 -159
- data/runtime/stdlib/rbconfig.rb +0 -0
- data/runtime/stdlib/si.rb +0 -17
- data/runtime/stdlib/strscan.rb +0 -53
- data/runtime/stdlib/uri.rb +0 -111
- data/runtime/stdlib/uri/common.rb +0 -1014
- data/runtime/stdlib/uri/ftp.rb +0 -261
- data/runtime/stdlib/uri/generic.rb +0 -1599
- data/runtime/stdlib/uri/http.rb +0 -106
- data/runtime/stdlib/uri/https.rb +0 -22
- data/runtime/stdlib/uri/ldap.rb +0 -260
- data/runtime/stdlib/uri/ldaps.rb +0 -20
- data/runtime/stdlib/uri/mailto.rb +0 -280
- data/spec/builder/output_path_spec.rb +0 -50
@@ -7,23 +7,20 @@ object
|
|
7
7
|
top_self
|
8
8
|
boolean
|
9
9
|
nil_class
|
10
|
-
native
|
11
10
|
enumerable
|
12
|
-
comparable
|
13
11
|
enumerator
|
12
|
+
comparable
|
14
13
|
array
|
15
14
|
hash
|
16
15
|
string
|
17
16
|
numeric
|
18
|
-
rational
|
19
|
-
complex
|
20
17
|
proc
|
21
18
|
range
|
22
19
|
error
|
23
20
|
regexp
|
24
21
|
match_data
|
25
|
-
struct
|
26
22
|
time
|
23
|
+
struct
|
27
24
|
io
|
28
25
|
file
|
29
26
|
dir
|
@@ -23,14 +23,12 @@ class MatchData
|
|
23
23
|
"#<MatchData #{self[0].inspect}>"
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
alias size length
|
27
27
|
|
28
28
|
def to_a
|
29
|
-
|
29
|
+
`$slice.call(this.$data)`
|
30
30
|
end
|
31
31
|
|
32
|
-
alias to_native to_a
|
33
|
-
|
34
32
|
def to_s
|
35
33
|
`this.$data[0]`
|
36
34
|
end
|
data/core/module.rb
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
class Module
|
2
|
+
def ===(object)
|
3
|
+
object.kind_of? self
|
4
|
+
end
|
5
|
+
|
6
|
+
def alias_method(newname, oldname)
|
7
|
+
`$opal.alias(this, newname, oldname)`
|
8
|
+
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def ancestors
|
13
|
+
%x{
|
14
|
+
var parent = this,
|
15
|
+
result = [];
|
16
|
+
|
17
|
+
while (parent) {
|
18
|
+
if (!(parent.$flags & FL_SINGLETON)) {
|
19
|
+
result.push(parent);
|
20
|
+
}
|
21
|
+
|
22
|
+
parent = parent.$s;
|
23
|
+
}
|
24
|
+
|
25
|
+
return result;
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def append_features(klass)
|
30
|
+
%x{
|
31
|
+
var module = this;
|
32
|
+
|
33
|
+
if (!klass.$included_modules) {
|
34
|
+
klass.$included_modules = [];
|
35
|
+
}
|
36
|
+
|
37
|
+
if (klass.$included_modules.indexOf(module) != -1) {
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
|
41
|
+
klass.$included_modules.push(module);
|
42
|
+
|
43
|
+
if (!module.$included_in) {
|
44
|
+
module.$included_in = [];
|
45
|
+
}
|
46
|
+
|
47
|
+
module.$included_in.push(klass);
|
48
|
+
|
49
|
+
var donator = module.$allocator.prototype,
|
50
|
+
prototype = klass.$proto,
|
51
|
+
methods = [];
|
52
|
+
|
53
|
+
for (var method in donator) {
|
54
|
+
if (hasOwnProperty.call(donator, method)) {
|
55
|
+
if (!prototype.hasOwnProperty(method)) {
|
56
|
+
prototype[method] = donator[method];
|
57
|
+
methods.push(method);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
if (klass.$included_in) {
|
63
|
+
klass.$donate(methods);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
# Private helper function to define attributes
|
71
|
+
%x{
|
72
|
+
function define_attr(klass, name, getter, setter) {
|
73
|
+
if (getter) {
|
74
|
+
define_method(klass, mid_to_jsid(name), function() {
|
75
|
+
var res = this[name];
|
76
|
+
|
77
|
+
return res == null ? nil : res;
|
78
|
+
});
|
79
|
+
}
|
80
|
+
|
81
|
+
if (setter) {
|
82
|
+
define_method(klass, mid_to_jsid(name + '='), function(block, val) {
|
83
|
+
return this[name] = val;
|
84
|
+
});
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
def attr_accessor(*attrs)
|
90
|
+
%x{
|
91
|
+
for (var i = 0, length = attrs.length; i < length; i++) {
|
92
|
+
define_attr(this, attrs[i], true, true);
|
93
|
+
}
|
94
|
+
|
95
|
+
return nil;
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
def attr_reader(*attrs)
|
100
|
+
%x{
|
101
|
+
for (var i = 0, length = attrs.length; i < length; i++) {
|
102
|
+
define_attr(this, attrs[i], true, false);
|
103
|
+
}
|
104
|
+
|
105
|
+
return nil;
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
def attr_writer(*attrs)
|
110
|
+
%x{
|
111
|
+
for (var i = 0, length = attrs.length; i < length; i++) {
|
112
|
+
define_attr(this, attrs[i], false, true);
|
113
|
+
}
|
114
|
+
|
115
|
+
return nil;
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
def attr(name, setter = false)
|
120
|
+
`define_attr(this, name, true, setter)`
|
121
|
+
|
122
|
+
self
|
123
|
+
end
|
124
|
+
|
125
|
+
def define_method(name, &body)
|
126
|
+
%x{
|
127
|
+
if (body === nil) {
|
128
|
+
raise(RubyLocalJumpError, 'no block given');
|
129
|
+
}
|
130
|
+
|
131
|
+
define_method(this, mid_to_jsid(name), body);
|
132
|
+
|
133
|
+
return nil;
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
# FIXME: this could do with a better name
|
138
|
+
def donate(methods)
|
139
|
+
%x{
|
140
|
+
var included_in = this.$included_in, includee, method, table = this.$proto, dest;
|
141
|
+
|
142
|
+
if (included_in) {
|
143
|
+
for (var i = 0, length = included_in.length; i < length; i++) {
|
144
|
+
includee = included_in[i];
|
145
|
+
dest = includee.$proto;
|
146
|
+
for (var j = 0, jj = methods.length; j < jj; j++) {
|
147
|
+
method = methods[j];
|
148
|
+
// if (!dest[method]) {
|
149
|
+
dest[method] = table[method];
|
150
|
+
// }
|
151
|
+
}
|
152
|
+
// if our includee is itself included in another module/class then it
|
153
|
+
// should also donate its new methods
|
154
|
+
if (includee.$included_in) {
|
155
|
+
includee.$donate(methods);
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
def include(*mods)
|
163
|
+
%x{
|
164
|
+
var i = mods.length - 1, mod;
|
165
|
+
while (i >= 0) {
|
166
|
+
#{mod = `mods[i]`};
|
167
|
+
#{mod.append_features self};
|
168
|
+
#{mod.included self};
|
169
|
+
|
170
|
+
i--;
|
171
|
+
}
|
172
|
+
|
173
|
+
return this;
|
174
|
+
}
|
175
|
+
end
|
176
|
+
|
177
|
+
# FIXME
|
178
|
+
def instance_methods
|
179
|
+
[]
|
180
|
+
end
|
181
|
+
|
182
|
+
def included(mod)
|
183
|
+
end
|
184
|
+
|
185
|
+
def module_eval(&block)
|
186
|
+
%x{
|
187
|
+
if (block === nil) {
|
188
|
+
raise(RubyLocalJumpError, 'no block given');
|
189
|
+
}
|
190
|
+
|
191
|
+
return block.call(this, null);
|
192
|
+
}
|
193
|
+
end
|
194
|
+
|
195
|
+
alias class_eval module_eval
|
196
|
+
|
197
|
+
def name
|
198
|
+
`this.$name`
|
199
|
+
end
|
200
|
+
|
201
|
+
alias public_instance_methods instance_methods
|
202
|
+
|
203
|
+
alias to_s name
|
204
|
+
end
|
@@ -77,7 +77,7 @@ class Numeric
|
|
77
77
|
|
78
78
|
def <=>(other)
|
79
79
|
%x{
|
80
|
-
if (
|
80
|
+
if (typeof(other) !== 'number') {
|
81
81
|
return nil;
|
82
82
|
}
|
83
83
|
|
@@ -98,7 +98,7 @@ class Numeric
|
|
98
98
|
|
99
99
|
%x{
|
100
100
|
for (var i = this; i >= finish; i--) {
|
101
|
-
if ($yield.call($context,
|
101
|
+
if ($yield.call($context, i) === $breaker) {
|
102
102
|
return $breaker.$v;
|
103
103
|
}
|
104
104
|
}
|
@@ -123,9 +123,9 @@ class Numeric
|
|
123
123
|
`this % 1 === 0`
|
124
124
|
end
|
125
125
|
|
126
|
-
|
126
|
+
alias magnitude abs
|
127
127
|
|
128
|
-
|
128
|
+
alias modulo %
|
129
129
|
|
130
130
|
def next
|
131
131
|
`this + 1`
|
@@ -143,14 +143,14 @@ class Numeric
|
|
143
143
|
`this - 1`
|
144
144
|
end
|
145
145
|
|
146
|
-
|
146
|
+
alias succ next
|
147
147
|
|
148
148
|
def times(&block)
|
149
149
|
return enum_for :times unless block
|
150
150
|
|
151
151
|
%x{
|
152
152
|
for (var i = 0; i <= this; i++) {
|
153
|
-
if ($yield.call($context,
|
153
|
+
if ($yield.call($context, i) === $breaker) {
|
154
154
|
return $breaker.$v;
|
155
155
|
}
|
156
156
|
}
|
@@ -167,10 +167,6 @@ class Numeric
|
|
167
167
|
`parseInt(this)`
|
168
168
|
end
|
169
169
|
|
170
|
-
def to_native
|
171
|
-
`this.valueOf()`
|
172
|
-
end
|
173
|
-
|
174
170
|
def to_s(base = 10)
|
175
171
|
`this.toString(base)`
|
176
172
|
end
|
@@ -180,7 +176,7 @@ class Numeric
|
|
180
176
|
|
181
177
|
%x{
|
182
178
|
for (var i = 0; i <= finish; i++) {
|
183
|
-
if ($yield.call($context,
|
179
|
+
if ($yield.call($context, i) === $breaker) {
|
184
180
|
return $breaker.$v;
|
185
181
|
}
|
186
182
|
}
|
@@ -197,7 +193,7 @@ end
|
|
197
193
|
class Integer
|
198
194
|
def self.===(obj)
|
199
195
|
%x{
|
200
|
-
if (
|
196
|
+
if (typeof(obj) !== 'number') {
|
201
197
|
return false;
|
202
198
|
}
|
203
199
|
|
@@ -209,7 +205,7 @@ end
|
|
209
205
|
class Float
|
210
206
|
def self.===(obj)
|
211
207
|
%x{
|
212
|
-
if (
|
208
|
+
if (typeof(obj) !== 'number') {
|
213
209
|
return false;
|
214
210
|
}
|
215
211
|
|
data/core/object.rb
ADDED
@@ -10,18 +10,7 @@ class Proc
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def call(*args)
|
13
|
-
`this.apply(this.$S,
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_native
|
17
|
-
%x{
|
18
|
-
return function() {
|
19
|
-
var args = Array.slice.call(arguments);
|
20
|
-
args.unshift(null); // block
|
21
|
-
|
22
|
-
return this.apply(this.$S, args);
|
23
|
-
};
|
24
|
-
}
|
13
|
+
`this.apply(this.$S, args)`
|
25
14
|
end
|
26
15
|
|
27
16
|
def to_proc
|
@@ -33,7 +22,7 @@ class Proc
|
|
33
22
|
end
|
34
23
|
|
35
24
|
def lambda?
|
36
|
-
|
25
|
+
`!!this.$lambda`
|
37
26
|
end
|
38
27
|
|
39
28
|
def arity
|
@@ -1,3 +1,15 @@
|
|
1
|
+
# Helper function on runtime for creating range literals
|
2
|
+
%x{
|
3
|
+
$opal.range = function(beg, end, exc) {
|
4
|
+
var range = new RubyRange.$allocator();
|
5
|
+
range.begin = beg;
|
6
|
+
range.end = end;
|
7
|
+
range.exclude = exc;
|
8
|
+
|
9
|
+
return range;
|
10
|
+
};
|
11
|
+
}
|
12
|
+
|
1
13
|
class Range
|
2
14
|
def begin
|
3
15
|
`this.begin`
|
@@ -7,16 +19,16 @@ class Range
|
|
7
19
|
`this.end`
|
8
20
|
end
|
9
21
|
|
10
|
-
|
11
|
-
|
22
|
+
alias first begin
|
23
|
+
alias min begin
|
12
24
|
|
13
|
-
|
14
|
-
|
25
|
+
alias last end
|
26
|
+
alias max end
|
15
27
|
|
16
28
|
def initialize(min, max, exclude = false)
|
17
|
-
@begin =
|
18
|
-
@end =
|
19
|
-
@exclude =
|
29
|
+
@begin = min
|
30
|
+
@end = max
|
31
|
+
@exclude = exclude
|
20
32
|
end
|
21
33
|
|
22
34
|
# FIXME: currently hardcoded to assume range holds numerics
|
File without changes
|
@@ -17,7 +17,7 @@ class Regexp
|
|
17
17
|
|
18
18
|
def =~(string)
|
19
19
|
%x{
|
20
|
-
var result
|
20
|
+
var result = this.exec(string);
|
21
21
|
|
22
22
|
if (result) {
|
23
23
|
var match = new RubyMatch.$allocator();
|
@@ -32,7 +32,7 @@ class Regexp
|
|
32
32
|
}
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
alias eql? ==
|
36
36
|
|
37
37
|
def inspect
|
38
38
|
`this.toString()`
|
@@ -53,10 +53,6 @@ class Regexp
|
|
53
53
|
}
|
54
54
|
end
|
55
55
|
|
56
|
-
def to_native
|
57
|
-
self
|
58
|
-
end
|
59
|
-
|
60
56
|
def to_s
|
61
57
|
`this.source`
|
62
58
|
end
|