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.
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
@@ -8,21 +8,14 @@ class BasicObject
8
8
 
9
9
  def __send__(symbol, *args, &block)
10
10
  %x{
11
- var meth = this[mid_to_jsid(symbol)];
11
+ var meth = this[mid_to_jsid(symbol)] || $opal.mm(mid_to_jsid(symbol));
12
12
 
13
- if (meth) {
14
- args.unshift(null);
15
-
16
- return meth.apply(this, args);
17
- }
18
- else {
19
- throw new Error("method missing yielder for " + symbol + " in __send__");
20
- }
13
+ return meth.apply(this, args);
21
14
  }
22
15
  end
23
16
 
24
17
  alias send __send__
25
-
18
+
26
19
  alias eql? ==
27
20
  alias equal? ==
28
21
 
@@ -32,7 +25,7 @@ class BasicObject
32
25
  raise(RubyArgError, 'block not supplied');
33
26
  }
34
27
 
35
- return block.call(this, null, this);
28
+ return block.call(this, this);
36
29
  }
37
30
  end
38
31
 
@@ -42,25 +35,21 @@ class BasicObject
42
35
  raise(RubyArgError, 'block not supplied');
43
36
  }
44
37
 
45
- args.unshift(null);
46
-
47
38
  return block.apply(this, args);
48
39
  }
49
40
  end
50
41
 
51
42
  def method_missing(symbol, *args)
52
- `raise(RubyNoMethodError, 'undefined method \`' + symbol + '\` for ' + #{inspect})`
43
+ `throw RubyNoMethodError.$new('undefined method \`' + symbol + '\` for ' + #{inspect});`
44
+ self
53
45
  end
54
46
 
55
47
  def singleton_method_added(symbol)
56
- nil
57
48
  end
58
49
 
59
50
  def singleton_method_removed(symbol)
60
- nil
61
51
  end
62
52
 
63
53
  def singleton_method_undefined(symbol)
64
- nil
65
54
  end
66
55
  end
