opal 0.3.18 → 0.3.19

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.
Files changed (259) hide show
  1. data/.gitignore +1 -1
  2. data/Gemfile +1 -3
  3. data/README.md +472 -10
  4. data/Rakefile +10 -52
  5. data/core/array.rb +9 -14
  6. data/core/basic_object.rb +7 -10
  7. data/core/boolean.rb +5 -1
  8. data/core/class.rb +15 -38
  9. data/core/dir.rb +89 -0
  10. data/core/enumerable.rb +133 -57
  11. data/core/error.rb +15 -1
  12. data/core/file.rb +85 -0
  13. data/core/hash.rb +186 -32
  14. data/core/kernel.rb +30 -31
  15. data/core/load_order +4 -2
  16. data/core/module.rb +42 -62
  17. data/core/numeric.rb +7 -1
  18. data/core/object.rb +1 -1
  19. data/core/proc.rb +6 -2
  20. data/core/range.rb +16 -28
  21. data/core/regexp.rb +3 -3
  22. data/core/runtime.js +281 -350
  23. data/core/string.rb +100 -110
  24. data/docs/CNAME +1 -0
  25. data/docs/Rakefile +55 -0
  26. data/docs/css/styles.css +50 -0
  27. data/docs/css/syntax.css +63 -0
  28. data/docs/layout/post.html +3 -0
  29. data/docs/layout/pre.html +11 -0
  30. data/examples/dependencies/app.rb +3 -0
  31. data/lib/opal.rb +2 -1
  32. data/lib/opal/builder.rb +36 -10
  33. data/lib/opal/builder_task.rb +51 -24
  34. data/lib/opal/grammar.rb +2509 -2439
  35. data/lib/opal/grammar.y +38 -5
  36. data/lib/opal/lexer.rb +18 -2
  37. data/lib/opal/parser.rb +375 -349
  38. data/lib/opal/scope.rb +24 -2
  39. data/lib/opal/version.rb +1 -1
  40. data/spec/builder/build_order_spec.rb +20 -0
  41. data/spec/builder/lib_name_for_spec.rb +24 -0
  42. data/spec/grammar/call_spec.rb +9 -6
  43. data/spec/grammar/lambda_spec.rb +64 -0
  44. data/spec/grammar/sclass_spec.rb +5 -3
  45. data/{core/spec → test}/core/array/allocate_spec.rb +0 -0
  46. data/{core/spec → test}/core/array/append_spec.rb +0 -0
  47. data/{core/spec → test}/core/array/assoc_spec.rb +0 -0
  48. data/{core/spec → test}/core/array/at_spec.rb +0 -0
  49. data/{core/spec → test}/core/array/clear_spec.rb +0 -0
  50. data/{core/spec → test}/core/array/clone_spec.rb +0 -0
  51. data/{core/spec → test}/core/array/collect_spec.rb +0 -0
  52. data/{core/spec → test}/core/array/compact_spec.rb +0 -0
  53. data/{core/spec → test}/core/array/concat_spec.rb +0 -0
  54. data/{core/spec → test}/core/array/constructor_spec.rb +0 -0
  55. data/{core/spec → test}/core/array/count_spec.rb +0 -0
  56. data/{core/spec → test}/core/array/delete_at_spec.rb +0 -0
  57. data/{core/spec → test}/core/array/delete_if_spec.rb +0 -0
  58. data/{core/spec → test}/core/array/delete_spec.rb +0 -0
  59. data/{core/spec → test}/core/array/each_index_spec.rb +0 -0
  60. data/{core/spec → test}/core/array/each_spec.rb +0 -0
  61. data/{core/spec → test}/core/array/element_reference_spec.rb +0 -0
  62. data/{core/spec → test}/core/array/empty_spec.rb +0 -0
  63. data/{core/spec → test}/core/array/eql_spec.rb +0 -0
  64. data/{core/spec → test}/core/array/fetch_spec.rb +0 -0
  65. data/{core/spec → test}/core/array/first_spec.rb +0 -0
  66. data/{core/spec → test}/core/array/flatten_spec.rb +0 -0
  67. data/{core/spec → test}/core/array/include_spec.rb +0 -0
  68. data/{core/spec → test}/core/array/insert_spec.rb +0 -0
  69. data/{core/spec → test}/core/array/last_spec.rb +0 -0
  70. data/{core/spec → test}/core/array/length_spec.rb +0 -0
  71. data/{core/spec → test}/core/array/map_spec.rb +0 -0
  72. data/{core/spec → test}/core/array/plus_spec.rb +0 -0
  73. data/{core/spec → test}/core/array/pop_spec.rb +0 -0
  74. data/{core/spec → test}/core/array/push_spec.rb +0 -0
  75. data/{core/spec → test}/core/array/rassoc_spec.rb +0 -0
  76. data/{core/spec → test}/core/array/reject_spec.rb +0 -0
  77. data/{core/spec → test}/core/array/replace_spec.rb +0 -0
  78. data/{core/spec → test}/core/array/reverse_each_spec.rb +0 -0
  79. data/{core/spec → test}/core/array/reverse_spec.rb +0 -0
  80. data/{core/spec → test}/core/array/size_spec.rb +0 -0
  81. data/{core/spec → test}/core/array/to_ary_spec.rb +0 -0
  82. data/{core/spec → test}/core/array/uniq_spec.rb +0 -0
  83. data/{core/spec → test}/core/array/zip_spec.rb +0 -0
  84. data/test/core/class/fixtures/classes.rb +9 -0
  85. data/test/core/class/new_spec.rb +108 -0
  86. data/{core/spec → test}/core/enumerable/all_spec.rb +0 -0
  87. data/{core/spec → test}/core/enumerable/any_spec.rb +0 -0
  88. data/{core/spec → test}/core/enumerable/collect_spec.rb +0 -0
  89. data/{core/spec → test}/core/enumerable/count_spec.rb +0 -0
  90. data/test/core/enumerable/detect_spec.rb +48 -0
  91. data/test/core/enumerable/drop_spec.rb +17 -0
  92. data/test/core/enumerable/drop_while_spec.rb +24 -0
  93. data/test/core/enumerable/each_with_index_spec.rb +11 -0
  94. data/test/core/enumerable/each_with_object_spec.rb +17 -0
  95. data/test/core/enumerable/entries_spec.rb +6 -0
  96. data/test/core/enumerable/find_all_spec.rb +13 -0
  97. data/test/core/enumerable/find_index_spec.rb +45 -0
  98. data/test/core/enumerable/find_spec.rb +48 -0
  99. data/test/core/enumerable/first_spec.rb +40 -0
  100. data/{core/spec → test}/core/enumerable/fixtures/classes.rb +19 -0
  101. data/test/core/enumerable/grep_spec.rb +21 -0
  102. data/test/core/enumerable/take_spec.rb +40 -0
  103. data/test/core/enumerable/to_a_spec.rb +6 -0
  104. data/{core/spec → test}/core/false/and_spec.rb +0 -0
  105. data/{core/spec → test}/core/false/inspect_spec.rb +0 -0
  106. data/{core/spec → test}/core/false/or_spec.rb +0 -0
  107. data/{core/spec → test}/core/false/to_s_spec.rb +0 -0
  108. data/{core/spec → test}/core/false/xor_spec.rb +0 -0
  109. data/test/core/file/expand_path_spec.rb +20 -0
  110. data/{core/spec → test}/core/hash/allocate_spec.rb +0 -0
  111. data/{core/spec → test}/core/hash/assoc_spec.rb +0 -0
  112. data/{core/spec → test}/core/hash/clear_spec.rb +0 -0
  113. data/{core/spec → test}/core/hash/clone_spec.rb +0 -0
  114. data/test/core/hash/default_spec.rb +9 -0
  115. data/{core/spec → test}/core/hash/delete_if_spec.rb +0 -0
  116. data/test/core/hash/each_key_spec.rb +15 -0
  117. data/test/core/hash/each_pair_spec.rb +30 -0
  118. data/test/core/hash/each_spec.rb +30 -0
  119. data/test/core/hash/each_value_spec.rb +15 -0
  120. data/{core/spec → test}/core/hash/element_reference_spec.rb +14 -0
  121. data/{core/spec → test}/core/hash/element_set_spec.rb +1 -0
  122. data/test/core/hash/empty_spec.rb +10 -0
  123. data/test/core/hash/fetch_spec.rb +24 -0
  124. data/test/core/hash/flatten_spec.rb +46 -0
  125. data/test/core/hash/has_key_spec.rb +24 -0
  126. data/test/core/hash/has_value_spec.rb +12 -0
  127. data/test/core/hash/include_spec.rb +24 -0
  128. data/test/core/hash/index_spec.rb +13 -0
  129. data/test/core/hash/indexes_spec.rb +9 -0
  130. data/test/core/hash/indices_spec.rb +9 -0
  131. data/test/core/hash/invert_spec.rb +12 -0
  132. data/test/core/hash/keep_if_spec.rb +18 -0
  133. data/test/core/hash/key_spec.rb +24 -0
  134. data/test/core/hash/keys_spec.rb +10 -0
  135. data/test/core/hash/length_spec.rb +10 -0
  136. data/test/core/hash/member_spec.rb +24 -0
  137. data/{core/spec → test}/core/hash/merge_spec.rb +0 -0
  138. data/{core/spec → test}/core/hash/new_spec.rb +0 -0
  139. data/test/core/hash/rassoc_spec.rb +34 -0
  140. data/test/core/hash/replace_spec.rb +7 -0
  141. data/test/core/hash/select_spec.rb +52 -0
  142. data/test/core/hash/shift_spec.rb +19 -0
  143. data/test/core/hash/size_spec.rb +10 -0
  144. data/test/core/hash/update_spec.rb +17 -0
  145. data/test/core/hash/value_spec.rb +12 -0
  146. data/test/core/hash/values_at_spec.rb +9 -0
  147. data/test/core/hash/values_spec.rb +7 -0
  148. data/test/core/kernel/eql_spec.rb +15 -0
  149. data/test/core/kernel/equal_value_spec.rb +12 -0
  150. data/test/core/kernel/loop_spec.rb +23 -0
  151. data/test/core/kernel/nil_spec.rb +7 -0
  152. data/test/core/kernel/proc_spec.rb +9 -0
  153. data/test/core/kernel/rand_spec.rb +14 -0
  154. data/test/core/kernel/respond_to_spec.rb +24 -0
  155. data/test/core/kernel/send_spec.rb +56 -0
  156. data/test/core/kernel/tap_spec.rb +10 -0
  157. data/test/core/kernel/to_s_spec.rb +5 -0
  158. data/{core/spec → test}/core/matchdata/to_a_spec.rb +0 -0
  159. data/{core/spec → test}/core/nil/and_spec.rb +0 -0
  160. data/{core/spec → test}/core/nil/inspect_spec.rb +0 -0
  161. data/{core/spec → test}/core/nil/nil_spec.rb +0 -0
  162. data/{core/spec → test}/core/nil/or_spec.rb +0 -0
  163. data/{core/spec → test}/core/nil/to_a_spec.rb +0 -0
  164. data/{core/spec → test}/core/nil/to_f_spec.rb +0 -0
  165. data/{core/spec → test}/core/nil/to_i_spec.rb +0 -0
  166. data/{core/spec → test}/core/nil/to_s_spec.rb +0 -0
  167. data/{core/spec → test}/core/nil/xor_spec.rb +0 -0
  168. data/{core/spec → test}/core/numeric/equal_value_spec.rb +0 -0
  169. data/test/core/range/begin_spec.rb +9 -0
  170. data/test/core/range/case_compare_spec.rb +16 -0
  171. data/test/core/range/end_spec.rb +9 -0
  172. data/{core/spec → test}/core/regexp/match_spec.rb +0 -0
  173. data/test/core/string/capitalize_spec.rb +10 -0
  174. data/test/core/string/casecmp_spec.rb +16 -0
  175. data/test/core/string/chomp_spec.rb +43 -0
  176. data/test/core/string/chop_spec.rb +10 -0
  177. data/test/core/string/chr_spec.rb +13 -0
  178. data/test/core/string/comparison_spec.rb +13 -0
  179. data/test/core/string/downcase_spec.rb +6 -0
  180. data/test/core/string/element_reference_spec.rb +72 -0
  181. data/test/core/string/empty_spec.rb +8 -0
  182. data/test/core/string/end_with_spec.rb +12 -0
  183. data/test/core/string/fixtures/classes.rb +3 -0
  184. data/test/core/string/gsub_spec.rb +17 -0
  185. data/test/core/string/include_spec.rb +12 -0
  186. data/test/core/string/intern_spec.rb +9 -0
  187. data/test/core/string/length_spec.rb +9 -0
  188. data/test/core/string/lstrip_spec.rb +7 -0
  189. data/test/core/string/match_spec.rb +27 -0
  190. data/test/core/string/next_spec.rb +10 -0
  191. data/test/core/string/ord_spec.rb +9 -0
  192. data/test/core/string/partition_spec.rb +10 -0
  193. data/test/core/string/reverse_spec.rb +7 -0
  194. data/test/core/string/rstrip_spec.rb +7 -0
  195. data/test/core/string/size_spec.rb +9 -0
  196. data/test/core/string/slice_spec.rb +72 -0
  197. data/test/core/string/split_spec.rb +5 -0
  198. data/test/core/string/start_with_spec.rb +12 -0
  199. data/test/core/string/strip_spec.rb +6 -0
  200. data/test/core/string/sub_spec.rb +22 -0
  201. data/test/core/string/succ_spec.rb +10 -0
  202. data/test/core/string/sum_spec.rb +5 -0
  203. data/test/core/string/swapcase_spec.rb +18 -0
  204. data/test/core/string/to_a_spec.rb +9 -0
  205. data/test/core/string/to_f_spec.rb +14 -0
  206. data/test/core/string/to_i_spec.rb +25 -0
  207. data/test/core/string/to_s_spec.rb +13 -0
  208. data/test/core/string/to_str_spec.rb +13 -0
  209. data/test/core/string/to_sym_spec.rb +9 -0
  210. data/test/core/string/upcase_spec.rb +6 -0
  211. data/test/core/symbol/to_proc_spec.rb +12 -0
  212. data/{core/spec → test}/core/true/and_spec.rb +0 -0
  213. data/{core/spec → test}/core/true/inspect_spec.rb +0 -0
  214. data/{core/spec → test}/core/true/or_spec.rb +0 -0
  215. data/{core/spec → test}/core/true/to_s_spec.rb +0 -0
  216. data/{core/spec → test}/core/true/xor_spec.rb +0 -0
  217. data/test/index.html +11 -0
  218. data/{core/spec → test}/language/alias_spec.rb +4 -0
  219. data/{core/spec → test}/language/and_spec.rb +0 -0
  220. data/{core/spec → test}/language/array_spec.rb +0 -0
  221. data/{core/spec → test}/language/block_spec.rb +0 -0
  222. data/{core/spec → test}/language/break_spec.rb +0 -0
  223. data/{core/spec → test}/language/case_spec.rb +0 -0
  224. data/{core/spec → test}/language/defined_spec.rb +0 -0
  225. data/{core/spec → test}/language/ensure_spec.rb +0 -0
  226. data/test/language/fixtures/yield.rb +23 -0
  227. data/{core/spec → test}/language/hash_spec.rb +0 -0
  228. data/{core/spec → test}/language/if_spec.rb +0 -0
  229. data/test/language/literal_lambda_spec.rb +47 -0
  230. data/{core/spec → test}/language/loop_spec.rb +0 -0
  231. data/{core/spec → test}/language/metaclass_spec.rb +0 -0
  232. data/{core/spec → test}/language/next_spec.rb +0 -0
  233. data/{core/spec → test}/language/or_spec.rb +0 -0
  234. data/{core/spec → test}/language/predefined_spec.rb +0 -0
  235. data/{core/spec → test}/language/regexp_spec.rb +0 -0
  236. data/{core/spec → test}/language/send_spec.rb +0 -0
  237. data/{core/spec → test}/language/singleton_class_spec.rb +0 -0
  238. data/{core/spec → test}/language/super_spec.rb +0 -0
  239. data/{core/spec → test}/language/symbol_spec.rb +0 -0
  240. data/{core/spec → test}/language/undef_spec.rb +0 -0
  241. data/{core/spec → test}/language/unless_spec.rb +0 -0
  242. data/{core/spec → test}/language/until_spec.rb +0 -0
  243. data/{core/spec → test}/language/variables_spec.rb +0 -0
  244. data/{core/spec → test}/language/while_spec.rb +0 -0
  245. data/test/language/yield_spec.rb +100 -0
  246. data/test/opal/array/subclassing_spec.rb +32 -0
  247. data/test/opal/class/bridge_class_spec.rb +37 -0
  248. data/test/opal/exception/subclassing_spec.rb +17 -0
  249. data/test/opal/runtime/_methods_spec.rb +48 -0
  250. data/test/opal/runtime/class_hierarchy_spec.rb +22 -0
  251. data/test/opal/runtime/def_spec.rb +23 -0
  252. data/test/opal/string/subclassing_spec.rb +26 -0
  253. data/test/spec_helper.rb +3 -0
  254. metadata +437 -111
  255. data/core/spec/core/class/new_spec.rb +0 -16
  256. data/core/spec/core/hash/default_spec.rb +0 -4
  257. data/core/spec/core/symbol/to_proc_spec.rb +0 -6
  258. data/core/spec/index.html +0 -11
  259. data/spec/builder/build_source_spec.rb +0 -52
