opal 0.3.11 → 0.3.15

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 (282) hide show
  1. data/.gitignore +13 -0
  2. data/Gemfile +10 -0
  3. data/LICENSE +20 -0
  4. data/README.md +11 -116
  5. data/Rakefile +126 -0
  6. data/bin/opal +1 -2
  7. data/docs/spec_runner.html +16 -0
  8. data/index.html +434 -0
  9. data/lib/opal.rb +14 -15
  10. data/lib/opal/builder.rb +46 -148
  11. data/lib/opal/command.rb +45 -115
  12. data/lib/opal/context.rb +139 -78
  13. data/lib/opal/dependency_builder.rb +34 -0
  14. data/lib/opal/environment.rb +92 -0
  15. data/lib/opal/parser/grammar.rb +4915 -0
  16. data/lib/opal/{parser.y → parser/grammar.y} +430 -284
  17. data/lib/opal/parser/lexer.rb +1329 -0
  18. data/lib/opal/parser/parser.rb +1460 -0
  19. data/lib/opal/parser/scope.rb +140 -0
  20. data/lib/opal/parser/sexp.rb +17 -0
  21. data/lib/opal/version.rb +2 -1
  22. data/opal.gemspec +23 -0
  23. data/opal.js +3149 -4162
  24. data/runtime/README.md +25 -0
  25. data/runtime/corelib/alpha.rb +10 -0
  26. data/runtime/corelib/array.rb +962 -0
  27. data/runtime/corelib/basic_object.rb +66 -0
  28. data/runtime/corelib/boolean.rb +44 -0
  29. data/runtime/corelib/class.rb +43 -0
  30. data/runtime/corelib/comparable.rb +25 -0
  31. data/runtime/corelib/complex.rb +2 -0
  32. data/runtime/corelib/dir.rb +29 -0
  33. data/runtime/corelib/enumerable.rb +316 -0
  34. data/runtime/corelib/enumerator.rb +80 -0
  35. data/runtime/corelib/error.rb +25 -0
  36. data/runtime/corelib/file.rb +80 -0
  37. data/runtime/corelib/hash.rb +503 -0
  38. data/runtime/corelib/io.rb +44 -0
  39. data/runtime/corelib/kernel.rb +237 -0
  40. data/runtime/corelib/load_order +29 -0
  41. data/runtime/corelib/match_data.rb +37 -0
  42. data/runtime/corelib/module.rb +171 -0
  43. data/runtime/corelib/native.rb +50 -0
  44. data/runtime/corelib/nil_class.rb +47 -0
  45. data/runtime/corelib/numeric.rb +219 -0
  46. data/runtime/corelib/object.rb +21 -0
  47. data/runtime/corelib/proc.rb +42 -0
  48. data/runtime/corelib/range.rb +38 -0
  49. data/runtime/corelib/rational.rb +16 -0
  50. data/runtime/corelib/regexp.rb +63 -0
  51. data/runtime/corelib/string.rb +185 -0
  52. data/runtime/corelib/struct.rb +97 -0
  53. data/runtime/corelib/time.rb +196 -0
  54. data/runtime/corelib/top_self.rb +7 -0
  55. data/runtime/gemlib/alpha.rb +5 -0
  56. data/runtime/gemlib/kernel.rb +17 -0
  57. data/runtime/gemlib/load_order +2 -0
  58. data/runtime/kernel/class.js +256 -0
  59. data/runtime/kernel/debug.js +42 -0
  60. data/runtime/kernel/init.js +114 -0
  61. data/runtime/kernel/load_order +5 -0
  62. data/runtime/kernel/loader.js +151 -0
  63. data/runtime/kernel/runtime.js +414 -0
  64. data/runtime/spec/README.md +34 -0
  65. data/runtime/spec/core/array/allocate_spec.rb +15 -0
  66. data/runtime/spec/core/array/append_spec.rb +31 -0
  67. data/runtime/spec/core/array/assoc_spec.rb +29 -0
  68. data/runtime/spec/core/array/at_spec.rb +38 -0
  69. data/runtime/spec/core/array/clear_spec.rb +22 -0
  70. data/runtime/spec/core/array/collect_spec.rb +3 -0
  71. data/runtime/spec/core/array/compact_spec.rb +42 -0
  72. data/runtime/spec/core/array/concat_spec.rb +21 -0
  73. data/runtime/spec/core/array/constructor_spec.rb +24 -0
  74. data/runtime/spec/core/array/count_spec.rb +11 -0
  75. data/runtime/spec/core/array/delete_at_spec.rb +31 -0
  76. data/runtime/spec/core/array/delete_if_spec.rb +24 -0
  77. data/runtime/spec/core/array/delete_spec.rb +26 -0
  78. data/runtime/spec/core/array/each_index_spec.rb +33 -0
  79. data/runtime/spec/core/array/each_spec.rb +11 -0
  80. data/runtime/spec/core/array/element_reference_spec.rb +136 -0
  81. data/runtime/spec/core/array/element_set_spec.rb +7 -0
  82. data/runtime/spec/core/array/empty_spec.rb +10 -0
  83. data/runtime/spec/core/array/eql_spec.rb +3 -0
  84. data/runtime/spec/core/array/equal_value_spec.rb +3 -0
  85. data/runtime/spec/core/array/fetch_spec.rb +26 -0
  86. data/runtime/spec/core/array/first_spec.rb +54 -0
  87. data/runtime/spec/core/array/fixtures/classes.rb +8 -0
  88. data/runtime/spec/core/array/flatten_spec.rb +41 -0
  89. data/runtime/spec/core/array/include_spec.rb +20 -0
  90. data/runtime/spec/core/array/insert_spec.rb +59 -0
  91. data/runtime/spec/core/array/last_spec.rb +57 -0
  92. data/runtime/spec/core/array/length_spec.rb +3 -0
  93. data/runtime/spec/core/array/map_spec.rb +3 -0
  94. data/runtime/spec/core/array/plus_spec.rb +16 -0
  95. data/runtime/spec/core/array/pop_spec.rb +79 -0
  96. data/runtime/spec/core/array/push_spec.rb +19 -0
  97. data/runtime/spec/core/array/rassoc_spec.rb +12 -0
  98. data/runtime/spec/core/array/reject_spec.rb +54 -0
  99. data/runtime/spec/core/array/replace_spec.rb +3 -0
  100. data/runtime/spec/core/array/reverse_each_spec.rb +18 -0
  101. data/runtime/spec/core/array/reverse_spec.rb +9 -0
  102. data/runtime/spec/core/array/shared/collect.rb +53 -0
  103. data/runtime/spec/core/array/shared/eql.rb +19 -0
  104. data/runtime/spec/core/array/shared/length.rb +6 -0
  105. data/runtime/spec/core/array/shared/replace.rb +31 -0
  106. data/runtime/spec/core/class/new_spec.rb +19 -0
  107. data/runtime/spec/core/enumerable/all_spec.rb +102 -0
  108. data/runtime/spec/core/enumerable/any_spec.rb +115 -0
  109. data/runtime/spec/core/enumerable/collect_spec.rb +3 -0
  110. data/runtime/spec/core/enumerable/count_spec.rb +29 -0
  111. data/runtime/spec/core/enumerable/detect_spec.rb +3 -0
  112. data/runtime/spec/core/enumerable/find_spec.rb +3 -0
  113. data/runtime/spec/core/enumerable/fixtures/classes.rb +26 -0
  114. data/runtime/spec/core/enumerable/shared/collect.rb +12 -0
  115. data/runtime/spec/core/enumerable/shared/entries.rb +7 -0
  116. data/runtime/spec/core/enumerable/shared/find.rb +49 -0
  117. data/runtime/spec/core/enumerable/to_a_spec.rb +7 -0
  118. data/runtime/spec/core/false/and_spec.rb +11 -0
  119. data/runtime/spec/core/false/inspect_spec.rb +7 -0
  120. data/runtime/spec/core/false/or_spec.rb +11 -0
  121. data/runtime/spec/core/false/to_s_spec.rb +7 -0
  122. data/runtime/spec/core/false/xor_spec.rb +11 -0
  123. data/runtime/spec/core/hash/allocate_spec.rb +15 -0
  124. data/runtime/spec/core/hash/assoc_spec.rb +29 -0
  125. data/runtime/spec/core/hash/clear_spec.rb +21 -0
  126. data/runtime/spec/core/hash/clone_spec.rb +12 -0
  127. data/runtime/spec/core/hash/default_spec.rb +6 -0
  128. data/runtime/spec/core/hash/delete_if_spec.rb +15 -0
  129. data/runtime/spec/core/hash/element_reference_spec.rb +16 -0
  130. data/runtime/spec/core/hash/element_set_spec.rb +8 -0
  131. data/runtime/spec/core/hash/new_spec.rb +13 -0
  132. data/runtime/spec/core/matchdata/to_a_spec.rb +7 -0
  133. data/runtime/spec/core/nil/and_spec.rb +12 -0
  134. data/runtime/spec/core/nil/inspect_spec.rb +8 -0
  135. data/runtime/spec/core/nil/nil_spec.rb +8 -0
  136. data/runtime/spec/core/nil/or_spec.rb +12 -0
  137. data/runtime/spec/core/nil/to_a_spec.rb +8 -0
  138. data/runtime/spec/core/nil/to_f_spec.rb +12 -0
  139. data/runtime/spec/core/nil/to_i_spec.rb +12 -0
  140. data/runtime/spec/core/nil/to_s_spec.rb +8 -0
  141. data/runtime/spec/core/nil/xor_spec.rb +12 -0
  142. data/runtime/spec/core/numeric/equal_value_spec.rb +11 -0
  143. data/runtime/spec/core/object/is_a_spec.rb +2 -0
  144. data/runtime/spec/core/object/shared/kind_of.rb +0 -0
  145. data/runtime/spec/core/regexp/match_spec.rb +23 -0
  146. data/runtime/spec/core/regexp/shared/match.rb +11 -0
  147. data/runtime/spec/core/symbol/to_proc_spec.rb +8 -0
  148. data/runtime/spec/core/true/and_spec.rb +11 -0
  149. data/runtime/spec/core/true/inspect_spec.rb +7 -0
  150. data/runtime/spec/core/true/or_spec.rb +11 -0
  151. data/runtime/spec/core/true/to_s_spec.rb +7 -0
  152. data/runtime/spec/core/true/xor_spec.rb +11 -0
  153. data/runtime/spec/language/alias_spec.rb +25 -0
  154. data/runtime/spec/language/and_spec.rb +62 -0
  155. data/runtime/spec/language/array_spec.rb +68 -0
  156. data/runtime/spec/language/block_spec.rb +105 -0
  157. data/runtime/spec/language/break_spec.rb +49 -0
  158. data/runtime/spec/language/case_spec.rb +165 -0
  159. data/runtime/spec/language/defined_spec.rb +80 -0
  160. data/runtime/spec/language/ensure_spec.rb +82 -0
  161. data/runtime/spec/language/fixtures/block.rb +19 -0
  162. data/runtime/spec/language/fixtures/break.rb +39 -0
  163. data/runtime/spec/language/fixtures/defined.rb +9 -0
  164. data/runtime/spec/language/fixtures/ensure.rb +37 -0
  165. data/runtime/spec/language/fixtures/next.rb +46 -0
  166. data/runtime/spec/language/fixtures/send.rb +36 -0
  167. data/runtime/spec/language/fixtures/super.rb +43 -0
  168. data/runtime/spec/language/hash_spec.rb +43 -0
  169. data/runtime/spec/language/if_spec.rb +278 -0
  170. data/runtime/spec/language/loop_spec.rb +32 -0
  171. data/runtime/spec/language/next_spec.rb +128 -0
  172. data/runtime/spec/language/or_spec.rb +65 -0
  173. data/runtime/spec/language/predefined_spec.rb +21 -0
  174. data/runtime/spec/language/regexp/interpolation_spec.rb +9 -0
  175. data/runtime/spec/language/regexp_spec.rb +7 -0
  176. data/runtime/spec/language/send_spec.rb +105 -0
  177. data/runtime/spec/language/string_spec.rb +4 -0
  178. data/runtime/spec/language/super_spec.rb +18 -0
  179. data/runtime/spec/language/symbol_spec.rb +41 -0
  180. data/runtime/spec/language/undef_spec.rb +16 -0
  181. data/runtime/spec/language/unless_spec.rb +44 -0
  182. data/runtime/spec/language/until_spec.rb +137 -0
  183. data/runtime/spec/language/variables_spec.rb +28 -0
  184. data/runtime/spec/language/versions/hash_1.9.rb +20 -0
  185. data/runtime/spec/language/while_spec.rb +175 -0
  186. data/runtime/spec/library/stringscanner/scan_spec.rb +36 -0
  187. data/runtime/spec/opal/forwardable/def_instance_delegator_spec.rb +49 -0
  188. data/runtime/spec/opal/opal/defined_spec.rb +15 -0
  189. data/runtime/spec/opal/opal/function_spec.rb +11 -0
  190. data/runtime/spec/opal/opal/native_spec.rb +16 -0
  191. data/runtime/spec/opal/opal/null_spec.rb +10 -0
  192. data/runtime/spec/opal/opal/number_spec.rb +11 -0
  193. data/runtime/spec/opal/opal/object_spec.rb +16 -0
  194. data/runtime/spec/opal/opal/string_spec.rb +11 -0
  195. data/runtime/spec/opal/opal/typeof_spec.rb +9 -0
  196. data/runtime/spec/opal/opal/undefined_spec.rb +10 -0
  197. data/runtime/spec/opal/true/case_compare_spec.rb +12 -0
  198. data/runtime/spec/opal/true/class_spec.rb +10 -0
  199. data/runtime/spec/spec_helper.rb +25 -0
  200. data/runtime/stdlib/base64.rb +91 -0
  201. data/runtime/stdlib/date.rb +4 -0
  202. data/{stdlib → runtime/stdlib}/dev.rb +0 -0
  203. data/runtime/stdlib/forwardable.rb +33 -0
  204. data/runtime/stdlib/optparse.rb +0 -0
  205. data/runtime/stdlib/pp.rb +6 -0
  206. data/{stdlib → runtime/stdlib}/racc/parser.rb +0 -0
  207. data/runtime/stdlib/rbconfig.rb +0 -0
  208. data/runtime/stdlib/si.rb +17 -0
  209. data/runtime/stdlib/strscan.rb +53 -0
  210. data/runtime/stdlib/uri.rb +111 -0
  211. data/runtime/stdlib/uri/common.rb +1014 -0
  212. data/runtime/stdlib/uri/ftp.rb +261 -0
  213. data/runtime/stdlib/uri/generic.rb +1599 -0
  214. data/runtime/stdlib/uri/http.rb +106 -0
  215. data/runtime/stdlib/uri/https.rb +22 -0
  216. data/runtime/stdlib/uri/ldap.rb +260 -0
  217. data/runtime/stdlib/uri/ldaps.rb +20 -0
  218. data/runtime/stdlib/uri/mailto.rb +280 -0
  219. data/spec/builder/build_source_spec.rb +52 -0
  220. data/spec/builder/fixtures/build_source/adam.rb +0 -0
  221. data/spec/builder/fixtures/build_source/bar/a.rb +0 -0
  222. data/spec/builder/fixtures/build_source/bar/wow/b.rb +0 -0
  223. data/spec/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
  224. data/spec/builder/fixtures/build_source/beynon.rb +0 -0
  225. data/spec/builder/fixtures/build_source/charles.js +0 -0
  226. data/spec/builder/fixtures/build_source/foo/a.rb +0 -0
  227. data/spec/builder/fixtures/build_source/foo/b.rb +0 -0
  228. data/spec/builder/fixtures/build_source/foo/x.js +0 -0
  229. data/spec/builder/fixtures/build_source/foo/y.js +0 -0
  230. data/spec/builder/output_path_spec.rb +50 -0
  231. data/spec/grammar/alias_spec.rb +26 -0
  232. data/spec/grammar/and_spec.rb +13 -0
  233. data/spec/grammar/array_spec.rb +22 -0
  234. data/spec/grammar/attrasgn_spec.rb +28 -0
  235. data/spec/grammar/begin_spec.rb +38 -0
  236. data/spec/grammar/block_spec.rb +12 -0
  237. data/spec/grammar/break_spec.rb +17 -0
  238. data/spec/grammar/call_spec.rb +58 -0
  239. data/spec/grammar/class_spec.rb +35 -0
  240. data/spec/grammar/const_spec.rb +13 -0
  241. data/spec/grammar/cvar_spec.rb +11 -0
  242. data/spec/grammar/def_spec.rb +60 -0
  243. data/spec/grammar/false_spec.rb +17 -0
  244. data/spec/grammar/file_spec.rb +7 -0
  245. data/spec/grammar/gvar_spec.rb +13 -0
  246. data/spec/grammar/hash_spec.rb +17 -0
  247. data/spec/grammar/iasgn_spec.rb +9 -0
  248. data/spec/grammar/if_spec.rb +26 -0
  249. data/spec/grammar/iter_spec.rb +59 -0
  250. data/spec/grammar/ivar_spec.rb +9 -0
  251. data/spec/grammar/lasgn_spec.rb +8 -0
  252. data/spec/grammar/line_spec.rb +8 -0
  253. data/spec/grammar/lvar_spec.rb +38 -0
  254. data/spec/grammar/module_spec.rb +27 -0
  255. data/spec/grammar/nil_spec.rb +17 -0
  256. data/spec/grammar/not_spec.rb +27 -0
  257. data/spec/grammar/op_asgn1_spec.rb +23 -0
  258. data/spec/grammar/op_asgn2_spec.rb +23 -0
  259. data/spec/grammar/or_spec.rb +13 -0
  260. data/spec/grammar/return_spec.rb +17 -0
  261. data/spec/grammar/sclass_spec.rb +20 -0
  262. data/spec/grammar/self_spec.rb +17 -0
  263. data/spec/grammar/str_spec.rb +96 -0
  264. data/spec/grammar/super_spec.rb +20 -0
  265. data/spec/grammar/true_spec.rb +17 -0
  266. data/spec/grammar/undef_spec.rb +15 -0
  267. data/spec/grammar/unless_spec.rb +13 -0
  268. data/spec/grammar/while_spec.rb +15 -0
  269. data/spec/grammar/xstr_spec.rb +116 -0
  270. data/spec/grammar/yield_spec.rb +20 -0
  271. data/spec/spec_helper.rb +9 -0
  272. metadata +346 -21
  273. data/lib/opal/bundle.rb +0 -34
  274. data/lib/opal/lexer.rb +0 -902
  275. data/lib/opal/nodes.rb +0 -2150
  276. data/lib/opal/parser.rb +0 -4894
  277. data/lib/opal/rake/bundle_task.rb +0 -63
  278. data/opal-parser.js +0 -8343
  279. data/stdlib/strscan.rb +0 -52
  280. data/templates/init/Rakefile +0 -7
  281. data/templates/init/index.html +0 -17
  282. data/templates/init/lib/__NAME__.rb +0 -2