data/core/boolean.rb ADDED
@@ -0,0 +1,40 @@
1
+ class Boolean
2
+ def &(other)
3
+ `(this == true) ? (other !== false && other !== nil) : false`
4
+ end
5
+
6
+ def |(other)
7
+ `(this == true) ? true : (other !== false && other !== nil)`
8
+ end
9
+
10
+ def ^(other)
11
+ `(this == true) ? (other === false || other === nil) : (other !== false && other !== nil)`
12
+ end
13
+
14
+ def ==(other)
15
+ `(this == true) === other.valueOf()`
16
+ end
17
+
18
+ def class
19
+ `(this == true) ? #{TrueClass} : #{FalseClass}`
20
+ end
21
+
22
+ def to_s
23
+ `(this == true) ? 'true' : 'false'`
24
+ end
25
+ end
26
+
27
+ class TrueClass
28
+ def self.===(obj)
29
+ `obj === true`
30
+ end
31
+ end
32
+
33
+ class FalseClass
34
+ def self.===(obj)
35
+ `obj === false`
36
+ end
37
+ end
38
+
39
+ TRUE = true
40
+ FALSE = false
data/core/class.rb ADDED
@@ -0,0 +1,69 @@
1
+ class Class
2
+ def self.new(sup = Object, &block)
3
+ %x{
4
+ var klass = boot_class(sup);
5
+ klass.$name = "AnonClass";
6
+
7
+ make_metaclass(klass, sup.$klass);
8
+
9
+ #{sup.inherited `klass`};
10
+
11
+ return block !== nil ? block.call(klass, null) : klass;
12
+ }
13
+ end
14
+
15
+ def bridge_class(constructor)
16
+ %x{
17
+ var prototype = constructor.prototype,
18
+ klass = this;
19
+
20
+ klass.$allocator = constructor;
21
+ klass.$proto = prototype;
22
+
23
+ bridged_classes.push(klass);
24
+
25
+ prototype.$klass = klass;
26
+ prototype.$flags = T_OBJECT;
27
+
28
+ var donator = RubyObject.$proto;
29
+ for (var method in donator) {
30
+ if (donator.hasOwnProperty(method)) {
31
+ if (!prototype[method]) {
32
+ prototype[method] = donator[method];
33
+ }
34
+ }
35
+ }
36
+
37
+ return klass;
38
+ }
39
+ end
40
+
41
+ def allocate
42
+ `new this.$allocator()`
43
+ end
44
+
45
+ def new(*args, &block)
46
+ obj = allocate()
47
+ obj.initialize *args, &block
48
+ obj
49
+ end
50
+
51
+ def inherited(cls)
52
+ end
53
+
54
+ def superclass
55
+ %x{
56
+ var sup = this.$s;
57
+
58
+ if (!sup) {
59
+ if (this === RubyObject) {
60
+ return nil;
61
+ }
62
+
63
+ raise(RubyRuntimeError, 'uninitialized class');
64
+ }
65
+
66
+ return sup;
67
+ }
68
+ end
69
+ end
File without changes
data/core/debug.js ADDED
@@ -0,0 +1,59 @@
1
+ // ..........................................................
2
+ // DEBUG - this is only included in debug mode
3
+ //
4
+
5
+ // Identify opal as being in debug mode
6
+ opal.debug = true;
7
+
8
+ // An array of every method send in debug mode
9
+ var debug_stack = [];
10
+
11
+ opal.send = function(recv, block, jsid) {
12
+ var args = $slice.call(arguments, 3),
13
+ meth = recv[jsid];
14
+
15
+ if (!meth) {
16
+ args.unshift(jsid_to_mid(jsid));
17
+ return recv.$method_missing.apply(recv, args);
18
+ }
19
+
20
+ // Always set a block. If a block wasn't given then this is just a
21
+ // no-op.
22
+ meth.$P = block;
23
+
24
+ // Push this call frame onto debug stack
25
+ debug_stack.push({
26
+ recv: recv,
27
+ jsid: jsid,
28
+ meth: meth
29
+ });
30
+
31
+ try {
32
+ var result = meth.apply(recv, args);
33
+ }
34
+ catch (err) {
35
+ if (!err.opal_stack) {
36
+ err.opal_stack = debug_stack.slice();
37
+ }
38
+
39
+ throw err;
40
+ }
41
+ finally {
42
+ debug_stack.pop();
43
+ }
44
+
45
+ return result;
46
+ };
47
+
48
+ var release_define_method = define_method;
49
+
50
+ define_method = opal.defn = function(klass, id, body, file, line) {
51
+
52
+ if (!body.$debugFile) {
53
+ body.$debugFile = file;
54
+ body.$debugLine = line;
55
+ body.$debugKlass = klass;
56
+ }
57
+
58
+ return release_define_method(klass, id, body);
59
+ };
data/core/debug.rb ADDED
@@ -0,0 +1,35 @@
1
+ #############################################################
2
+ # DEBUG - only included in debug mode
3
+ #
4
+
5
+ class Exception
6
+ def backtrace
7
+ %x{
8
+ var result = [],
9
+ stack = this.opal_stack || [],
10
+ frame,
11
+ recv,
12
+ meth;
13
+
14
+ for (var i = stack.length - 1; i >= 0; i--) {
15
+ frame = stack[i];
16
+ meth = frame.meth;
17
+ recv = frame.recv;
18
+ klass = meth.$debugKlass;
19
+
20
+ if (recv.$flags & T_OBJECT) {
21
+ recv = class_real(recv.$klass);
22
+ recv = (recv === klass ? recv.$name : klass.$name + '(' + recv.$name + ')') + '#';
23
+ }
24
+ else {
25
+
26
+ recv = recv.$name + '.';
27
+ }
28
+
29
+ result.push('from ' + recv + jsid_to_mid(frame.jsid) + ' at ' + meth.$debugFile + ':' + meth.$debugLine);
30
+ }
31
+
32
+ return result;
33
+ }
34
+ end
35
+ end
data/core/dir.rb ADDED
@@ -0,0 +1,90 @@
1
+ class Dir
2
+ def self.getwd
3
+ `FS_CWD`
4
+ end
5
+
6
+ def self.pwd
7
+ `FS_CWD`
8
+ end
9
+
10
+ def self.[](*globs)
11
+ %x{
12
+ var result = [], files = FACTORIES;
13
+
14
+ for (var i = 0, ii = globs.length; i < ii; i++) {
15
+ var glob = globs[i];
16
+
17
+ var re = fs_glob_to_regexp(#{ File.expand_path `glob` });
18
+
19
+ for (var file in files) {
20
+ if (re.exec(file)) {
21
+ result.push(file);
22
+ }
23
+ }
24
+ }
25
+
26
+ return result;
27
+ }
28
+ end
29
+
30
+ %x(
31
+ function fs_glob_to_regexp(glob) {
32
+ var parts = glob.split(''),
33
+ length = parts.length,
34
+ result = '';
35
+
36
+ var opt_group_stack = 0;
37
+
38
+ for (var i = 0; i < length; i++) {
39
+ var cur = parts[i];
40
+
41
+ switch (cur) {
42
+ case '*':
43
+ if (parts[i + 1] === '*' && parts[i + 2] === '/') {
44
+ result += '.*';
45
+ i += 2;
46
+ }
47
+ else {
48
+ result += '[^/]*';
49
+ }
50
+ break;
51
+
52
+ case '.':
53
+ result += '\\\\';
54
+ result += cur;
55
+ break;
56
+
57
+ case ',':
58
+ if (opt_group_stack) {
59
+ result += '|';
60
+ }
61
+ else {
62
+ result += ',';
63
+ }
64
+ break;
65
+
66
+ case '{':
67
+ result += '(';
68
+ opt_group_stack++;
69
+ break;
70
+
71
+ case '}':
72
+ if (opt_group_stack) {
73
+ result += ')';
74
+ opt_group_stack--;
75
+ }
76
+ else {
77
+ result += '}'
78
+ }
79
+ break;
80
+
81
+ default:
82
+ result += cur;
83
+ }
84
+ }
85
+
86
+ return new RegExp('^' + result + '$');
87
+ }
88
+
89
+ )
90
+ end
@@ -0,0 +1,331 @@
1
+ module Enumerable
2
+ def all?(&block)
3
+ %x{
4
+ var result = true;
5
+
6
+ this.$each.$P = block !== nil
7
+ ? function(obj) {
8
+ var value;
9
+
10
+ if ((value = $yield.call($context, obj)) === $breaker) {
11
+ return $breaker.$v;
12
+ }
13
+
14
+ if (value === false || value === nil) {
15
+ result = false;
16
+ $breaker.$v = nil;
17
+
18
+ return $breaker;
19
+ }
20
+ }
21
+ : function(obj) {
22
+ if (obj === false || obj === nil) {
23
+ result = false;
24
+ $breaker.$v = nil;
25
+
26
+ return $breaker;
27
+ }
28
+ };
29
+
30
+ this.$each();
31
+
32
+ return result;
33
+ }
34
+ end
35
+
36
+ def any?(&block)
37
+ %x{
38
+ var result = false;
39
+
40
+ this.$each.$P = block !== nil
41
+ ? function(obj) {
42
+ var value;
43
+
44
+ if ((value = $yield.call($context, obj)) === $breaker) {
45
+ return $breaker.$v;
46
+ }
47
+
48
+ if (value !== false && value !== nil) {
49
+ result = true;
50
+ $breaker.$v = nil;
51
+
52
+ return $breaker;
53
+ }
54
+ }
55
+ : function(obj) {
56
+ if (obj !== false && obj !== nil) {
57
+ result = true;
58
+ $breaker.$v = nil;
59
+
60
+ return $breaker;
61
+ }
62
+ };
63
+
64
+ this.$each();
65
+
66
+ return result;
67
+ }
68
+ end
69
+
70
+ def collect(&block)
71
+ return enum_for :collect unless block_given?
72
+
73
+ %x{
74
+ var result = [];
75
+
76
+ this.$each.$P = function () {
77
+ var obj = $slice.call(arguments),
78
+ value;
79
+
80
+ if ((value = $yield.apply($context, obj)) === $breaker) {
81
+ return $breaker.$v;
82
+ }
83
+
84
+ result.push(value);
85
+ };
86
+
87
+ this.$each();
88
+
89
+ return result;
90
+ }
91
+ end
92
+
93
+ def count(object = undefined, &block)
94
+ %x{
95
+ var result = 0;
96
+
97
+ if (block === nil) {
98
+ if (object === undefined) {
99
+ $yield = function() { return true; };
100
+ }
101
+ else {
102
+ $yield = function(obj) { return #{`obj` == `object`}; };
103
+ }
104
+ }
105
+
106
+ this.$each.$P = function(obj) {
107
+ var value;
108
+
109
+ if ((value = $yield.call($context, obj)) === $breaker) {
110
+ return $breaker.$v;
111
+ }
112
+
113
+ if (value !== false && value !== nil) {
114
+ result++;
115
+ }
116
+ };
117
+
118
+ this.$each();
119
+
120
+ return result;
121
+ }
122
+ end
123
+
124
+ def detect(ifnone = undefined, &block)
125
+ return enum_for :detect, ifnone unless block
126
+
127
+ %x{
128
+ var result = nil;
129
+
130
+ this.$each.$P = function(obj) {
131
+ var value;
132
+
133
+ if ((value = $yield.call($context, obj)) === $breaker) {
134
+ return $breaker.$v;
135
+ }
136
+
137
+ if (value !== false && value !== nil) {
138
+ result = obj;
139
+ $breaker.$v = nil;
140
+
141
+ return $breaker;
142
+ }
143
+ };
144
+
145
+ this.$each();
146
+
147
+ if (result !== nil) {
148
+ return result;
149
+ }
150
+
151
+ if (typeof(ifnone) === 'function') {
152
+ return ifnone.$call();
153
+ }
154
+
155
+ return ifnone === undefined ? nil : ifnone;
156
+ }
157
+ end
158
+
159
+ def drop(number)
160
+ raise NotImplementedError
161
+
162
+ %x{
163
+ var result = [],
164
+ current = 0;
165
+
166
+ this.$each.$P = function(obj) {
167
+ if (number < current) {
168
+ result.push(e);
169
+ }
170
+
171
+ current++;
172
+ };
173
+
174
+ this.$each();
175
+
176
+ return result;
177
+ }
178
+ end
179
+
180
+ def drop_while(&block)
181
+ return enum_for :drop_while unless block
182
+
183
+ %x{
184
+ var result = [];
185
+
186
+ this.$each.$P = function(obj) {
187
+ var value;
188
+
189
+ if ((value = $yield.call($context, obj)) === $breaker) {
190
+ return $breaker.$v;
191
+ }
192
+
193
+ if (value !== false && value !== nil) {
194
+ result.push(obj);
195
+ }
196
+ else {
197
+ return $breaker;
198
+ }
199
+ };
200
+
201
+ this.$each();
202
+
203
+ return result;
204
+ }
205
+ end
206
+
207
+ def each_with_index(&block)
208
+ return enum_for :each_with_index unless block
209
+
210
+ %x{
211
+ var index = 0;
212
+
213
+ this.$each.$P = function(obj) {
214
+ var value;
215
+
216
+ if ((value = $yield.call($context, obj, index)) === $breaker) {
217
+ return $breaker.$v;
218
+ }
219
+
220
+ index++;
221
+ };
222
+
223
+ this.$each();
224
+
225
+ return nil;
226
+ }
227
+ end
228
+
229
+ def entries
230
+ %x{
231
+ var result = [];
232
+
233
+ this.$each.$P = function(obj) { return result.push(obj); };
234
+ this.$each();
235
+
236
+ return result;
237
+ }
238
+ end
239
+
240
+ alias find detect
241
+
242
+ def find_index(object = undefined, &block)
243
+ return enum_for :find_index, object unless block
244
+
245
+ %x{
246
+ if (object !== undefined) {
247
+ $yield = function (iter, obj) { return obj.$eq$(object); };
248
+ }
249
+
250
+ var result = nil;
251
+
252
+ this.$each_with_index.$P = function(obj, index) {
253
+ var value;
254
+
255
+ if ((value = $yield.call($context, obj)) === $breaker) {
256
+ return $breaker.$v;
257
+ }
258
+
259
+ if (value !== false && value !== nil) {
260
+ result = obj;
261
+ breaker.$v = index;
262
+
263
+ return $breaker;
264
+ }
265
+ };
266
+
267
+ this.$each_with_index();
268
+
269
+ return result;
270
+ }
271
+ end
272
+
273
+ def first(number = undefined)
274
+ %x{
275
+ var result = [],
276
+ current = 0;
277
+
278
+ this.$each.$P = number === undefined
279
+ ? function(obj) {
280
+ result = obj; return $breaker;
281
+ }
282
+ : function(obj) {
283
+ if (number <= current) {
284
+ return $breaker;
285
+ }
286
+
287
+ result.push(obj);
288
+
289
+ current++;
290
+ };
291
+
292
+ this.$each();
293
+
294
+ return result;
295
+ }
296
+ end
297
+
298
+ def grep(pattern, &block)
299
+ %x{
300
+ var result = [];
301
+
302
+ this.$each.$P = block !== nil
303
+ ? function(obj) {
304
+ var value = pattern.$eqq$(obj);
305
+
306
+ if (value !== false && value !== nil) {
307
+ if ((value = $yield.call($context, obj)) === $breaker) {
308
+ return $breaker.$v;
309
+ }
310
+
311
+ result.push(obj);
312
+ }
313
+ }
314
+ : function(obj) {
315
+ var value = pattern.$eqq$(obj);
316
+
317
+ if (value !== false && value !== nil) {
318
+ ary.push(obj);
319
+ }
320
+ };
321
+
322
+ this.$each();
323
+
324
+ return result;
325
+ }
326
+ end
327
+
328
+ alias take first
329
+
330
+ alias to_a entries
331
+ end