opal 0.3.15 → 0.3.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. data/.gitignore +1 -1
  2. data/Gemfile +8 -2
  3. data/README.md +1 -1
  4. data/Rakefile +51 -57
  5. data/bin/opal +50 -2
  6. data/{runtime/corelib → core}/alpha.rb +6 -1
  7. data/{runtime/corelib → core}/array.rb +38 -42
  8. data/{runtime/corelib → core}/basic_object.rb +6 -17
  9. data/core/boolean.rb +40 -0
  10. data/core/class.rb +69 -0
  11. data/{runtime/corelib → core}/comparable.rb +0 -0
  12. data/core/debug.js +59 -0
  13. data/core/debug.rb +35 -0
  14. data/core/dir.rb +90 -0
  15. data/core/enumerable.rb +331 -0
  16. data/core/enumerator.rb +126 -0
  17. data/core/error.rb +40 -0
  18. data/{runtime/corelib → core}/file.rb +6 -3
  19. data/core/gemlib.rb +30 -0
  20. data/{runtime/corelib → core}/hash.rb +37 -35
  21. data/{runtime/corelib → core}/io.rb +0 -0
  22. data/{runtime/corelib → core}/kernel.rb +26 -21
  23. data/{runtime/corelib → core}/load_order +2 -5
  24. data/{runtime/corelib → core}/match_data.rb +2 -4
  25. data/core/module.rb +204 -0
  26. data/{runtime/corelib → core}/nil_class.rb +1 -7
  27. data/{runtime/corelib → core}/numeric.rb +9 -13
  28. data/core/object.rb +17 -0
  29. data/{runtime/corelib → core}/proc.rb +2 -13
  30. data/{runtime/corelib → core}/range.rb +19 -7
  31. data/{runtime/corelib → core}/rational.rb +0 -0
  32. data/{runtime/corelib → core}/regexp.rb +2 -6
  33. data/core/runtime.js +672 -0
  34. data/{runtime/corelib → core}/string.rb +25 -9
  35. data/{runtime/corelib → core}/struct.rb +0 -0
  36. data/core/time.rb +111 -0
  37. data/{runtime/corelib → core}/top_self.rb +0 -0
  38. data/{runtime/spec → core_spec}/README.md +0 -0
  39. data/{runtime/spec → core_spec}/core/array/allocate_spec.rb +0 -0
  40. data/{runtime/spec → core_spec}/core/array/append_spec.rb +0 -0
  41. data/{runtime/spec → core_spec}/core/array/assoc_spec.rb +0 -0
  42. data/{runtime/spec → core_spec}/core/array/at_spec.rb +0 -0
  43. data/{runtime/spec → core_spec}/core/array/clear_spec.rb +0 -0
  44. data/{runtime/spec → core_spec}/core/array/collect_spec.rb +0 -0
  45. data/{runtime/spec → core_spec}/core/array/compact_spec.rb +0 -0
  46. data/{runtime/spec → core_spec}/core/array/concat_spec.rb +0 -0
  47. data/{runtime/spec → core_spec}/core/array/constructor_spec.rb +0 -0
  48. data/{runtime/spec → core_spec}/core/array/count_spec.rb +0 -0
  49. data/{runtime/spec → core_spec}/core/array/delete_at_spec.rb +0 -0
  50. data/{runtime/spec → core_spec}/core/array/delete_if_spec.rb +0 -0
  51. data/{runtime/spec → core_spec}/core/array/delete_spec.rb +0 -0
  52. data/{runtime/spec → core_spec}/core/array/each_index_spec.rb +0 -0
  53. data/{runtime/spec → core_spec}/core/array/each_spec.rb +0 -0
  54. data/{runtime/spec → core_spec}/core/array/element_reference_spec.rb +0 -0
  55. data/{runtime/spec → core_spec}/core/array/element_set_spec.rb +0 -0
  56. data/{runtime/spec → core_spec}/core/array/empty_spec.rb +0 -0
  57. data/{runtime/spec → core_spec}/core/array/eql_spec.rb +0 -0
  58. data/{runtime/spec → core_spec}/core/array/equal_value_spec.rb +0 -0
  59. data/{runtime/spec → core_spec}/core/array/fetch_spec.rb +0 -0
  60. data/{runtime/spec → core_spec}/core/array/first_spec.rb +0 -0
  61. data/{runtime/spec → core_spec}/core/array/fixtures/classes.rb +0 -0
  62. data/{runtime/spec → core_spec}/core/array/flatten_spec.rb +0 -0
  63. data/{runtime/spec → core_spec}/core/array/include_spec.rb +0 -0
  64. data/{runtime/spec → core_spec}/core/array/insert_spec.rb +0 -0
  65. data/{runtime/spec → core_spec}/core/array/last_spec.rb +0 -0
  66. data/{runtime/spec → core_spec}/core/array/length_spec.rb +0 -0
  67. data/{runtime/spec → core_spec}/core/array/map_spec.rb +0 -0
  68. data/{runtime/spec → core_spec}/core/array/plus_spec.rb +0 -0
  69. data/{runtime/spec → core_spec}/core/array/pop_spec.rb +0 -0
  70. data/{runtime/spec → core_spec}/core/array/push_spec.rb +0 -0
  71. data/{runtime/spec → core_spec}/core/array/rassoc_spec.rb +0 -0
  72. data/{runtime/spec → core_spec}/core/array/reject_spec.rb +0 -0
  73. data/{runtime/spec → core_spec}/core/array/replace_spec.rb +0 -0
  74. data/{runtime/spec → core_spec}/core/array/reverse_each_spec.rb +0 -0
  75. data/{runtime/spec → core_spec}/core/array/reverse_spec.rb +0 -0
  76. data/{runtime/spec → core_spec}/core/array/shared/collect.rb +0 -0
  77. data/{runtime/spec → core_spec}/core/array/shared/eql.rb +0 -0
  78. data/{runtime/spec → core_spec}/core/array/shared/length.rb +0 -0
  79. data/{runtime/spec → core_spec}/core/array/shared/replace.rb +0 -0
  80. data/{runtime/spec → core_spec}/core/class/new_spec.rb +0 -0
  81. data/{runtime/spec → core_spec}/core/enumerable/all_spec.rb +0 -0
  82. data/{runtime/spec → core_spec}/core/enumerable/any_spec.rb +0 -0
  83. data/{runtime/spec → core_spec}/core/enumerable/collect_spec.rb +0 -0
  84. data/{runtime/spec → core_spec}/core/enumerable/count_spec.rb +0 -0
  85. data/{runtime/spec → core_spec}/core/enumerable/detect_spec.rb +0 -0
  86. data/{runtime/spec → core_spec}/core/enumerable/find_spec.rb +0 -0
  87. data/core_spec/core/enumerable/first_spec.rb +3 -0
  88. data/{runtime/spec → core_spec}/core/enumerable/fixtures/classes.rb +0 -0
  89. data/{runtime/spec → core_spec}/core/enumerable/shared/collect.rb +0 -0
  90. data/{runtime/spec → core_spec}/core/enumerable/shared/entries.rb +0 -0
  91. data/{runtime/spec → core_spec}/core/enumerable/shared/find.rb +0 -0
  92. data/core_spec/core/enumerable/shared/take.rb +31 -0
  93. data/{runtime/spec → core_spec}/core/enumerable/to_a_spec.rb +0 -0
  94. data/{runtime/spec → core_spec}/core/false/and_spec.rb +0 -0
  95. data/{runtime/spec → core_spec}/core/false/inspect_spec.rb +0 -0
  96. data/{runtime/spec → core_spec}/core/false/or_spec.rb +0 -0
  97. data/{runtime/spec → core_spec}/core/false/to_s_spec.rb +0 -0
  98. data/{runtime/spec → core_spec}/core/false/xor_spec.rb +0 -0
  99. data/{runtime/spec → core_spec}/core/hash/allocate_spec.rb +0 -0
  100. data/{runtime/spec → core_spec}/core/hash/assoc_spec.rb +0 -0
  101. data/{runtime/spec → core_spec}/core/hash/clear_spec.rb +0 -0
  102. data/{runtime/spec → core_spec}/core/hash/clone_spec.rb +0 -0
  103. data/{runtime/spec → core_spec}/core/hash/default_spec.rb +0 -0
  104. data/{runtime/spec → core_spec}/core/hash/delete_if_spec.rb +0 -0
  105. data/{runtime/spec → core_spec}/core/hash/element_reference_spec.rb +0 -0
  106. data/{runtime/spec → core_spec}/core/hash/element_set_spec.rb +0 -0
  107. data/{runtime/spec → core_spec}/core/hash/new_spec.rb +0 -0
  108. data/{runtime/spec → core_spec}/core/matchdata/to_a_spec.rb +0 -0
  109. data/{runtime/spec → core_spec}/core/nil/and_spec.rb +0 -0
  110. data/{runtime/spec → core_spec}/core/nil/inspect_spec.rb +0 -0
  111. data/{runtime/spec → core_spec}/core/nil/nil_spec.rb +0 -0
  112. data/{runtime/spec → core_spec}/core/nil/or_spec.rb +0 -0
  113. data/{runtime/spec → core_spec}/core/nil/to_a_spec.rb +0 -0
  114. data/{runtime/spec → core_spec}/core/nil/to_f_spec.rb +0 -0
  115. data/{runtime/spec → core_spec}/core/nil/to_i_spec.rb +0 -0
  116. data/{runtime/spec → core_spec}/core/nil/to_s_spec.rb +0 -0
  117. data/{runtime/spec → core_spec}/core/nil/xor_spec.rb +0 -0
  118. data/{runtime/spec → core_spec}/core/numeric/equal_value_spec.rb +0 -0
  119. data/{runtime/spec → core_spec}/core/object/is_a_spec.rb +0 -0
  120. data/{runtime/spec → core_spec}/core/object/shared/kind_of.rb +0 -0
  121. data/{runtime/spec → core_spec}/core/regexp/match_spec.rb +0 -0
  122. data/{runtime/spec → core_spec}/core/regexp/shared/match.rb +0 -0
  123. data/{runtime/spec → core_spec}/core/symbol/to_proc_spec.rb +0 -0
  124. data/{runtime/spec → core_spec}/core/true/and_spec.rb +0 -0
  125. data/{runtime/spec → core_spec}/core/true/inspect_spec.rb +0 -0
  126. data/{runtime/spec → core_spec}/core/true/or_spec.rb +0 -0
  127. data/{runtime/spec → core_spec}/core/true/to_s_spec.rb +0 -0
  128. data/{runtime/spec → core_spec}/core/true/xor_spec.rb +0 -0
  129. data/{runtime/spec → core_spec}/language/alias_spec.rb +0 -0
  130. data/{runtime/spec → core_spec}/language/and_spec.rb +0 -0
  131. data/{runtime/spec → core_spec}/language/array_spec.rb +0 -0
  132. data/{runtime/spec → core_spec}/language/block_spec.rb +0 -0
  133. data/{runtime/spec → core_spec}/language/break_spec.rb +0 -0
  134. data/{runtime/spec → core_spec}/language/case_spec.rb +0 -0
  135. data/{runtime/spec → core_spec}/language/defined_spec.rb +0 -0
  136. data/{runtime/spec → core_spec}/language/ensure_spec.rb +0 -0
  137. data/{runtime/spec → core_spec}/language/fixtures/block.rb +0 -0
  138. data/{runtime/spec → core_spec}/language/fixtures/break.rb +0 -0
  139. data/{runtime/spec → core_spec}/language/fixtures/defined.rb +0 -0
  140. data/{runtime/spec → core_spec}/language/fixtures/ensure.rb +0 -0
  141. data/{runtime/spec → core_spec}/language/fixtures/next.rb +0 -0
  142. data/{runtime/spec → core_spec}/language/fixtures/send.rb +0 -0
  143. data/{runtime/spec → core_spec}/language/fixtures/super.rb +0 -0
  144. data/{runtime/spec → core_spec}/language/hash_spec.rb +0 -0
  145. data/{runtime/spec → core_spec}/language/if_spec.rb +0 -0
  146. data/{runtime/spec → core_spec}/language/loop_spec.rb +0 -0
  147. data/{runtime/spec → core_spec}/language/next_spec.rb +0 -0
  148. data/{runtime/spec → core_spec}/language/or_spec.rb +0 -0
  149. data/{runtime/spec → core_spec}/language/predefined_spec.rb +0 -0
  150. data/{runtime/spec → core_spec}/language/regexp/interpolation_spec.rb +8 -0
  151. data/{runtime/spec → core_spec}/language/regexp_spec.rb +0 -0
  152. data/{runtime/spec → core_spec}/language/send_spec.rb +0 -0
  153. data/{runtime/spec → core_spec}/language/string_spec.rb +0 -0
  154. data/{runtime/spec → core_spec}/language/super_spec.rb +0 -0
  155. data/{runtime/spec → core_spec}/language/symbol_spec.rb +0 -0
  156. data/{runtime/spec → core_spec}/language/undef_spec.rb +0 -0
  157. data/{runtime/spec → core_spec}/language/unless_spec.rb +0 -0
  158. data/{runtime/spec → core_spec}/language/until_spec.rb +0 -0
  159. data/core_spec/language/variables_spec.rb +112 -0
  160. data/{runtime/spec → core_spec}/language/versions/hash_1.9.rb +0 -0
  161. data/{runtime/spec → core_spec}/language/while_spec.rb +0 -0
  162. data/{runtime/spec → core_spec}/opal/opal/defined_spec.rb +0 -0
  163. data/{runtime/spec → core_spec}/opal/opal/function_spec.rb +0 -0
  164. data/{runtime/spec → core_spec}/opal/opal/native_spec.rb +0 -0
  165. data/{runtime/spec → core_spec}/opal/opal/null_spec.rb +0 -0
  166. data/{runtime/spec → core_spec}/opal/opal/number_spec.rb +0 -0
  167. data/{runtime/spec → core_spec}/opal/opal/object_spec.rb +0 -0
  168. data/{runtime/spec → core_spec}/opal/opal/string_spec.rb +0 -0
  169. data/{runtime/spec → core_spec}/opal/opal/typeof_spec.rb +0 -0
  170. data/{runtime/spec → core_spec}/opal/opal/undefined_spec.rb +0 -0
  171. data/{runtime/spec → core_spec}/opal/true/case_compare_spec.rb +0 -0
  172. data/{runtime/spec → core_spec}/opal/true/class_spec.rb +0 -0
  173. data/{docs/spec_runner.html → core_spec/release_runner.html} +4 -3
  174. data/core_spec/runner.html +16 -0
  175. data/core_spec/spec_helper.rb +23 -0
  176. data/lib/opal.rb +85 -2
  177. data/lib/opal/builder.rb +129 -46
  178. data/lib/opal/context.rb +47 -26
  179. data/lib/opal/dependency_builder.rb +113 -14
  180. data/lib/opal/environment.rb +40 -45
  181. data/lib/opal/parser/grammar.rb +2296 -2254
  182. data/lib/opal/parser/grammar.y +27 -8
  183. data/lib/opal/parser/lexer.rb +12 -3
  184. data/lib/opal/parser/parser.rb +117 -30
  185. data/lib/opal/parser/scope.rb +2 -2
  186. data/lib/opal/version.rb +1 -1
  187. data/opal.gemspec +3 -8
  188. data/spec/grammar/masgn_spec.rb +37 -0
  189. metadata +177 -227
  190. data/index.html +0 -434
  191. data/lib/opal/command.rb +0 -73
  192. data/runtime/README.md +0 -25
  193. data/runtime/corelib/boolean.rb +0 -44
  194. data/runtime/corelib/class.rb +0 -43
  195. data/runtime/corelib/complex.rb +0 -2
  196. data/runtime/corelib/dir.rb +0 -29
  197. data/runtime/corelib/enumerable.rb +0 -316
  198. data/runtime/corelib/enumerator.rb +0 -80
  199. data/runtime/corelib/error.rb +0 -25
  200. data/runtime/corelib/module.rb +0 -171
  201. data/runtime/corelib/native.rb +0 -50
  202. data/runtime/corelib/object.rb +0 -21
  203. data/runtime/corelib/time.rb +0 -196
  204. data/runtime/gemlib/alpha.rb +0 -5
  205. data/runtime/gemlib/kernel.rb +0 -17
  206. data/runtime/gemlib/load_order +0 -2
  207. data/runtime/kernel/class.js +0 -256
  208. data/runtime/kernel/debug.js +0 -42
  209. data/runtime/kernel/init.js +0 -114
  210. data/runtime/kernel/load_order +0 -5
  211. data/runtime/kernel/loader.js +0 -151
  212. data/runtime/kernel/runtime.js +0 -414
  213. data/runtime/spec/language/variables_spec.rb +0 -28
  214. data/runtime/spec/library/stringscanner/scan_spec.rb +0 -36
  215. data/runtime/spec/opal/forwardable/def_instance_delegator_spec.rb +0 -49
  216. data/runtime/spec/spec_helper.rb +0 -25
  217. data/runtime/stdlib/base64.rb +0 -91
  218. data/runtime/stdlib/date.rb +0 -4
  219. data/runtime/stdlib/dev.rb +0 -171
  220. data/runtime/stdlib/forwardable.rb +0 -33
  221. data/runtime/stdlib/optparse.rb +0 -0
  222. data/runtime/stdlib/pp.rb +0 -6
  223. data/runtime/stdlib/racc/parser.rb +0 -159
  224. data/runtime/stdlib/rbconfig.rb +0 -0
  225. data/runtime/stdlib/si.rb +0 -17
  226. data/runtime/stdlib/strscan.rb +0 -53
  227. data/runtime/stdlib/uri.rb +0 -111
  228. data/runtime/stdlib/uri/common.rb +0 -1014
  229. data/runtime/stdlib/uri/ftp.rb +0 -261
  230. data/runtime/stdlib/uri/generic.rb +0 -1599
  231. data/runtime/stdlib/uri/http.rb +0 -106
  232. data/runtime/stdlib/uri/https.rb +0 -22
  233. data/runtime/stdlib/uri/ldap.rb +0 -260
  234. data/runtime/stdlib/uri/ldaps.rb +0 -20
  235. data/runtime/stdlib/uri/mailto.rb +0 -280
  236. 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