@@ -29,29 +29,18 @@ module Kernel
29
29
  }
30
30
  end
31
31
 
32
- def at_exit(&block)
33
- %x{
34
- if (block === null) {
35
- throw RubyArgError.$new('called without a block');
36
- }
37
-
38
- end_procs.push(block);
39
-
40
- return block;
41
- }
42
- end
43
-
44
32
  def class
45
- `class_real(this._klass)`
33
+ `return this._real`
46
34
  end
47
35
 
48
36
  def define_singleton_method(name, &body)
49
37
  %x{
50
- if (body === null) {
51
- throw RubyLocalJumpError.$new('no block given');
38
+ if (body === nil) {
39
+ no_block_given();
52
40
  }
53
41
 
54
- opal.defs(this, mid_to_jsid(name), body);
42
+ // FIXME: need to donate()
43
+ this.$singleton_class()._proto[mid_to_jsid(name)] = body;
55
44
 
56
45
  return this;
57
46
  }
@@ -88,14 +77,14 @@ module Kernel
88
77
  end
89
78
 
90
79
  def instance_variable_defined?(name)
91
- `hasOwnProperty.call(this, name.substr(1))`
80
+ `__hasOwn.call(this, name.substr(1))`
92
81
  end
93
82
 
94
83
  def instance_variable_get(name)
95
84
  %x{
96
85
  var ivar = this[name.substr(1)];
97
86
 
98
- return ivar == undefined ? null : ivar;
87
+ return ivar == null ? nil : ivar;
99
88
  }
100
89
  end
101
90
 
@@ -142,7 +131,7 @@ module Kernel
142
131
 
143
132
  %x{
144
133
  while (true) {
145
- if (block.call(__context) === breaker) {
134
+ if (block.call(__context) === __breaker) {
146
135
  return breaker.$v;
147
136
  }
148
137
  }
@@ -168,7 +157,13 @@ module Kernel
168
157
  end
169
158
 
170
159
  def proc(&block)
171
- block
160
+ %x{
161
+ if (block === nil) {
162
+ no_block_given();
163
+ }
164
+
165
+ return block;
166
+ }
172
167
  end
173
168
 
174
169
  def protected(*)
@@ -183,9 +178,10 @@ module Kernel
183
178
  %x{
184
179
  for (var i = 0; i < strs.length; i++) {
185
180
  var obj = strs[i];
186
- console.log(obj == null ? "nil" : obj.$to_s());
181
+ console.log(#{ `obj`.to_s });
187
182
  }
188
183
  }
184
+ nil
189
185
  end
190
186
 
191
187
  alias sprintf format
@@ -193,9 +189,9 @@ module Kernel
193
189
  def raise(exception, string = undefined)
194
190
  %x{
195
191
  if (typeof(exception) === 'string') {
196
- exception = #{`RubyRuntimeError`.new `exception`};
192
+ exception = #{RuntimeError.new exception};
197
193
  }
198
- else if (#{!exception.is_a? `RubyException`}) {
194
+ else if (#{!exception.is_a? Exception}) {
199
195
  exception = #{`exception`.new string};
200
196
  }
201
197
 
@@ -208,7 +204,7 @@ module Kernel
208
204
  end
209
205
 
210
206
  def require(path)
211
- `require_handler(path);`
207
+ `Opal.require(path)`
212
208
  end
213
209
 
214
210
  def respond_to?(name)
@@ -219,18 +215,17 @@ module Kernel
219
215
  %x{
220
216
  var obj = this, klass;
221
217
 
222
- if (obj._flags & T_OBJECT) {
223
- if ((obj._flags & T_NUMBER) || (obj._flags & T_STRING)) {
218
+ if (obj._isObject) {
219
+ if (obj._isNumber || obj._isString) {
224
220
  throw RubyTypeError.$new("can't define singleton");
225
221
  }
226
222
  }
227
223
 
228
- if ((obj._klass._flags & FL_SINGLETON) && obj._klass.__attached__ == obj) {
224
+ if ((obj._klass._isSingleton) && obj._klass.__attached__ == obj) {
229
225
  klass = obj._klass;
230
226
  }
231
227
  else {
232
228
  var class_id = obj._klass._name;
233
-
234
229
  klass = make_metaclass(obj, obj._klass);
235
230
  }
236
231
 
@@ -240,8 +235,8 @@ module Kernel
240
235
 
241
236
  def tap(&block)
242
237
  %x{
243
- if (block === null) {
244
- throw RubyLocalJumpError.$new('no block given');
238
+ if (block === nil) {
239
+ no_block_given();
245
240
  }
246
241
 
247
242
  if (block.call(__context, this) === __breaker) {
@@ -252,7 +247,11 @@ module Kernel
252
247
  }
253
248
  end
254
249
 
250
+ def to_proc
251
+ self
252
+ end
253
+
255
254
  def to_s
256
- `return "#<" + class_real(this._klass)._name + ":0x" + (this._id * 400487).toString(16) + ">";`
255
+ `return "#<" + this._klass._real._name + ":0x" + (this._id * 400487).toString(16) + ">";`
257
256
  end
258
257
  end
@@ -1,7 +1,7 @@
1
1
  alpha
2
+ basic_object
2
3
  module
3
4
  kernel
4
- basic_object
5
5
  object
6
6
  top_self
7
7
  class
@@ -20,4 +20,6 @@ error
20
20
  regexp
21
21
  match_data
22
22
  time
23
- struct
23
+ struct
24
+ file
25
+ dir
@@ -1,6 +1,11 @@
1
1
  class Module
2
2
  def ===(object)
3
3
  %x{
4
+
5
+ if (object == null) {
6
+ return false;
7
+ }
8
+
4
9
  var search = object._klass;
5
10
 
6
11
  while (search) {
@@ -16,8 +21,7 @@ class Module
16
21
  end
17
22
 
18
23
  def alias_method(newname, oldname)
19
- `opal.alias(this, newname, oldname)`
20
-
24
+ `this._proto[mid_to_jsid(newname)] = this._proto[mid_to_jsid(oldname)]`
21
25
  self
22
26
  end
23
27
 
@@ -27,10 +31,10 @@ class Module
27
31
  result = [];
28
32
 
29
33
  while (parent) {
30
- if (parent._flags & FL_SINGLETON) {
34
+ if (parent._isSingleton) {
31
35
  continue;
32
36
  }
33
- else if (parent._flags & T_ICLASS)
37
+ else if (parent._isIClass)
34
38
  result.push(parent._klass);
35
39
  else {
36
40
  result.push(parent);
@@ -65,19 +69,15 @@ class Module
65
69
 
66
70
  var donator = module._alloc.prototype,
67
71
  prototype = klass._proto,
68
- methods = [];
69
-
70
- for (var method in donator) {
71
- if (hasOwnProperty.call(donator, method)) {
72
- if (!prototype.hasOwnProperty(method)) {
73
- prototype[method] = donator[method];
74
- methods.push(method);
75
- }
76
- }
72
+ methods = module._methods;
73
+
74
+ for (var i = 0, length = methods.length; i < length; i++) {
75
+ var method = methods[i];
76
+ prototype[method] = donator[method];
77
77
  }
78
78
 
79
79
  if (klass.$included_in) {
80
- klass.$donate(methods);
80
+ __donate(klass, methods.slice(), true);
81
81
  }
82
82
  }
83
83
 
@@ -88,17 +88,24 @@ class Module
88
88
  %x{
89
89
  function define_attr(klass, name, getter, setter) {
90
90
  if (getter) {
91
- define_method(klass, mid_to_jsid(name), function() {
91
+ var get_jsid = mid_to_jsid(name);
92
+
93
+ klass._alloc.prototype[get_jsid] = function() {
92
94
  var res = this[name];
95
+ return res == null ? nil : res;
96
+ };
93
97
 
94
- return res == null ? null : res;
95
- });
98
+ __donate(klass, [get_jsid]);
96
99
  }
97
100
 
98
101
  if (setter) {
99
- define_method(klass, mid_to_jsid(name + '='), function(val) {
102
+ var set_jsid = mid_to_jsid(name + '=');
103
+
104
+ klass._alloc.prototype[set_jsid] = function(val) {
100
105
  return this[name] = val;
101
- });
106
+ };
107
+
108
+ __donate(klass, [set_jsid]);
102
109
  }
103
110
  }
104
111
  }
@@ -109,7 +116,7 @@ class Module
109
116
  define_attr(this, attrs[i], true, true);
110
117
  }
111
118
 
112
- return null;
119
+ return nil;
113
120
  }
114
121
  end
115
122
 
@@ -119,7 +126,7 @@ class Module
119
126
  define_attr(this, attrs[i], true, false);
120
127
  }
121
128
 
122
- return null;
129
+ return nil;
123
130
  }
124
131
  end
125
132
 
@@ -129,7 +136,7 @@ class Module
129
136
  define_attr(this, attrs[i], false, true);
130
137
  }
131
138
 
132
- return null;
139
+ return nil;
133
140
  }
134
141
  end
135
142
 
@@ -139,43 +146,19 @@ class Module
139
146
  self
140
147
  end
141
148
 
142
- def define_method(name, &body)
149
+ def define_method(name, &block)
143
150
  %x{
144
- if (body === null) {
145
- throw RubyLocalJumpError.$new('no block given');
151
+ if (block === nil) {
152
+ no_block_given();
146
153
  }
147
154
 
148
155
  var jsid = mid_to_jsid(name);
156
+ block._jsid = jsid;
149
157
 
150
- body.o$jsid = jsid;
151
- define_method(this, jsid, body);
158
+ this._alloc.prototype[jsid] = block;
159
+ __donate(this, [jsid]);
152
160
 
153
- return null;
154
- }
155
- end
156
-
157
- # FIXME: this could do with a better name
158
- def donate(methods)
159
- %x{
160
- var included_in = this.$included_in, includee, method, table = this._proto, dest;
161
-
162
- if (included_in) {
163
- for (var i = 0, length = included_in.length; i < length; i++) {
164
- includee = included_in[i];
165
- dest = includee._proto;
166
- for (var j = 0, jj = methods.length; j < jj; j++) {
167
- method = methods[j];
168
- // if (!dest[method]) {
169
- dest[method] = table[method];
170
- // }
171
- }
172
- // if our includee is itself included in another module/class then it
173
- // should also donate its new methods
174
- if (includee.$included_in) {
175
- includee.$donate(methods);
176
- }
177
- }
178
- }
161
+ return nil;
179
162
  }
180
163
  end
181
164
 
@@ -183,13 +166,10 @@ class Module
183
166
  %x{
184
167
  var i = mods.length - 1, mod;
185
168
  while (i >= 0) {
186
- #{mod = `mods[i]`};
187
-
169
+ mod = mods[i];
188
170
  define_iclass(this, mod);
189
-
190
- #{mod.append_features self};
191
- #{mod.included self};
192
-
171
+ mod.$append_features(this);
172
+ mod.$included(this);
193
173
  i--;
194
174
  }
195
175
 
@@ -207,11 +187,11 @@ class Module
207
187
 
208
188
  def module_eval(&block)
209
189
  %x{
210
- if (block === null) {
211
- throw RubyLocalJumpError.$new('no block given');
190
+ if (block === nil) {
191
+ no_block_given();
212
192
  }
213
193
 
214
- return block.call(this, null);
194
+ return block.call(this);
215
195
  }
216
196
  end
217
197
 
@@ -1,4 +1,8 @@
1
- class Numeric
1
+ class Numeric < `Number`
2
+ %x{
3
+ def._isNumber = true;
4
+ }
5
+
2
6
  include Comparable
3
7
 
4
8
  def +(other)
@@ -113,6 +117,8 @@ class Numeric
113
117
  }
114
118
  end
115
119
 
120
+ alias eql? ==
121
+
116
122
  def even?
117
123
  `this % 2 === 0`
118
124
  end
@@ -14,4 +14,4 @@ class Object
14
14
  def singleton_methods
15
15
  []
16
16
  end
17
- end
17
+ end
@@ -1,6 +1,10 @@
1
- class Proc
1
+ class Proc < `Function`
2
+ %x{
3
+ def._isProc = true;
4
+ }
5
+
2
6
  def self.new(&block)
3
- raise ArgumentError, 'tried to create Proc object without a block' unless block_given?
7
+ `if (block === nil) no_block_given();`
4
8
 
5
9
  block
6
10
  end
@@ -1,18 +1,20 @@
1
- # Helper function on runtime for creating range literals
2
- %x{
3
- Opal.range = function(beg, end, exc) {
4
- var range = new RubyRange._alloc();
5
- range.begin = beg;
6
- range.end = end;
7
- range.exclude = exc;
8
-
9
- return range;
10
- };
11
- }
12
-
13
1
  class Range
14
2
  include Enumerable
15
3
 
4
+ %x{
5
+ var range_class = this;
6
+ def._isRange = true;
7
+
8
+ Opal.range = function(beg, end, exc) {
9
+ var range = new range_class._alloc();
10
+ range.begin = beg;
11
+ range.end = end;
12
+ range.exclude = exc;
13
+
14
+ return range;
15
+ };
16
+ }
17
+
16
18
  def initialize(min, max, exclude = false)
17
19
  @begin = min
18
20
  @end = max
@@ -73,23 +75,9 @@ class Range
73
75
  `return obj >= this.begin && obj <= this.end`
74
76
  end
75
77
 
76
- def max
77
- if block_given?
78
- # I actually don't get what this should do
79
- raise NotImplementedError
80
- else
81
- `this.end`
82
- end
83
- end
78
+ alias max end
84
79
 
85
- def min
86
- if block_given?
87
- # I actually don't get what this should do
88
- raise NotImplementedError
89
- else
90
- `this.begin`
91
- end
92
- end
80
+ alias min begin
93
81
 
94
82
  alias member? include?
95
83