@@ -0,0 +1,44 @@
1
+ class IO
2
+ def puts(*args)
3
+ return flush if args.empty?
4
+
5
+ args.each do |a|
6
+ write a.to_s
7
+ flush
8
+ end
9
+ end
10
+
11
+ def print(*args)
12
+ args.each { |a| write a.to_s }
13
+
14
+ nil
15
+ end
16
+
17
+ def write()
18
+ # erm..
19
+ end
20
+
21
+ def flush
22
+ self
23
+ end
24
+ end
25
+
26
+ STDOUT = $stdout = IO.new
27
+
28
+ class << $stdout
29
+ # private variable used to buffer stdout until flush
30
+ `var stdout_buffer = [];`
31
+
32
+ def write(str)
33
+ `stdout_buffer.push(str);`
34
+
35
+ nil
36
+ end
37
+
38
+ def flush
39
+ `console.log(stdout_buffer.join(''));`
40
+ `stdout_buffer = [];`
41
+
42
+ nil
43
+ end
44
+ end
@@ -0,0 +1,237 @@
1
+ module Kernel
2
+ def =~(obj)
3
+ false
4
+ end
5
+
6
+ def ===(other)
7
+ `this == other`
8
+ end
9
+
10
+ def Object (object)
11
+ Opal.native?(object) ? Native::Object.new(object) : object
12
+ end
13
+
14
+ def Array(object)
15
+ return [] unless object
16
+
17
+ unless Opal.native?(object)
18
+ return object.to_ary if object.respond_to? :to_ary
19
+ return object.to_a if object.respond_to? :to_a
20
+ end
21
+
22
+ %x{
23
+ var length = object.length || 0,
24
+ result = new Array(length);
25
+
26
+ while (length--) {
27
+ result[length] = object[length];
28
+ }
29
+
30
+ return result;
31
+ }
32
+ end
33
+
34
+ def at_exit(&block)
35
+ %x{
36
+ if (block === nil) {
37
+ raise(RubyArgError, 'called without a block');
38
+ }
39
+
40
+ end_procs.push(block);
41
+
42
+ return block;
43
+ }
44
+ end
45
+
46
+ def class
47
+ `class_real(this.$klass)`
48
+ end
49
+
50
+ def define_singleton_method(&body)
51
+ %x{
52
+ if (body === nil) {
53
+ raise(RubyLocalJumpError, 'no block given');
54
+ }
55
+
56
+ $opal.ds(this, name, body);
57
+
58
+ return this;
59
+ }
60
+ end
61
+
62
+ def equal?(other)
63
+ `this === other`
64
+ end
65
+
66
+ def extend(*mods)
67
+ %x{
68
+ for (var i = 0, length = mods.length; i < length; i++) {
69
+ include_module(singleton_class(this), mods[i]);
70
+ }
71
+
72
+ return this;
73
+ }
74
+ end
75
+
76
+ def hash
77
+ `this.$id`
78
+ end
79
+
80
+ def inspect
81
+ to_s
82
+ end
83
+
84
+ def instance_of?(klass)
85
+ `this.$klass === klass`
86
+ end
87
+
88
+ def instance_variable_defined?(name)
89
+ `this.hasOwnProperty(name.substr(1));`
90
+ end
91
+
92
+ def instance_variable_get(name)
93
+ %x{
94
+ var ivar = this[name.substr(1)];
95
+
96
+ return ivar == undefined ? nil : ivar;
97
+ }
98
+ end
99
+
100
+ def instance_variable_set(name, value)
101
+ `this[name.substr(1)] = value`
102
+ end
103
+
104
+ def instance_variables
105
+ %x{
106
+ var result = [];
107
+
108
+ for (var name in this) {
109
+ result.push(name);
110
+ }
111
+
112
+ return result;
113
+ }
114
+ end
115
+
116
+ def is_a?(klass)
117
+ %x{
118
+ var search = this.$klass;
119
+
120
+ while (search) {
121
+ if (search === klass) {
122
+ return true;
123
+ }
124
+
125
+ search = search.$s;
126
+ }
127
+
128
+ return false;
129
+ }
130
+ end
131
+
132
+ alias_method :kind_of?, :is_a?
133
+
134
+ def lambda(&block)
135
+ block
136
+ end
137
+
138
+ def loop(&block)
139
+ return enum_for :loop unless block_given?
140
+
141
+ %x{
142
+ while (true) {
143
+ if ($yield.call($context, null) === breaker) {
144
+ return breaker.$v;
145
+ }
146
+ }
147
+
148
+ return this;
149
+ }
150
+ end
151
+
152
+ def nil?
153
+ false
154
+ end
155
+
156
+ def object_id
157
+ `this.$id || (this.$id = unique_id++)`
158
+ end
159
+
160
+ def print(*strs)
161
+ $stdout.print *strs
162
+ end
163
+
164
+ def proc(&block)
165
+ block
166
+ end
167
+
168
+ def puts(*strs)
169
+ $stdout.puts *strs
170
+ end
171
+
172
+ def raise(exception, string = undefined)
173
+ %x{
174
+ if (#{Opal.string?(exception)}) {
175
+ exception = #{`RubyRuntimeError`.new `exception`};
176
+ }
177
+ else if (#{!exception.is_a? `RubyException`}) {
178
+ exception = #{`exception`.new string};
179
+ }
180
+
181
+ throw exception;
182
+ }
183
+ end
184
+
185
+ def rand(max = undefined)
186
+ `max === undefined ? Math.random() : Math.floor(Math.random() * max)`
187
+ end
188
+
189
+ def require(path)
190
+ %x{
191
+ var resolved = find_lib(path);
192
+
193
+ if (!resolved) {
194
+ raise(RubyLoadError, 'no such file to load -- ' + path);
195
+ }
196
+
197
+ if (LOADER_CACHE[resolved]) {
198
+ return false;
199
+ }
200
+
201
+ LOADER_CACHE[resolved] = true;
202
+ $opal.FILE = resolved;
203
+ FACTORIES[resolved].call(top_self, resolved, $opal);
204
+
205
+ return true;
206
+ }
207
+ end
208
+
209
+ def respond_to?(name)
210
+ %x{
211
+ var meth = this[mid_to_jsid(name)];
212
+ return !!meth;
213
+ }
214
+ end
215
+
216
+ def singleton_class
217
+ `singleton_class(this)`
218
+ end
219
+
220
+ def tap(&block)
221
+ %x{
222
+ if (block === nil) {
223
+ raise(RubyLocalJumpError, 'no block given');
224
+ }
225
+
226
+ if ($yield.call($context, null, this) === breaker) {
227
+ return breaker.$v;
228
+ }
229
+
230
+ return this;
231
+ }
232
+ end
233
+
234
+ def to_s
235
+ `inspect_object(this)`
236
+ end
237
+ end
@@ -0,0 +1,29 @@
1
+ alpha
2
+ module
3
+ class
4
+ kernel
5
+ basic_object
6
+ object
7
+ top_self
8
+ boolean
9
+ nil_class
10
+ native
11
+ enumerable
12
+ comparable
13
+ enumerator
14
+ array
15
+ hash
16
+ string
17
+ numeric
18
+ rational
19
+ complex
20
+ proc
21
+ range
22
+ error
23
+ regexp
24
+ match_data
25
+ struct
26
+ time
27
+ io
28
+ file
29
+ dir
@@ -0,0 +1,37 @@
1
+ class MatchData
2
+ def [](index)
3
+ %x{
4
+ var length = this.$data.length;
5
+
6
+ if (index < 0) {
7
+ index += length;
8
+ }
9
+
10
+ if (index >= length || index < 0) {
11
+ return nil;
12
+ }
13
+
14
+ return this.$data[index];
15
+ }
16
+ end
17
+
18
+ def length
19
+ `this.$data.length`
20
+ end
21
+
22
+ def inspect
23
+ "#<MatchData #{self[0].inspect}>"
24
+ end
25
+
26
+ alias_method :size, :length
27
+
28
+ def to_a
29
+ `[].slice.call(this.$data, 0)`
30
+ end
31
+
32
+ alias to_native to_a
33
+
34
+ def to_s
35
+ `this.$data[0]`
36
+ end
37
+ end
@@ -0,0 +1,171 @@
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(mod)
30
+ `include_module(mod, this)`
31
+
32
+ self
33
+ end
34
+
35
+ def attr_accessor(*attrs)
36
+ %x{
37
+ for (var i = 0, length = attrs.length; i < length; i++) {
38
+ define_attr(this, attrs[i], true, true);
39
+ }
40
+
41
+ return nil;
42
+ }
43
+ end
44
+
45
+ def attr_accessor_bridge(target, *attrs)
46
+ %x{
47
+ for (var i = 0, length = attrs.length; i < length; i++) {
48
+ define_attr_bridge(this, target, attrs[i], true, true);
49
+ }
50
+
51
+ return nil;
52
+ }
53
+ end
54
+
55
+ def attr_reader(*attrs)
56
+ %x{
57
+ for (var i = 0, length = attrs.length; i < length; i++) {
58
+ define_attr(this, attrs[i], true, false);
59
+ }
60
+
61
+ return nil;
62
+ }
63
+ end
64
+
65
+ def attr_reader_bridge(target, *attrs)
66
+ %x{
67
+ for (var i = 0, length = attrs.length; i < length; i++) {
68
+ define_attr_bridge(this, target, attrs[i], true, false);
69
+ }
70
+
71
+ return nil;
72
+ }
73
+ end
74
+
75
+ def attr_writer(*attrs)
76
+ %x{
77
+ for (var i = 0, length = attrs.length; i < length; i++) {
78
+ define_attr(this, attrs[i], false, true);
79
+ }
80
+
81
+ return nil;
82
+ }
83
+ end
84
+
85
+ def attr_reader_bridge(target, *attrs)
86
+ %x{
87
+ for (var i = 0, length = attrs.length; i < length; i++) {
88
+ define_attr_bridge(this, target, attrs[i], false, true);
89
+ }
90
+
91
+ return nil;
92
+ }
93
+ end
94
+
95
+ def attr(name, setter = false)
96
+ `define_attr(this, name, true, setter)`
97
+
98
+ self
99
+ end
100
+
101
+ def attr_bridge(target, name, setter = false)
102
+ `define_attr_bridge(this, target, name, true, setter)`
103
+
104
+ self
105
+ end
106
+
107
+ def define_method(name, &body)
108
+ %x{
109
+ if (body === nil) {
110
+ raise(RubyLocalJumpError, 'no block given');
111
+ }
112
+
113
+ define_method(this, mid_to_jsid(name), body);
114
+ this.$methods.push(name);
115
+
116
+ return nil;
117
+ }
118
+ end
119
+
120
+ def define_method_bridge(object, name, ali = nil)
121
+ %x{
122
+ define_method_bridge(this, object, mid_to_jsid(#{ali || name}), name);
123
+ this.$methods.push(name);
124
+
125
+ return nil;
126
+ }
127
+ end
128
+
129
+ def include(*mods)
130
+ %x{
131
+ var i = mods.length - 1, mod;
132
+ while (i >= 0) {
133
+ #{mod = `mods[i]`};
134
+ #{mod.append_features self};
135
+ #{mod.included self};
136
+
137
+ i--;
138
+ }
139
+
140
+ return this;
141
+ }
142
+ end
143
+
144
+ def instance_methods
145
+ `this.$methods`
146
+ end
147
+
148
+ def included(mod)
149
+ nil
150
+ end
151
+
152
+ def module_eval(&block)
153
+ %x{
154
+ if (block === nil) {
155
+ raise(RubyLocalJumpError, 'no block given');
156
+ }
157
+
158
+ return block.call(this, null);
159
+ }
160
+ end
161
+
162
+ alias_method :class_eval, :module_eval
163
+
164
+ def name
165
+ `this.__classid__`
166
+ end
167
+
168
+ alias_method :public_instance_methods, :instance_methods
169
+
170
+ alias_method :to_s, :name
171
+ end