- alias_method :size, :length
26
+ alias size length
27
27
 
28
28
  def to_a
29
- `[].slice.call(this.$data, 0)`
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
@@ -31,13 +31,7 @@ class NilClass
31
31
  0
32
32
  end
33
33
 
34
- def to_f
35
- 0.0
36
- end
37
-
38
- def to_native
39
- `var result; return result;`
40
- end
34
+ alias to_f to_i
41
35
 
42
36
  def to_s
43
37
  ''
@@ -77,7 +77,7 @@ class Numeric
77
77
 
78
78
  def <=>(other)
79
79
  %x{
80
- if (#{!Opal.number?(other)}) {
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, null, i) === $breaker) {
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
- alias_method :magnitude, :abs
126
+ alias magnitude abs
127
127
 
128
- alias_method :modulo, :%
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
- alias_method :succ, :next
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, null, i) === $breaker) {
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, null, i) === $breaker) {
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 (#{!Opal.number?(obj)}) {
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 (#{!Opal.number?(obj)}) {
208
+ if (typeof(obj) !== 'number') {
213
209
  return false;
214
210
  }
215
211
 
data/core/object.rb ADDED
@@ -0,0 +1,17 @@
1
+ class Object
2
+ include Kernel
3
+
4
+ # FIXME
5
+ def methods
6
+ []
7
+ end
8
+
9
+ alias private_methods methods
10
+ alias protected_methods methods
11
+ alias public_methods methods
12
+
13
+ # FIXME
14
+ def singleton_methods
15
+ []
16
+ end
17
+ end
@@ -10,18 +10,7 @@ class Proc
10
10
  end
11
11
 
12
12
  def call(*args)
13
- `this.apply(this.$S, $slice.call(arguments))`
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
- `this.$lambda ? true : false`
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
- alias_method :first, :begin
11
- alias_method :min, :begin
22
+ alias first begin
23
+ alias min begin
12
24
 
13
- alias_method :last, :end
14
- alias_method :max, :end
25
+ alias last end
26
+ alias max end
15
27
 
16
28
  def initialize(min, max, exclude = false)
17
- @begin = `this.begin = min`
18
- @end = `this.end = max`
19
- @exclude = `this.exclude = 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 = this.exec(string);
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
- alias_method :eql?, :==
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