opal-native 0.0.1 → 0.0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -3
- data/lib/opal/native.rb +172 -178
- data/opal-native.gemspec +1 -3
- metadata +3 -14
data/Rakefile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
require 'opal'
|
3
3
|
|
4
|
-
desc 'Build specified dependencies
|
4
|
+
desc 'Build specified dependencies to build dir'
|
5
5
|
task :dependencies do
|
6
|
-
Opal::DependencyBuilder.new(
|
6
|
+
Opal::DependencyBuilder.new(out: 'build').build
|
7
7
|
end
|
8
8
|
|
9
|
-
desc 'Build latest opal-native to
|
9
|
+
desc 'Build latest opal-native to build dir'
|
10
10
|
task :build do
|
11
11
|
Opal::Builder.new('lib', join: 'build/opal-native.js').build
|
12
12
|
end
|
data/lib/opal/native.rb
CHANGED
@@ -9,226 +9,220 @@
|
|
9
9
|
#++
|
10
10
|
|
11
11
|
module Native
|
12
|
-
|
13
|
-
|
12
|
+
class Object
|
13
|
+
include Native
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def [](name)
|
16
|
+
`#@native[name]`
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
def []=(name, value)
|
20
|
+
`#@native[name] = value`
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def nil?
|
24
|
+
`#@native === null || #@native === undefined`
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
def method_missing (name, *args)
|
28
|
+
return super unless Opal.function? `#@native[name]`
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
__native_send__ name, *args
|
31
|
+
end
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
def self.included (klass)
|
35
|
+
class << klass
|
36
|
+
def from_native (object)
|
37
|
+
instance = allocate
|
38
|
+
instance.instance_variable_set :@native, object
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
instance
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
def initialize (native)
|
46
|
+
@native = native
|
47
|
+
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
def to_native
|
50
|
+
@native
|
51
|
+
end
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
def native_send (name, *args)
|
54
|
+
return method_missing(name, *args) unless Opal.function? `#@native[name]`
|
55
55
|
|
56
|
-
|
57
|
-
|
56
|
+
`#@native[$opal.mid_to_jsid(name)].apply(#@native, args)`
|
57
|
+
end
|
58
58
|
|
59
|
-
|
59
|
+
alias_method :__native_send__, :native_send
|
60
60
|
end
|
61
61
|
|
62
62
|
class Module
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
return nil;
|
149
|
-
}
|
150
|
-
end
|
63
|
+
%x{
|
64
|
+
function define_attr_bridge(klass, target, name, getter, setter) {
|
65
|
+
if (getter) {
|
66
|
+
$opal.defn(klass, $opal.mid_to_jsid(name), function() {
|
67
|
+
var real_target = target;
|
68
|
+
|
69
|
+
if (target.$f & T_STRING) {
|
70
|
+
real_target = target[0] == '@' ? this[target.substr(1)] : this[$opal.mid_to_jsid(target)].apply(this, null);
|
71
|
+
}
|
72
|
+
|
73
|
+
var result = real_target[name];
|
74
|
+
|
75
|
+
return result == null ? nil : result;
|
76
|
+
});
|
77
|
+
}
|
78
|
+
|
79
|
+
if (setter) {
|
80
|
+
$opal.defn(klass, $opal.mid_to_jsid(name + '='), function (block, val) {
|
81
|
+
var real_target = target;
|
82
|
+
|
83
|
+
if (target.$f & T_STRING) {
|
84
|
+
real_target = target[0] == '@' ? this[target.substr(1)] : this[$opal.mid_to_jsid(target)].apply(this, null);
|
85
|
+
}
|
86
|
+
|
87
|
+
return real_target[name] = val;
|
88
|
+
});
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
def attr_accessor_bridge(target, *attrs)
|
94
|
+
%x{
|
95
|
+
for (var i = 0, length = attrs.length; i < length; i++) {
|
96
|
+
define_attr_bridge(this, target, attrs[i], true, true);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
self
|
101
|
+
end
|
102
|
+
|
103
|
+
def attr_reader_bridge(target, *attrs)
|
104
|
+
%x{
|
105
|
+
for (var i = 0, length = attrs.length; i < length; i++) {
|
106
|
+
define_attr_bridge(this, target, attrs[i], true, false);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
self
|
111
|
+
end
|
112
|
+
|
113
|
+
def attr_reader_bridge(target, *attrs)
|
114
|
+
%x{
|
115
|
+
for (var i = 0, length = attrs.length; i < length; i++) {
|
116
|
+
define_attr_bridge(this, target, attrs[i], false, true);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
self
|
121
|
+
end
|
122
|
+
|
123
|
+
def attr_bridge(target, name, setter = false)
|
124
|
+
`define_attr_bridge(this, target, name, true, setter)`
|
125
|
+
|
126
|
+
self
|
127
|
+
end
|
128
|
+
|
129
|
+
%x{
|
130
|
+
function define_method_bridge(klass, target, id, name) {
|
131
|
+
define_method(klass, id, function() {
|
132
|
+
var real_target = target;
|
133
|
+
|
134
|
+
if (target.$f & T_STRING) {
|
135
|
+
real_target = target[0] == '@' ? this[target.substr(1)] : this[$opal.mid_to_jsid(target)].apply(this, null);
|
136
|
+
}
|
137
|
+
|
138
|
+
return real_target.apply(this, $slice.call(arguments, 1));
|
139
|
+
});
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
def define_method_bridge(object, name, ali = nil)
|
144
|
+
`define_method_bridge(this, object, $opal.mid_to_jsid(#{ali || name}), name)`
|
145
|
+
|
146
|
+
self
|
147
|
+
end
|
151
148
|
end
|
152
149
|
|
153
|
-
class
|
154
|
-
|
155
|
-
|
156
|
-
|
150
|
+
class Object
|
151
|
+
def to_native
|
152
|
+
raise TypeError, 'no specialized #to_native has been implemented'
|
153
|
+
end
|
157
154
|
end
|
158
155
|
|
159
156
|
class Boolean
|
160
|
-
|
161
|
-
|
162
|
-
|
157
|
+
def to_native
|
158
|
+
`this.valueOf()`
|
159
|
+
end
|
163
160
|
end
|
164
161
|
|
165
|
-
class
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
162
|
+
class Array
|
163
|
+
def to_native
|
164
|
+
map { |obj| Opal.object?(obj) ? obj.to_native : obj }
|
165
|
+
end
|
166
|
+
end
|
170
167
|
|
171
|
-
|
172
|
-
|
173
|
-
|
168
|
+
class Hash
|
169
|
+
def to_native
|
170
|
+
%x{
|
171
|
+
var map = this.map,
|
172
|
+
result = {};
|
174
173
|
|
175
|
-
|
176
|
-
|
174
|
+
for (var assoc in map) {
|
175
|
+
var key = map[assoc][0],
|
176
|
+
value = map[assoc][1];
|
177
177
|
|
178
|
-
|
179
|
-
|
180
|
-
end
|
181
|
-
end
|
178
|
+
result[key] = #{Opal.native?(`value`)} ? value : #{`value`.to_native};
|
179
|
+
}
|
182
180
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
end
|
181
|
+
return result;
|
182
|
+
}
|
183
|
+
end
|
187
184
|
end
|
188
185
|
|
189
186
|
class MatchData
|
190
|
-
|
187
|
+
alias to_native to_a
|
191
188
|
end
|
192
189
|
|
193
190
|
class NilClass
|
194
|
-
|
195
|
-
|
196
|
-
|
191
|
+
def to_native
|
192
|
+
`var result; return result;`
|
193
|
+
end
|
197
194
|
end
|
198
195
|
|
199
196
|
class Numeric
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
end
|
204
|
-
|
205
|
-
class Object
|
206
|
-
def to_native
|
207
|
-
raise TypeError, 'no specialized #to_native has been implemented'
|
208
|
-
end
|
197
|
+
def to_native
|
198
|
+
`this.valueOf()`
|
199
|
+
end
|
209
200
|
end
|
210
201
|
|
211
202
|
class Proc
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
};
|
220
|
-
}
|
221
|
-
end
|
203
|
+
def to_native
|
204
|
+
%x{
|
205
|
+
return function () {
|
206
|
+
return this.apply(this.$S, arguments);
|
207
|
+
};
|
208
|
+
}
|
209
|
+
end
|
222
210
|
end
|
223
211
|
|
224
212
|
class Regexp
|
225
|
-
|
226
|
-
|
227
|
-
|
213
|
+
def to_native
|
214
|
+
self
|
215
|
+
end
|
228
216
|
end
|
229
217
|
|
230
218
|
class String
|
231
|
-
|
232
|
-
|
233
|
-
|
219
|
+
def to_native
|
220
|
+
`this.valueOf()`
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
module Kernel
|
225
|
+
def Object(object)
|
226
|
+
Opal.native?(object) ? Native::Object.new(object) : object
|
227
|
+
end
|
234
228
|
end
|
data/opal-native.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new {|s|
|
2
2
|
s.name = 'opal-native'
|
3
|
-
s.version = '0.0.1'
|
3
|
+
s.version = '0.0.1.1'
|
4
4
|
s.author = 'meh.'
|
5
5
|
s.email = 'meh@paranoici.org'
|
6
6
|
s.homepage = 'http://github.com/opal/opal-native'
|
@@ -11,6 +11,4 @@ Gem::Specification.new {|s|
|
|
11
11
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
12
12
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
13
|
s.require_paths = ['lib']
|
14
|
-
|
15
|
-
s.add_dependency 'opal'
|
16
14
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-native
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
4
|
+
version: 0.0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,19 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: opal
|
16
|
-
requirement: &21726440 !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: *21726440
|
12
|
+
date: 2012-01-12 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
25
14
|
description:
|
26
15
|
email: meh@paranoici.org
|
27
16
|
executables: []
|