opal 0.5.0 → 0.5.2
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.
- checksums.yaml +4 -4
- data/Gemfile +0 -2
- data/README.md +1 -1
- data/Rakefile +11 -8
- data/lib/opal.rb +1 -1
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +1 -1
- data/{corelib → opal/core}/array.rb +47 -40
- data/{corelib → opal/core}/basic_object.rb +4 -0
- data/{corelib → opal/core}/boolean.rb +2 -6
- data/{corelib → opal/core}/class.rb +0 -0
- data/{corelib → opal/core}/comparable.rb +0 -0
- data/{corelib → opal/core}/encoding.rb +0 -0
- data/{corelib → opal/core}/enumerable.rb +160 -38
- data/opal/core/enumerator.rb +416 -0
- data/{corelib → opal/core}/error.rb +0 -0
- data/{corelib → opal/core}/hash.rb +38 -48
- data/{corelib → opal/core}/io.rb +13 -9
- data/{corelib → opal/core}/kernel.rb +75 -49
- data/{corelib → opal/core}/main.rb +0 -0
- data/{corelib → opal/core}/match_data.rb +0 -4
- data/{corelib → opal/core}/method.rb +0 -0
- data/{corelib → opal/core}/module.rb +24 -3
- data/{corelib → opal/core}/nil_class.rb +0 -4
- data/{corelib → opal/core}/numeric.rb +3 -4
- data/{corelib → opal/core}/proc.rb +0 -4
- data/{corelib → opal/core}/range.rb +0 -0
- data/{corelib → opal/core}/regexp.rb +0 -4
- data/{corelib → opal/core}/runtime.js +0 -0
- data/{corelib → opal/core}/string.rb +4 -6
- data/{corelib → opal/core}/struct.rb +3 -21
- data/{corelib → opal/core}/time.rb +0 -4
- data/opal/opal.rb +121 -0
- data/spec/corelib/array/select_spec.rb +14 -0
- data/spec/filters/20.rb +4 -0
- data/spec/filters/bugs/enumerable.rb +1 -48
- data/spec/filters/unsupported/enumerator.rb +13 -0
- data/spec/opal/compiler/irb_spec.rb +1 -0
- data/spec/rubyspecs +1 -0
- data/spec/{corelib → stdlib}/native/alias_native_spec.rb +6 -4
- data/spec/{corelib → stdlib}/native/each_spec.rb +3 -1
- data/spec/{corelib → stdlib}/native/element_reference_spec.rb +3 -1
- data/spec/stdlib/native/ext_spec.rb +19 -0
- data/spec/{corelib → stdlib}/native/initialize_spec.rb +4 -4
- data/spec/{corelib → stdlib}/native/method_missing_spec.rb +13 -1
- data/spec/{corelib → stdlib}/native/new_spec.rb +3 -1
- data/stdlib/enumerator.rb +1 -0
- data/stdlib/json.rb +1 -1
- data/stdlib/native.rb +483 -0
- metadata +52 -47
- data/corelib/enumerator.rb +0 -55
- data/corelib/native.rb +0 -270
- data/corelib/opal.rb +0 -88
- data/spec/corelib/native/ext_spec.rb +0 -5
- data/spec/filters/bugs/enumerator.rb +0 -6
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Beynon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: source_map
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.3.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.3.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,33 +126,6 @@ files:
|
|
126
126
|
- Rakefile
|
127
127
|
- bin/opal
|
128
128
|
- bin/opal-repl
|
129
|
-
- corelib/array.rb
|
130
|
-
- corelib/basic_object.rb
|
131
|
-
- corelib/boolean.rb
|
132
|
-
- corelib/class.rb
|
133
|
-
- corelib/comparable.rb
|
134
|
-
- corelib/encoding.rb
|
135
|
-
- corelib/enumerable.rb
|
136
|
-
- corelib/enumerator.rb
|
137
|
-
- corelib/error.rb
|
138
|
-
- corelib/hash.rb
|
139
|
-
- corelib/io.rb
|
140
|
-
- corelib/kernel.rb
|
141
|
-
- corelib/main.rb
|
142
|
-
- corelib/match_data.rb
|
143
|
-
- corelib/method.rb
|
144
|
-
- corelib/module.rb
|
145
|
-
- corelib/native.rb
|
146
|
-
- corelib/nil_class.rb
|
147
|
-
- corelib/numeric.rb
|
148
|
-
- corelib/opal.rb
|
149
|
-
- corelib/proc.rb
|
150
|
-
- corelib/range.rb
|
151
|
-
- corelib/regexp.rb
|
152
|
-
- corelib/runtime.js
|
153
|
-
- corelib/string.rb
|
154
|
-
- corelib/struct.rb
|
155
|
-
- corelib/time.rb
|
156
129
|
- doc/compiler.md
|
157
130
|
- doc/compiler_options.md
|
158
131
|
- doc/examples/node_http_server.rb
|
@@ -212,7 +185,34 @@ files:
|
|
212
185
|
- mri_spec/fixtures/opal_file.rb
|
213
186
|
- mri_spec/spec_helper.rb
|
214
187
|
- opal.gemspec
|
188
|
+
- opal/core/array.rb
|
189
|
+
- opal/core/basic_object.rb
|
190
|
+
- opal/core/boolean.rb
|
191
|
+
- opal/core/class.rb
|
192
|
+
- opal/core/comparable.rb
|
193
|
+
- opal/core/encoding.rb
|
194
|
+
- opal/core/enumerable.rb
|
195
|
+
- opal/core/enumerator.rb
|
196
|
+
- opal/core/error.rb
|
197
|
+
- opal/core/hash.rb
|
198
|
+
- opal/core/io.rb
|
199
|
+
- opal/core/kernel.rb
|
200
|
+
- opal/core/main.rb
|
201
|
+
- opal/core/match_data.rb
|
202
|
+
- opal/core/method.rb
|
203
|
+
- opal/core/module.rb
|
204
|
+
- opal/core/nil_class.rb
|
205
|
+
- opal/core/numeric.rb
|
206
|
+
- opal/core/proc.rb
|
207
|
+
- opal/core/range.rb
|
208
|
+
- opal/core/regexp.rb
|
209
|
+
- opal/core/runtime.js
|
210
|
+
- opal/core/string.rb
|
211
|
+
- opal/core/struct.rb
|
212
|
+
- opal/core/time.rb
|
213
|
+
- opal/opal.rb
|
215
214
|
- spec/config.ru
|
215
|
+
- spec/corelib/array/select_spec.rb
|
216
216
|
- spec/corelib/enumerable/all_break_spec.rb
|
217
217
|
- spec/corelib/enumerable/any_break_spec.rb
|
218
218
|
- spec/corelib/enumerable/collect_break_spec.rb
|
@@ -310,13 +310,6 @@ files:
|
|
310
310
|
- spec/corelib/module/public_method_defined_spec.rb
|
311
311
|
- spec/corelib/module/remove_const_spec.rb
|
312
312
|
- spec/corelib/module/undef_method_spec.rb
|
313
|
-
- spec/corelib/native/alias_native_spec.rb
|
314
|
-
- spec/corelib/native/each_spec.rb
|
315
|
-
- spec/corelib/native/element_reference_spec.rb
|
316
|
-
- spec/corelib/native/ext_spec.rb
|
317
|
-
- spec/corelib/native/initialize_spec.rb
|
318
|
-
- spec/corelib/native/method_missing_spec.rb
|
319
|
-
- spec/corelib/native/new_spec.rb
|
320
313
|
- spec/corelib/numeric/abs_spec.rb
|
321
314
|
- spec/corelib/numeric/bit_and_spec.rb
|
322
315
|
- spec/corelib/numeric/bit_or_spec.rb
|
@@ -409,11 +402,11 @@ files:
|
|
409
402
|
- spec/corelib/string/to_i_spec.rb
|
410
403
|
- spec/corelib/string/tr_s_spec.rb
|
411
404
|
- spec/corelib/string/tr_spec.rb
|
405
|
+
- spec/filters/20.rb
|
412
406
|
- spec/filters/bugs/array.rb
|
413
407
|
- spec/filters/bugs/basic_object.rb
|
414
408
|
- spec/filters/bugs/class.rb
|
415
409
|
- spec/filters/bugs/enumerable.rb
|
416
|
-
- spec/filters/bugs/enumerator.rb
|
417
410
|
- spec/filters/bugs/hash.rb
|
418
411
|
- spec/filters/bugs/kernel.rb
|
419
412
|
- spec/filters/bugs/language.rb
|
@@ -430,6 +423,7 @@ files:
|
|
430
423
|
- spec/filters/bugs/unknown.rb
|
431
424
|
- spec/filters/unsupported/array_subclasses.rb
|
432
425
|
- spec/filters/unsupported/encoding.rb
|
426
|
+
- spec/filters/unsupported/enumerator.rb
|
433
427
|
- spec/filters/unsupported/float.rb
|
434
428
|
- spec/filters/unsupported/frozen.rb
|
435
429
|
- spec/filters/unsupported/hash_compare_by_identity.rb
|
@@ -503,6 +497,13 @@ files:
|
|
503
497
|
- spec/stdlib/erb/simple.opalerb
|
504
498
|
- spec/stdlib/json/ext_spec.rb
|
505
499
|
- spec/stdlib/json/parse_spec.rb
|
500
|
+
- spec/stdlib/native/alias_native_spec.rb
|
501
|
+
- spec/stdlib/native/each_spec.rb
|
502
|
+
- spec/stdlib/native/element_reference_spec.rb
|
503
|
+
- spec/stdlib/native/ext_spec.rb
|
504
|
+
- spec/stdlib/native/initialize_spec.rb
|
505
|
+
- spec/stdlib/native/method_missing_spec.rb
|
506
|
+
- spec/stdlib/native/new_spec.rb
|
506
507
|
- spec/stdlib/template/paths_spec.rb
|
507
508
|
- stdlib/buffer.rb
|
508
509
|
- stdlib/buffer/array.rb
|
@@ -510,10 +511,12 @@ files:
|
|
510
511
|
- stdlib/date.rb
|
511
512
|
- stdlib/delegate.rb
|
512
513
|
- stdlib/dir.rb
|
514
|
+
- stdlib/enumerator.rb
|
513
515
|
- stdlib/erb.rb
|
514
516
|
- stdlib/file.rb
|
515
517
|
- stdlib/forwardable.rb
|
516
518
|
- stdlib/json.rb
|
519
|
+
- stdlib/native.rb
|
517
520
|
- stdlib/observer.rb
|
518
521
|
- stdlib/opal-parser.rb
|
519
522
|
- stdlib/opal-source-maps.js.erb
|
@@ -559,6 +562,7 @@ specification_version: 4
|
|
559
562
|
summary: Ruby runtime and core library for javascript
|
560
563
|
test_files:
|
561
564
|
- spec/config.ru
|
565
|
+
- spec/corelib/array/select_spec.rb
|
562
566
|
- spec/corelib/enumerable/all_break_spec.rb
|
563
567
|
- spec/corelib/enumerable/any_break_spec.rb
|
564
568
|
- spec/corelib/enumerable/collect_break_spec.rb
|
@@ -656,13 +660,6 @@ test_files:
|
|
656
660
|
- spec/corelib/module/public_method_defined_spec.rb
|
657
661
|
- spec/corelib/module/remove_const_spec.rb
|
658
662
|
- spec/corelib/module/undef_method_spec.rb
|
659
|
-
- spec/corelib/native/alias_native_spec.rb
|
660
|
-
- spec/corelib/native/each_spec.rb
|
661
|
-
- spec/corelib/native/element_reference_spec.rb
|
662
|
-
- spec/corelib/native/ext_spec.rb
|
663
|
-
- spec/corelib/native/initialize_spec.rb
|
664
|
-
- spec/corelib/native/method_missing_spec.rb
|
665
|
-
- spec/corelib/native/new_spec.rb
|
666
663
|
- spec/corelib/numeric/abs_spec.rb
|
667
664
|
- spec/corelib/numeric/bit_and_spec.rb
|
668
665
|
- spec/corelib/numeric/bit_or_spec.rb
|
@@ -755,11 +752,11 @@ test_files:
|
|
755
752
|
- spec/corelib/string/to_i_spec.rb
|
756
753
|
- spec/corelib/string/tr_s_spec.rb
|
757
754
|
- spec/corelib/string/tr_spec.rb
|
755
|
+
- spec/filters/20.rb
|
758
756
|
- spec/filters/bugs/array.rb
|
759
757
|
- spec/filters/bugs/basic_object.rb
|
760
758
|
- spec/filters/bugs/class.rb
|
761
759
|
- spec/filters/bugs/enumerable.rb
|
762
|
-
- spec/filters/bugs/enumerator.rb
|
763
760
|
- spec/filters/bugs/hash.rb
|
764
761
|
- spec/filters/bugs/kernel.rb
|
765
762
|
- spec/filters/bugs/language.rb
|
@@ -776,6 +773,7 @@ test_files:
|
|
776
773
|
- spec/filters/bugs/unknown.rb
|
777
774
|
- spec/filters/unsupported/array_subclasses.rb
|
778
775
|
- spec/filters/unsupported/encoding.rb
|
776
|
+
- spec/filters/unsupported/enumerator.rb
|
779
777
|
- spec/filters/unsupported/float.rb
|
780
778
|
- spec/filters/unsupported/frozen.rb
|
781
779
|
- spec/filters/unsupported/hash_compare_by_identity.rb
|
@@ -849,4 +847,11 @@ test_files:
|
|
849
847
|
- spec/stdlib/erb/simple.opalerb
|
850
848
|
- spec/stdlib/json/ext_spec.rb
|
851
849
|
- spec/stdlib/json/parse_spec.rb
|
850
|
+
- spec/stdlib/native/alias_native_spec.rb
|
851
|
+
- spec/stdlib/native/each_spec.rb
|
852
|
+
- spec/stdlib/native/element_reference_spec.rb
|
853
|
+
- spec/stdlib/native/ext_spec.rb
|
854
|
+
- spec/stdlib/native/initialize_spec.rb
|
855
|
+
- spec/stdlib/native/method_missing_spec.rb
|
856
|
+
- spec/stdlib/native/new_spec.rb
|
852
857
|
- spec/stdlib/template/paths_spec.rb
|
data/corelib/enumerator.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
class Enumerator
|
2
|
-
include Enumerable
|
3
|
-
|
4
|
-
class Yielder
|
5
|
-
def initialize(enumerator, block, to)
|
6
|
-
@enumerator = enumerator
|
7
|
-
@block = block
|
8
|
-
@to = to
|
9
|
-
end
|
10
|
-
|
11
|
-
def yield(*values)
|
12
|
-
@to.call(*values)
|
13
|
-
end
|
14
|
-
|
15
|
-
alias << yield
|
16
|
-
|
17
|
-
def call
|
18
|
-
@block.call(self)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize(obj = nil, method = :each, *args, &block)
|
23
|
-
if block
|
24
|
-
@block = block
|
25
|
-
else
|
26
|
-
@object = obj
|
27
|
-
@method = method
|
28
|
-
@args = args
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def each(&block)
|
33
|
-
return enum_for :each unless block_given?
|
34
|
-
|
35
|
-
if @block
|
36
|
-
Yielder.new(self, @block, block).call
|
37
|
-
else
|
38
|
-
@object.__send__(@method, *@args, &block)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def next
|
43
|
-
@cache ||= to_a
|
44
|
-
|
45
|
-
raise StopIteration, 'end of enumeration' if @cache.empty?
|
46
|
-
|
47
|
-
@cache.shift
|
48
|
-
end
|
49
|
-
|
50
|
-
def rewind
|
51
|
-
@cache = nil
|
52
|
-
|
53
|
-
self
|
54
|
-
end
|
55
|
-
end
|
data/corelib/native.rb
DELETED
@@ -1,270 +0,0 @@
|
|
1
|
-
module Kernel
|
2
|
-
def native?(value)
|
3
|
-
`value == null || !value._klass`
|
4
|
-
end
|
5
|
-
|
6
|
-
def Native(obj)
|
7
|
-
if `#{obj} == null`
|
8
|
-
nil
|
9
|
-
elsif native?(obj)
|
10
|
-
Native.new(obj)
|
11
|
-
else
|
12
|
-
obj
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Native < BasicObject
|
18
|
-
module Base
|
19
|
-
module Helpers
|
20
|
-
def alias_native(new, old = new, options = {})
|
21
|
-
if old.end_with? ?=
|
22
|
-
define_method new do |value|
|
23
|
-
`#@native[#{old[0 .. -2]}] = #{Native.convert(value)}`
|
24
|
-
|
25
|
-
value
|
26
|
-
end
|
27
|
-
else
|
28
|
-
if as = options[:as]
|
29
|
-
define_method new do |*args, &block|
|
30
|
-
if value = Native.call(@native, old, *args, &block)
|
31
|
-
as.new(value.to_n)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
else
|
35
|
-
define_method new do |*args, &block|
|
36
|
-
Native.call(@native, old, *args, &block)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.included(klass)
|
44
|
-
klass.instance_eval {
|
45
|
-
extend Helpers
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
def initialize(native)
|
50
|
-
unless Kernel.native?(native)
|
51
|
-
Kernel.raise ArgumentError, "the passed value isn't native"
|
52
|
-
end
|
53
|
-
|
54
|
-
@native = native
|
55
|
-
end
|
56
|
-
|
57
|
-
def to_n
|
58
|
-
@native
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class Array
|
63
|
-
include Base
|
64
|
-
include Enumerable
|
65
|
-
|
66
|
-
def initialize(native, options = {}, &block)
|
67
|
-
super(native)
|
68
|
-
|
69
|
-
@get = options[:get] || options[:access]
|
70
|
-
@named = options[:named]
|
71
|
-
@set = options[:set] || options[:access]
|
72
|
-
@length = options[:length] || :length
|
73
|
-
@block = block
|
74
|
-
|
75
|
-
if `#{length} == null`
|
76
|
-
raise ArgumentError, "no length found on the array-like object"
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def each(&block)
|
81
|
-
return enum_for :each unless block
|
82
|
-
|
83
|
-
index = 0
|
84
|
-
length = self.length
|
85
|
-
|
86
|
-
while index < length
|
87
|
-
block.call(self[index])
|
88
|
-
|
89
|
-
index += 1
|
90
|
-
end
|
91
|
-
|
92
|
-
self
|
93
|
-
end
|
94
|
-
|
95
|
-
def [](index)
|
96
|
-
result = case index
|
97
|
-
when String, Symbol
|
98
|
-
@named ? `#@native[#@named](#{index})` : `#@native[#{index}]`
|
99
|
-
|
100
|
-
when Integer
|
101
|
-
@get ? `#@native[#@get](#{index})` : `#@native[#{index}]`
|
102
|
-
end
|
103
|
-
|
104
|
-
if result
|
105
|
-
if @block
|
106
|
-
@block.call(result)
|
107
|
-
else
|
108
|
-
Native(result)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def []=(index, value)
|
114
|
-
if @set
|
115
|
-
`#@native[#@set](#{index}, #{value})`
|
116
|
-
else
|
117
|
-
`#@native[#{index}] = #{value}`
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def last(count = nil)
|
122
|
-
if count
|
123
|
-
index = length - 1
|
124
|
-
result = []
|
125
|
-
|
126
|
-
while index >= 0
|
127
|
-
result << self[index]
|
128
|
-
index -= 1
|
129
|
-
end
|
130
|
-
|
131
|
-
result
|
132
|
-
else
|
133
|
-
self[length - 1]
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
def length
|
138
|
-
`#@native[#@length]`
|
139
|
-
end
|
140
|
-
|
141
|
-
alias to_ary to_a
|
142
|
-
|
143
|
-
def inspect
|
144
|
-
to_a.inspect
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def self.is_a?(object, klass)
|
149
|
-
%x{
|
150
|
-
try {
|
151
|
-
return #{object} instanceof #{Native.try_convert(klass)};
|
152
|
-
}
|
153
|
-
catch (e) {
|
154
|
-
return false;
|
155
|
-
}
|
156
|
-
}
|
157
|
-
end
|
158
|
-
|
159
|
-
def self.try_convert(value)
|
160
|
-
%x{
|
161
|
-
if (#{native?(value)}) {
|
162
|
-
return #{value};
|
163
|
-
}
|
164
|
-
else if (#{value.respond_to? :to_n}) {
|
165
|
-
return #{value.to_n};
|
166
|
-
}
|
167
|
-
else {
|
168
|
-
return nil;
|
169
|
-
}
|
170
|
-
}
|
171
|
-
end
|
172
|
-
|
173
|
-
def self.convert(value)
|
174
|
-
native = try_convert(value)
|
175
|
-
|
176
|
-
if `#{native} === nil`
|
177
|
-
raise ArgumentError, "the passed value isn't a native"
|
178
|
-
end
|
179
|
-
|
180
|
-
native
|
181
|
-
end
|
182
|
-
|
183
|
-
def self.call(obj, key, *args, &block)
|
184
|
-
args << block if block
|
185
|
-
|
186
|
-
%x{
|
187
|
-
var prop = #{obj}[#{key}];
|
188
|
-
|
189
|
-
if (prop == null) {
|
190
|
-
return nil;
|
191
|
-
}
|
192
|
-
else if (prop instanceof Function) {
|
193
|
-
var result = prop.apply(#{obj}, #{args});
|
194
|
-
|
195
|
-
return result == null ? nil : result;
|
196
|
-
}
|
197
|
-
else if (#{native?(`prop`)}) {
|
198
|
-
return #{Native(`prop`)};
|
199
|
-
}
|
200
|
-
else {
|
201
|
-
return prop;
|
202
|
-
}
|
203
|
-
}
|
204
|
-
end
|
205
|
-
|
206
|
-
include Base
|
207
|
-
|
208
|
-
def has_key?(name)
|
209
|
-
`#@native.hasOwnProperty(#{name})`
|
210
|
-
end
|
211
|
-
|
212
|
-
alias key? has_key?
|
213
|
-
alias include? has_key?
|
214
|
-
alias member? has_key?
|
215
|
-
|
216
|
-
def each(*args)
|
217
|
-
if block_given?
|
218
|
-
%x{
|
219
|
-
for (var key in #@native) {
|
220
|
-
#{yield `key`, `#@native[key]`}
|
221
|
-
}
|
222
|
-
}
|
223
|
-
|
224
|
-
self
|
225
|
-
else
|
226
|
-
method_missing(:each, *args)
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
def [](key)
|
231
|
-
%x{
|
232
|
-
var prop = #@native[key];
|
233
|
-
|
234
|
-
if (prop instanceof Function) {
|
235
|
-
return prop;
|
236
|
-
}
|
237
|
-
else {
|
238
|
-
return #{::Native.call(@native, key)}
|
239
|
-
}
|
240
|
-
}
|
241
|
-
end
|
242
|
-
|
243
|
-
def []=(key, value)
|
244
|
-
native = Native.try_convert(value)
|
245
|
-
|
246
|
-
if `#{native} === nil`
|
247
|
-
`#@native[key] = #{value}`
|
248
|
-
else
|
249
|
-
`#@native[key] = #{native}`
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
def method_missing(mid, *args, &block)
|
254
|
-
%x{
|
255
|
-
if (mid.charAt(mid.length - 1) === '=') {
|
256
|
-
return #{self[mid.slice(0, mid.length - 1)] = args[0]};
|
257
|
-
}
|
258
|
-
else {
|
259
|
-
return #{::Native.call(@native, mid, *args, &block)};
|
260
|
-
}
|
261
|
-
}
|
262
|
-
end
|
263
|
-
|
264
|
-
def nil?
|
265
|
-
false
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
# native global
|
270
|
-
$$ = $global = Native(`Opal.global`)
|