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.
Files changed (4) hide show
  1. data/Rakefile +3 -3
  2. data/lib/opal/native.rb +172 -178
  3. data/opal-native.gemspec +1 -3
  4. 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 into .'
4
+ desc 'Build specified dependencies to build dir'
5
5
  task :dependencies do
6
- Opal::DependencyBuilder.new(stdlib: 'native', out: 'build').build
6
+ Opal::DependencyBuilder.new(out: 'build').build
7
7
  end
8
8
 
9
- desc 'Build latest opal-native to current dir'
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
- class Object
13
- include Native
12
+ class Object
13
+ include Native
14
14
 
15
- def [](name)
16
- `#@native[name]`
17
- end
15
+ def [](name)
16
+ `#@native[name]`
17
+ end
18
18
 
19
- def []=(name, value)
20
- `#@native[name] = value`
21
- end
19
+ def []=(name, value)
20
+ `#@native[name] = value`
21
+ end
22
22
 
23
- def nil?
24
- `#@native === null || #@native === undefined`
25
- end
23
+ def nil?
24
+ `#@native === null || #@native === undefined`
25
+ end
26
26
 
27
- def method_missing(name, *args)
28
- return super unless Opal.function? `#@native[name]`
27
+ def method_missing (name, *args)
28
+ return super unless Opal.function? `#@native[name]`
29
29
 
30
- __native_send__ name, *args
31
- end
32
- end
30
+ __native_send__ name, *args
31
+ end
32
+ end
33
33
 
34
- def self.included (klass)
35
- class << klass
36
- def from_native (object)
37
- instance = allocate
38
- instance.instance_variable_set :@native, object
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
- instance
41
- end
42
- end
43
- end
40
+ instance
41
+ end
42
+ end
43
+ end
44
44
 
45
- def initialize(native)
46
- @native = native
47
- end
45
+ def initialize (native)
46
+ @native = native
47
+ end
48
48
 
49
- def to_native
50
- @native
51
- end
49
+ def to_native
50
+ @native
51
+ end
52
52
 
53
- def native_send(name, *args)
54
- return method_missing(name, *args) unless Opal.function? `#@native[name]`
53
+ def native_send (name, *args)
54
+ return method_missing(name, *args) unless Opal.function? `#@native[name]`
55
55
 
56
- `#@native[name].apply(#@native, args)`
57
- end
56
+ `#@native[$opal.mid_to_jsid(name)].apply(#@native, args)`
57
+ end
58
58
 
59
- alias_method :__native_send__, :native_send
59
+ alias_method :__native_send__, :native_send
60
60
  end
61
61
 
62
62
  class Module
63
- %x{
64
- function define_attr_bridge(klass, target, name, getter, setter) {
65
- if (getter) {
66
- define_method(klass, 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[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
- define_method(klass, 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[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
- return nil;
100
- }
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
- return nil;
110
- }
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
- return nil;
120
- }
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[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
- %x{
145
- define_method_bridge(this, object, mid_to_jsid(#{ali || name}), name);
146
- this.$methods.push(name);
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 Array
154
- def to_native
155
- map { |obj| Opal.object?(obj) ? obj.to_native : obj }
156
- end
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
- def to_native
161
- `this == true`
162
- end
157
+ def to_native
158
+ `this.valueOf()`
159
+ end
163
160
  end
164
161
 
165
- class Hash
166
- def to_native
167
- %x{
168
- var map = this.map,
169
- result = {};
162
+ class Array
163
+ def to_native
164
+ map { |obj| Opal.object?(obj) ? obj.to_native : obj }
165
+ end
166
+ end
170
167
 
171
- for (var assoc in map) {
172
- var key = map[assoc][0],
173
- value = map[assoc][1];
168
+ class Hash
169
+ def to_native
170
+ %x{
171
+ var map = this.map,
172
+ result = {};
174
173
 
175
- result[key] = #{Opal.native?(`value`)} ? value : #{`value`.to_native};
176
- }
174
+ for (var assoc in map) {
175
+ var key = map[assoc][0],
176
+ value = map[assoc][1];
177
177
 
178
- return result;
179
- }
180
- end
181
- end
178
+ result[key] = #{Opal.native?(`value`)} ? value : #{`value`.to_native};
179
+ }
182
180
 
183
- module Kernel
184
- def Object(object)
185
- Opal.native?(object) ? Native::Object.new(object) : object
186
- end
181
+ return result;
182
+ }
183
+ end
187
184
  end
188
185
 
189
186
  class MatchData
190
- alias to_native to_a
187
+ alias to_native to_a
191
188
  end
192
189
 
193
190
  class NilClass
194
- def to_native
195
- `var result; return result;`
196
- end
191
+ def to_native
192
+ `var result; return result;`
193
+ end
197
194
  end
198
195
 
199
196
  class Numeric
200
- def to_native
201
- `this.valueOf()`
202
- end
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
- def to_native
213
- %x{
214
- return function() {
215
- var args = Array.slice.call(arguments);
216
- args.unshift(null); // block
217
-
218
- return this.apply(this.$S, args);
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
- def to_native
226
- self
227
- end
213
+ def to_native
214
+ self
215
+ end
228
216
  end
229
217
 
230
218
  class String
231
- def to_native
232
- `this.valueOf()`
233
- end
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-10 00:00:00.000000000 Z
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: []