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
@@ -1,80 +0,0 @@
1
- # NOTE: our next/peek/rewind implementation is REALLY slow
2
-
3
- class Enumerator
4
- include Enumerable
5
-
6
- class Yielder
7
- def initialize (block)
8
- @block = block
9
- end
10
-
11
- def call (block)
12
- @call = block
13
-
14
- @block.call
15
- end
16
-
17
- def yield (value)
18
- @call.call(value)
19
- end
20
-
21
- alias_method :<<, :yield
22
- end
23
-
24
- class Generator
25
- attr_reader :enumerator
26
-
27
- def initialize (block)
28
- @yielder = Yielder.new(block)
29
- end
30
-
31
- def each (&block)
32
- @yielder.call(block)
33
- end
34
- end
35
-
36
- def initialize (object = nil, method = :each, *args, &block)
37
- if block_given?
38
- @object = Generator.new(block)
39
- method = :each
40
- end
41
-
42
- raise ArgumentError, 'wrong number of argument (0 for 1+)' unless object
43
-
44
- @object = object
45
- @method = method
46
- @args = args
47
-
48
- @current = 0
49
- end
50
-
51
- def next
52
- end
53
-
54
- def each (&block)
55
- return self unless block
56
-
57
- @object.__send__ @method, *args, &block
58
- end
59
-
60
- def each_with_index (&block)
61
- with_index &block
62
- end
63
-
64
- def with_index (offset = 0, &block)
65
- return Enumerator.new(self, :with_index, offset) unless block
66
- end
67
-
68
- def with_object (object, &block)
69
- return Enumerator.new(self, :with_object, object) unless block
70
-
71
- end
72
- end
73
-
74
- module Kernel
75
- def enum_for (method = :each, *args)
76
- Enumerator.new(self, method, *args)
77
- end
78
-
79
- alias_method :to_enum, :enum_for
80
- end
@@ -1,25 +0,0 @@
1
- class Exception
2
- def initialize(message = '')
3
- %x{
4
- if (Error.captureStackTrace) {
5
- Error.captureStackTrace(this);
6
- }
7
-
8
- this.message = message;
9
- }
10
- end
11
-
12
- def backtrace
13
- `this._bt || (this._bt = exc_backtrace(this))`
14
- end
15
-
16
- def inspect
17
- "#<#{self.class}: '#{message}'>"
18
- end
19
-
20
- def message
21
- `this.message`
22
- end
23
-
24
- alias_method :to_s, :message
25
- end
@@ -1,171 +0,0 @@
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
@@ -1,50 +0,0 @@
1
- module Native
2
- class Object
3
- include Native
4
-
5
- def [](name)
6
- `#@native[name]`
7
- end
8
-
9
- def []=(name, value)
10
- `#@native[name] = value`
11
- end
12
-
13
- def nil?
14
- `#@native === null || #@native === undefined`
15
- end
16
-
17
- def method_missing(name, *args)
18
- return super unless Opal.function? `#@native[name]`
19
-
20
- __native_send__ name, *args
21
- end
22
- end
23
-
24
- def self.included (klass)
25
- class << klass
26
- def from_native (object)
27
- instance = allocate
28
- instance.instance_variable_set :@native, object
29
-
30
- instance
31
- end
32
- end
33
- end
34
-
35
- def initialize(native)
36
- @native = native
37
- end
38
-
39
- def to_native
40
- @native
41
- end
42
-
43
- def native_send(name, *args)
44
- return method_missing(name, *args) unless Opal.function? `#@native[name]`
45
-
46
- `#@native[name].apply(#@native, args)`
47
- end
48
-
49
- alias_method :__native_send__, :native_send
50
- end
@@ -1,21 +0,0 @@
1
- class Object
2
- include Kernel
3
-
4
- def methods
5
- `this.$klass.$methods`
6
- end
7
-
8
- alias_method :private_methods, :methods
9
-
10
- alias_method :protected_methods, :methods
11
-
12
- alias_method :public_methods, :methods
13
-
14
- def singleton_methods
15
- raise NotImplementedError, 'Object#singleton_methods not yet implemented'
16
- end
17
-
18
- def to_native
19
- raise TypeError, 'no specialized #to_native has been implemented'
20
- end
21
- end
@@ -1,196 +0,0 @@
1
- class Time
2
- include Native
3
- include Comparable
4
-
5
- def self.at(seconds, frac = 0)
6
- from_native(`new Date(seconds * 1000 + frac)`)
7
- end
8
-
9
- def self.now
10
- from_native(`new Date()`)
11
- end
12
-
13
- def initialize(year = nil, month = nil, day = nil, hour = nil, min = nil, sec = nil, utc_offset = nil)
14
- if year
15
- super(`new Date(#{year.to_native}, #{month.to_native}, #{day.to_native}, #{hour.to_native}, #{min.to_native}, #{sec.to_native})`)
16
- else
17
- super(`new Date()`)
18
- end
19
- end
20
-
21
- def +(other)
22
- from_native(`new Date(#{to_f + other.to_f})`)
23
- end
24
-
25
- def -(other)
26
- from_native(`new Date(#{to_f - other.to_f})`)
27
- end
28
-
29
- def <=>(other)
30
- to_f <=> other.to_f
31
- end
32
-
33
- def asctime
34
- raise NotImplementedError
35
- end
36
-
37
- alias ctime asctime
38
-
39
- def day
40
- `#@native.getDate()`
41
- end
42
-
43
- def dst?
44
- raise NotImplementedError
45
- end
46
-
47
- def eql?(other)
48
- other.is_a?(Time) && (self <=> other).zero?
49
- end
50
-
51
- def friday?
52
- wday == 5
53
- end
54
-
55
- def getgm
56
- raise NotImplementedError
57
- end
58
-
59
- def getlocal (*)
60
- raise NotImplementedError
61
- end
62
-
63
- alias getutc getgm
64
-
65
- def gmt?
66
- raise NotImplementedError
67
- end
68
-
69
- def gmt_offset
70
- raise NotImplementedError
71
- end
72
-
73
- def gmtime
74
- raise NotImplementedError
75
- end
76
-
77
- alias gmtoff gmt_offset
78
-
79
- def hour
80
- `#@native.getHours()`
81
- end
82
-
83
- alias isdst dst?
84
-
85
- def localtime (*)
86
- raise NotImplementedError
87
- end
88
-
89
- alias mday day
90
-
91
- def min
92
- `#@native.getMinutes()`
93
- end
94
-
95
- def mon
96
- `#@native.getMonth() + 1`
97
- end
98
-
99
- def monday?
100
- wday == 1
101
- end
102
-
103
- alias month mon
104
-
105
- def nsec
106
- raise NotImplementedError
107
- end
108
-
109
- def round (*)
110
- raise NotImplementedError
111
- end
112
-
113
- def saturday?
114
- wday == 6
115
- end
116
-
117
- def sec
118
- `#@native.getSeconds()`
119
- end
120
-
121
- def strftime (string)
122
- raise NotImplementedError
123
- end
124
-
125
- def subsec
126
- raise NotImplementedError
127
- end
128
-
129
- def sunday?
130
- wday == 0
131
- end
132
-
133
- def thursday?
134
- wday == 4
135
- end
136
-
137
- def to_a
138
- raise NotImplementedError
139
- end
140
-
141
- def to_f
142
- `#@native.getTime() / 1000`
143
- end
144
-
145
- def to_i
146
- `parseInt(#@native.getTime() / 1000)`
147
- end
148
-
149
- def to_r
150
- raise NotImplementedError
151
- end
152
-
153
- def to_s
154
- raise NotImplementedError
155
- end
156
-
157
- def tuesday?
158
- wday == 2
159
- end
160
-
161
- alias tv_nsec nsec
162
-
163
- alias tv_sec to_i
164
-
165
- def tv_usec
166
- raise NotImplementedError
167
- end
168
-
169
- alias usec tv_usec
170
-
171
- alias utc gmtime
172
-
173
- alias utc? gmt?
174
-
175
- alias utc_offset gmt_offset
176
-
177
- def wday
178
- `#@native.getDay()`
179
- end
180
-
181
- def wednesday?
182
- wday == 3
183
- end
184
-
185
- def yday
186
- raise NotImplementedError
187
- end
188
-
189
- def year
190
- `#@native.getFullYear()`
191
- end
192
-
193
- def zone
194
- raise NotImplementedError
195
- end
196
- end