opal 0.3.30 → 0.3.31
Sign up to get free protection for your applications and to get access to all the features.
- data/core/array.rb +12 -12
- data/core/class.rb +11 -1
- data/core/enumerable.rb +12 -12
- data/core/{template.rb → erb.rb} +3 -3
- data/core/hash.rb +13 -12
- data/core/kernel.rb +9 -2
- data/core/load_order +1 -1
- data/core/numeric.rb +3 -3
- data/core/proc.rb +2 -2
- data/core/string.rb +1 -1
- data/lib/opal/erb.rb +3 -2
- data/lib/opal/parser.rb +17 -17
- data/lib/opal/version.rb +2 -2
- data/spec/language/proc_spec.rb +37 -0
- data/spec/parser/erb_spec.rb +7 -7
- metadata +5 -3
data/core/array.rb
CHANGED
@@ -28,7 +28,7 @@ class Array < `Array`
|
|
28
28
|
}
|
29
29
|
else {
|
30
30
|
for (var i = 0; i < size; i++) {
|
31
|
-
arr[i] = block
|
31
|
+
arr[i] = block(i);
|
32
32
|
}
|
33
33
|
}
|
34
34
|
}
|
@@ -228,7 +228,7 @@ class Array < `Array`
|
|
228
228
|
var result = [];
|
229
229
|
|
230
230
|
for (var i = 0, length = #{self}.length, value; i < length; i++) {
|
231
|
-
if ((value = block
|
231
|
+
if ((value = block(#{self}[i])) === __breaker) {
|
232
232
|
return __breaker.$v;
|
233
233
|
}
|
234
234
|
|
@@ -242,7 +242,7 @@ class Array < `Array`
|
|
242
242
|
def collect!(&block)
|
243
243
|
%x{
|
244
244
|
for (var i = 0, length = #{self}.length, val; i < length; i++) {
|
245
|
-
if ((val = block
|
245
|
+
if ((val = block(#{self}[i])) === __breaker) {
|
246
246
|
return __breaker.$v;
|
247
247
|
}
|
248
248
|
|
@@ -350,7 +350,7 @@ class Array < `Array`
|
|
350
350
|
def delete_if(&block)
|
351
351
|
%x{
|
352
352
|
for (var i = 0, length = #{self}.length, value; i < length; i++) {
|
353
|
-
if ((value = block
|
353
|
+
if ((value = block(#{self}[i])) === __breaker) {
|
354
354
|
return __breaker.$v;
|
355
355
|
}
|
356
356
|
|
@@ -409,7 +409,7 @@ class Array < `Array`
|
|
409
409
|
}
|
410
410
|
|
411
411
|
if (block !== nil) {
|
412
|
-
return block(
|
412
|
+
return block(original);
|
413
413
|
}
|
414
414
|
|
415
415
|
#{ raise "Array#fetch" };
|
@@ -489,7 +489,7 @@ class Array < `Array`
|
|
489
489
|
}
|
490
490
|
else if (block !== nil) {
|
491
491
|
for (var i = 0, length = #{self}.length, value; i < length; i++) {
|
492
|
-
if ((value = block
|
492
|
+
if ((value = block(#{self}[i])) === __breaker) {
|
493
493
|
return __breaker.$v;
|
494
494
|
}
|
495
495
|
|
@@ -561,7 +561,7 @@ class Array < `Array`
|
|
561
561
|
def keep_if(&block)
|
562
562
|
%x{
|
563
563
|
for (var i = 0, length = #{self}.length, value; i < length; i++) {
|
564
|
-
if ((value = block
|
564
|
+
if ((value = block(#{self}[i])) === __breaker) {
|
565
565
|
return __breaker.$v;
|
566
566
|
}
|
567
567
|
|
@@ -651,7 +651,7 @@ class Array < `Array`
|
|
651
651
|
var result = [];
|
652
652
|
|
653
653
|
for (var i = 0, length = #{self}.length, value; i < length; i++) {
|
654
|
-
if ((value = block
|
654
|
+
if ((value = block(#{self}[i])) === __breaker) {
|
655
655
|
return __breaker.$v;
|
656
656
|
}
|
657
657
|
|
@@ -699,7 +699,7 @@ class Array < `Array`
|
|
699
699
|
%x{
|
700
700
|
if (block !== nil) {
|
701
701
|
for (var i = #{self}.length - 1, value; i >= 0; i--) {
|
702
|
-
if ((value = block
|
702
|
+
if ((value = block(#{self}[i])) === __breaker) {
|
703
703
|
return __breaker.$v;
|
704
704
|
}
|
705
705
|
|
@@ -727,7 +727,7 @@ class Array < `Array`
|
|
727
727
|
for (var i = 0, length = #{self}.length, item, value; i < length; i++) {
|
728
728
|
item = #{self}[i];
|
729
729
|
|
730
|
-
if ((value = block
|
730
|
+
if ((value = block(item)) === __breaker) {
|
731
731
|
return __breaker.$v;
|
732
732
|
}
|
733
733
|
|
@@ -791,7 +791,7 @@ class Array < `Array`
|
|
791
791
|
for (var i = 0, length = #{self}.length, item, value; i < length; i++) {
|
792
792
|
item = #{self}[i];
|
793
793
|
|
794
|
-
if ((value = block
|
794
|
+
if ((value = block(item)) === __breaker) {
|
795
795
|
return __breaker.$v;
|
796
796
|
}
|
797
797
|
|
@@ -902,7 +902,7 @@ class Array < `Array`
|
|
902
902
|
|
903
903
|
if (block !== nil) {
|
904
904
|
for (var i = 0; i < size; i++) {
|
905
|
-
block
|
905
|
+
block(result[i]);
|
906
906
|
}
|
907
907
|
|
908
908
|
return nil;
|
data/core/class.rb
CHANGED
@@ -8,7 +8,10 @@ class Class
|
|
8
8
|
sup.$inherited(klass);
|
9
9
|
|
10
10
|
if (block !== nil) {
|
11
|
+
var block_self = block._s;
|
12
|
+
block._s = null;
|
11
13
|
block.call(klass);
|
14
|
+
block._s = block_self;
|
12
15
|
}
|
13
16
|
|
14
17
|
return klass;
|
@@ -101,6 +104,7 @@ class Class
|
|
101
104
|
var jsid = '$' + name;
|
102
105
|
block._jsid = jsid;
|
103
106
|
block._sup = #{self}.prototype[jsid];
|
107
|
+
block._s = null;
|
104
108
|
|
105
109
|
#{self}.prototype[jsid] = block;
|
106
110
|
#{self}._donate([jsid]);
|
@@ -158,7 +162,13 @@ class Class
|
|
158
162
|
no_block_given();
|
159
163
|
}
|
160
164
|
|
161
|
-
|
165
|
+
var block_self = block._s, result;
|
166
|
+
|
167
|
+
block._s = null;
|
168
|
+
result = block.call(#{self});
|
169
|
+
block._s = block_self;
|
170
|
+
|
171
|
+
return result;
|
162
172
|
}
|
163
173
|
end
|
164
174
|
|
data/core/enumerable.rb
CHANGED
@@ -7,7 +7,7 @@ module Enumerable
|
|
7
7
|
proc = function(obj) {
|
8
8
|
var value;
|
9
9
|
|
10
|
-
if ((value = block
|
10
|
+
if ((value = block(obj)) === __breaker) {
|
11
11
|
return __breaker.$v;
|
12
12
|
}
|
13
13
|
|
@@ -45,7 +45,7 @@ module Enumerable
|
|
45
45
|
proc = function(obj) {
|
46
46
|
var value;
|
47
47
|
|
48
|
-
if ((value = block
|
48
|
+
if ((value = block(obj)) === __breaker) {
|
49
49
|
return __breaker.$v;
|
50
50
|
}
|
51
51
|
|
@@ -82,7 +82,7 @@ module Enumerable
|
|
82
82
|
var proc = function() {
|
83
83
|
var obj = __slice.call(arguments), value;
|
84
84
|
|
85
|
-
if ((value = block.apply(
|
85
|
+
if ((value = block.apply(null, obj)) === __breaker) {
|
86
86
|
return __breaker.$v;
|
87
87
|
}
|
88
88
|
|
@@ -103,7 +103,7 @@ module Enumerable
|
|
103
103
|
var proc = function() {
|
104
104
|
var obj = __slice.call(arguments), value;
|
105
105
|
|
106
|
-
if ((value = block.apply(
|
106
|
+
if ((value = block.apply(null, [result].concat(obj))) === __breaker) {
|
107
107
|
result = __breaker.$v;
|
108
108
|
__breaker.$v = nil;
|
109
109
|
|
@@ -134,7 +134,7 @@ module Enumerable
|
|
134
134
|
var proc = function(obj) {
|
135
135
|
var value;
|
136
136
|
|
137
|
-
if ((value = block
|
137
|
+
if ((value = block(obj)) === __breaker) {
|
138
138
|
return __breaker.$v;
|
139
139
|
}
|
140
140
|
|
@@ -157,7 +157,7 @@ module Enumerable
|
|
157
157
|
#{self}.$each._p = function(obj) {
|
158
158
|
var value;
|
159
159
|
|
160
|
-
if ((value = block
|
160
|
+
if ((value = block(obj)) === __breaker) {
|
161
161
|
return __breaker.$v;
|
162
162
|
}
|
163
163
|
|
@@ -209,7 +209,7 @@ module Enumerable
|
|
209
209
|
#{self}.$each._p = function(obj) {
|
210
210
|
var value;
|
211
211
|
|
212
|
-
if ((value = block
|
212
|
+
if ((value = block(obj)) === __breaker) {
|
213
213
|
return __breaker;
|
214
214
|
}
|
215
215
|
|
@@ -235,7 +235,7 @@ module Enumerable
|
|
235
235
|
#{self}.$each._p = function(obj) {
|
236
236
|
var value;
|
237
237
|
|
238
|
-
if ((value = block
|
238
|
+
if ((value = block(obj, index)) === __breaker) {
|
239
239
|
return __breaker.$v;
|
240
240
|
}
|
241
241
|
|
@@ -253,7 +253,7 @@ module Enumerable
|
|
253
253
|
#{self}.$each._p = function(obj) {
|
254
254
|
var value;
|
255
255
|
|
256
|
-
if ((value = block
|
256
|
+
if ((value = block(obj, object)) === __breaker) {
|
257
257
|
return __breaker.$v;
|
258
258
|
}
|
259
259
|
};
|
@@ -287,7 +287,7 @@ module Enumerable
|
|
287
287
|
#{self}.$each._p = function(obj) {
|
288
288
|
var value;
|
289
289
|
|
290
|
-
if ((value = block
|
290
|
+
if ((value = block(obj)) === __breaker) {
|
291
291
|
return __breaker.$v;
|
292
292
|
}
|
293
293
|
|
@@ -319,7 +319,7 @@ module Enumerable
|
|
319
319
|
proc = function(obj) {
|
320
320
|
var value;
|
321
321
|
|
322
|
-
if ((value = block
|
322
|
+
if ((value = block(obj)) === __breaker) {
|
323
323
|
return __breaker.$v;
|
324
324
|
}
|
325
325
|
|
@@ -379,7 +379,7 @@ module Enumerable
|
|
379
379
|
var value = #{pattern === `obj`};
|
380
380
|
|
381
381
|
if (value !== false && value !== nil) {
|
382
|
-
if ((value = block
|
382
|
+
if ((value = block(obj)) === __breaker) {
|
383
383
|
return __breaker.$v;
|
384
384
|
}
|
385
385
|
|
data/core/{template.rb → erb.rb}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class ERB
|
2
2
|
@_cache = {}
|
3
3
|
def self.[](name)
|
4
4
|
@_cache[name]
|
@@ -11,10 +11,10 @@ class Template
|
|
11
11
|
def initialize(name, &body)
|
12
12
|
@body = body
|
13
13
|
@name = name
|
14
|
-
|
14
|
+
ERB[name] = self
|
15
15
|
end
|
16
16
|
|
17
17
|
def render(ctx=self)
|
18
18
|
ctx.instance_eval(&@body)
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end
|
data/core/hash.rb
CHANGED
@@ -189,7 +189,7 @@ class Hash
|
|
189
189
|
var map = #{self}.map, value;
|
190
190
|
|
191
191
|
for (var key in map) {
|
192
|
-
if ((value = block
|
192
|
+
if ((value = block(key, map[key])) === __breaker) {
|
193
193
|
return __breaker.$v;
|
194
194
|
}
|
195
195
|
|
@@ -209,7 +209,7 @@ class Hash
|
|
209
209
|
var map = #{self}.map;
|
210
210
|
|
211
211
|
for (var key in map) {
|
212
|
-
if (block
|
212
|
+
if (block(key, map[key]) === __breaker) {
|
213
213
|
return __breaker.$v;
|
214
214
|
}
|
215
215
|
}
|
@@ -223,7 +223,7 @@ class Hash
|
|
223
223
|
var map = #{self}.map;
|
224
224
|
|
225
225
|
for (var key in map) {
|
226
|
-
if (block
|
226
|
+
if (block(key) === __breaker) {
|
227
227
|
return __breaker.$v;
|
228
228
|
}
|
229
229
|
}
|
@@ -239,7 +239,7 @@ class Hash
|
|
239
239
|
var map = #{self}.map;
|
240
240
|
|
241
241
|
for (var key in map) {
|
242
|
-
if (block
|
242
|
+
if (block(map[key]) === __breaker) {
|
243
243
|
return __breaker.$v;
|
244
244
|
}
|
245
245
|
}
|
@@ -271,7 +271,7 @@ class Hash
|
|
271
271
|
if (block !== nil) {
|
272
272
|
var value;
|
273
273
|
|
274
|
-
if ((value = block
|
274
|
+
if ((value = block(key)) === __breaker) {
|
275
275
|
return __breaker.$v;
|
276
276
|
}
|
277
277
|
|
@@ -403,7 +403,7 @@ class Hash
|
|
403
403
|
for (var key in map) {
|
404
404
|
var obj = map[key];
|
405
405
|
|
406
|
-
if ((value = block
|
406
|
+
if ((value = block(key, obj)) === __breaker) {
|
407
407
|
return __breaker.$v;
|
408
408
|
}
|
409
409
|
|
@@ -467,7 +467,7 @@ class Hash
|
|
467
467
|
map2[key] = map[key];
|
468
468
|
}
|
469
469
|
else {
|
470
|
-
map2[key] = block
|
470
|
+
map2[key] = block(key, map2[key], map[key]);
|
471
471
|
}
|
472
472
|
}
|
473
473
|
}
|
@@ -491,7 +491,7 @@ class Hash
|
|
491
491
|
map[key] = map2[key];
|
492
492
|
}
|
493
493
|
else {
|
494
|
-
map[key] = block
|
494
|
+
map[key] = block(key, map[key], map2[key]);
|
495
495
|
}
|
496
496
|
}
|
497
497
|
}
|
@@ -523,7 +523,7 @@ class Hash
|
|
523
523
|
for (var key in map) {
|
524
524
|
var obj = map[key], value;
|
525
525
|
|
526
|
-
if ((value = block
|
526
|
+
if ((value = block(key, obj)) === __breaker) {
|
527
527
|
return __breaker.$v;
|
528
528
|
}
|
529
529
|
|
@@ -555,7 +555,7 @@ class Hash
|
|
555
555
|
for (var key in map) {
|
556
556
|
var obj = map[key], value;
|
557
557
|
|
558
|
-
if ((value = block
|
558
|
+
if ((value = block(key, obj)) === __breaker) {
|
559
559
|
return __breaker.$v;
|
560
560
|
}
|
561
561
|
|
@@ -575,7 +575,7 @@ class Hash
|
|
575
575
|
for (var key in map) {
|
576
576
|
var obj = map[key];
|
577
577
|
|
578
|
-
if ((value = block
|
578
|
+
if ((value = block(key, obj)) === __breaker) {
|
579
579
|
return __breaker.$v;
|
580
580
|
}
|
581
581
|
|
@@ -686,4 +686,5 @@ class Hash
|
|
686
686
|
return result;
|
687
687
|
}
|
688
688
|
end
|
689
|
-
end
|
689
|
+
end
|
690
|
+
|
data/core/kernel.rb
CHANGED
@@ -78,7 +78,8 @@ module Kernel
|
|
78
78
|
|
79
79
|
var jsid = '$' + name;
|
80
80
|
body._jsid = jsid;
|
81
|
-
body._sup = #{self}[jsid]
|
81
|
+
body._sup = #{self}[jsid];
|
82
|
+
body._s = null;
|
82
83
|
|
83
84
|
#{self}[jsid] = body;
|
84
85
|
|
@@ -246,7 +247,13 @@ module Kernel
|
|
246
247
|
no_block_given();
|
247
248
|
}
|
248
249
|
|
249
|
-
|
250
|
+
var block_self = block._s, result;
|
251
|
+
|
252
|
+
block._s = null;
|
253
|
+
result = block.call(#{self}, #{self});
|
254
|
+
block._s = block_self;
|
255
|
+
|
256
|
+
return result;
|
250
257
|
}
|
251
258
|
end
|
252
259
|
|
data/core/load_order
CHANGED
data/core/numeric.rb
CHANGED
@@ -106,7 +106,7 @@ class Numeric < `Number`
|
|
106
106
|
def downto(finish, &block)
|
107
107
|
%x{
|
108
108
|
for (var i = #{self}; i >= finish; i--) {
|
109
|
-
if (block
|
109
|
+
if (block(i) === __breaker) {
|
110
110
|
return __breaker.$v;
|
111
111
|
}
|
112
112
|
}
|
@@ -162,7 +162,7 @@ class Numeric < `Number`
|
|
162
162
|
def times(&block)
|
163
163
|
%x{
|
164
164
|
for (var i = 0; i < #{self}; i++) {
|
165
|
-
if (block
|
165
|
+
if (block(i) === __breaker) {
|
166
166
|
return __breaker.$v;
|
167
167
|
}
|
168
168
|
}
|
@@ -190,7 +190,7 @@ class Numeric < `Number`
|
|
190
190
|
def upto(finish, &block)
|
191
191
|
%x{
|
192
192
|
for (var i = #{self}; i <= finish; i++) {
|
193
|
-
if (block
|
193
|
+
if (block(i) === __breaker) {
|
194
194
|
return __breaker.$v;
|
195
195
|
}
|
196
196
|
}
|
data/core/proc.rb
CHANGED
@@ -11,7 +11,7 @@ class Proc < `Function`
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(*args)
|
14
|
-
`#{self}.apply(
|
14
|
+
`#{self}.apply(null, #{args})`
|
15
15
|
end
|
16
16
|
|
17
17
|
def to_proc
|
@@ -29,4 +29,4 @@ class Proc < `Function`
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
class Method < Proc; end
|
32
|
+
class Method < Proc; end
|
data/core/string.rb
CHANGED
data/lib/opal/erb.rb
CHANGED
@@ -7,7 +7,8 @@ module Opal
|
|
7
7
|
"\")\n#{ $1 }\nout.<<(\""
|
8
8
|
end
|
9
9
|
|
10
|
-
code = "
|
10
|
+
code = "ERB.new('#{name}') do\nout = []\nout.<<(\"#{ body }\")\nout.join\nend\n"
|
11
11
|
"// #{ name } (erb)\n#{ Opal.parse(code) }\n"
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
14
|
+
|
data/lib/opal/parser.rb
CHANGED
@@ -633,6 +633,7 @@ module Opal
|
|
633
633
|
code = ""
|
634
634
|
params = nil
|
635
635
|
scope_name = nil
|
636
|
+
identity = nil
|
636
637
|
|
637
638
|
args = nil if Fixnum === args # argh
|
638
639
|
args ||= s(:masgn, s(:array))
|
@@ -651,6 +652,9 @@ module Opal
|
|
651
652
|
|
652
653
|
indent do
|
653
654
|
in_scope(:iter) do
|
655
|
+
identity = @scope.identify!
|
656
|
+
@scope.add_temp "self = #{identity}._s || this"
|
657
|
+
|
654
658
|
args[1..-1].each do |arg|
|
655
659
|
arg = arg[1]
|
656
660
|
arg = "#{arg}$" if RESERVED.include? arg.to_s
|
@@ -685,19 +689,13 @@ module Opal
|
|
685
689
|
end
|
686
690
|
|
687
691
|
code = "\n#@indent#{@scope.to_vars}\n#@indent#{code}"
|
688
|
-
|
689
|
-
scope_name = @scope.identity
|
690
692
|
end
|
691
693
|
end
|
692
694
|
|
693
|
-
|
694
|
-
|
695
|
-
itercode = "#{scope_name} = #{itercode}" if scope_name
|
696
|
-
|
697
|
-
call << ("(%s = %s, %s._s = %s, %s)" % [tmp, itercode, tmp, current_self, tmp])
|
695
|
+
itercode = "function(#{params.join ', '}) {\n#{code}\n#@indent}"
|
696
|
+
call << ("(%s = %s, %s._s = %s, %s)" % [identity, itercode, identity, current_self, identity])
|
698
697
|
|
699
|
-
|
700
|
-
end
|
698
|
+
process call, level
|
701
699
|
end
|
702
700
|
|
703
701
|
def js_block_args(sexp)
|
@@ -790,7 +788,7 @@ module Opal
|
|
790
788
|
@requires << path[1]
|
791
789
|
end
|
792
790
|
|
793
|
-
return "
|
791
|
+
return ""
|
794
792
|
when :respond_to?
|
795
793
|
return handle_respond_to(sexp, level)
|
796
794
|
end
|
@@ -1081,11 +1079,11 @@ module Opal
|
|
1081
1079
|
scope_name = @scope.identity
|
1082
1080
|
|
1083
1081
|
if @scope.uses_block?
|
1084
|
-
@scope.add_temp '__context'
|
1082
|
+
# @scope.add_temp '__context'
|
1085
1083
|
@scope.add_temp yielder
|
1086
1084
|
|
1087
|
-
blk = "\n%s%s = %s._p || nil,
|
1088
|
-
[@indent, yielder, scope_name,
|
1085
|
+
blk = "\n%s%s = %s._p || nil, %s._p = null;\n%s" %
|
1086
|
+
[@indent, yielder, scope_name, scope_name, @indent]
|
1089
1087
|
|
1090
1088
|
code = blk + code
|
1091
1089
|
end
|
@@ -1165,7 +1163,9 @@ module Opal
|
|
1165
1163
|
'self'
|
1166
1164
|
elsif @scope.top?
|
1167
1165
|
'self'
|
1168
|
-
|
1166
|
+
elsif @scope.iter?
|
1167
|
+
'self'
|
1168
|
+
else # def
|
1169
1169
|
'this'
|
1170
1170
|
end
|
1171
1171
|
end
|
@@ -1647,12 +1647,12 @@ module Opal
|
|
1647
1647
|
@scope.uses_block!
|
1648
1648
|
|
1649
1649
|
splat = sexp.any? { |s| s.first == :splat }
|
1650
|
-
sexp.unshift s(:js_tmp, '__context') unless splat # self
|
1650
|
+
# sexp.unshift s(:js_tmp, '__context') unless splat # self
|
1651
1651
|
args = process_arglist sexp, level
|
1652
1652
|
|
1653
1653
|
y = @scope.block_name || '__yield'
|
1654
1654
|
|
1655
|
-
splat ? "#{y}.apply(
|
1655
|
+
splat ? "#{y}.apply(null, #{args})" : "#{y}(#{args})"
|
1656
1656
|
end
|
1657
1657
|
|
1658
1658
|
def process_break(exp, level)
|
@@ -1816,7 +1816,7 @@ module Opal
|
|
1816
1816
|
elsif @scope.type == :iter
|
1817
1817
|
chain, defn, mid = @scope.get_super_chain
|
1818
1818
|
trys = chain.map { |c| "#{c}._sup" }.join ' || '
|
1819
|
-
"(#{trys} ||
|
1819
|
+
"(#{trys} || #{current_self}._klass._super.prototype[#{mid}]).apply(#{current_self}, #{args})"
|
1820
1820
|
else
|
1821
1821
|
raise "Cannot call super() from outside a method block"
|
1822
1822
|
end
|
data/lib/opal/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Opal
|
2
|
-
VERSION = '0.3.
|
3
|
-
end
|
2
|
+
VERSION = '0.3.31'
|
3
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class ProcSpec
|
2
|
+
define_method :defined_method do
|
3
|
+
self
|
4
|
+
end
|
5
|
+
|
6
|
+
def call_proc
|
7
|
+
get_proc.call
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_proc
|
11
|
+
proc { self }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "Procs" do
|
16
|
+
before do
|
17
|
+
@obj = ProcSpec.new
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should use the 'self' value of wrapping scope" do
|
21
|
+
@obj.call_proc.should eq(@obj)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "instance_eval correctly sets proc self value" do
|
25
|
+
arr = []
|
26
|
+
arr.instance_eval(&@obj.get_proc).should eq(arr)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "procs used by define_method use correct self value" do
|
30
|
+
@obj.defined_method.should eq(@obj)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "procs used by define_singleton_method use correct self value" do
|
34
|
+
@obj.define_singleton_method(:bar) { self }
|
35
|
+
@obj.bar.should eq(@obj)
|
36
|
+
end
|
37
|
+
end
|
data/spec/parser/erb_spec.rb
CHANGED
@@ -4,8 +4,8 @@ describe "Opal.parse_erb" do
|
|
4
4
|
@quoted = opal_eval_compiled(Opal.parse_erb('<div class="foo">hello <%= "there " + @name %></div>', "quoted_test"))
|
5
5
|
end
|
6
6
|
|
7
|
-
it "should be an instance of
|
8
|
-
@simple.should be_kind_of(
|
7
|
+
it "should be an instance of ERB" do
|
8
|
+
@simple.should be_kind_of(ERB)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "calling the block with a context should render the block" do
|
@@ -18,15 +18,15 @@ describe "Opal.parse_erb" do
|
|
18
18
|
@quoted.render(self).should == "<div class=\"foo\">hello there adam</div>"
|
19
19
|
end
|
20
20
|
|
21
|
-
it 'stores created templates in
|
22
|
-
|
23
|
-
|
21
|
+
it 'stores created templates in ERB[] by name' do
|
22
|
+
ERB['simple_test'].should == @simple
|
23
|
+
ERB['quoted_test'].should == @quoted
|
24
24
|
end
|
25
25
|
|
26
26
|
describe '.parse' do
|
27
27
|
it 'parses erb content by running it through compiler' do
|
28
28
|
opal_eval_compiled Opal.parse_erb("hi there", 'test_parse')
|
29
|
-
|
29
|
+
ERB['test_parse'].should be_kind_of(ERB)
|
30
30
|
end
|
31
31
|
end
|
32
|
-
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.31
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby runtime and core library for javascript.
|
15
15
|
email: adam.beynon@gmail.com
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- core/comparable.rb
|
34
34
|
- core/date.rb
|
35
35
|
- core/enumerable.rb
|
36
|
+
- core/erb.rb
|
36
37
|
- core/error.rb
|
37
38
|
- core/hash.rb
|
38
39
|
- core/json.rb
|
@@ -48,7 +49,6 @@ files:
|
|
48
49
|
- core/regexp.rb
|
49
50
|
- core/runtime.js
|
50
51
|
- core/string.rb
|
51
|
-
- core/template.rb
|
52
52
|
- core/test_runner/runner.js
|
53
53
|
- core/time.rb
|
54
54
|
- lib/opal.rb
|
@@ -410,6 +410,7 @@ files:
|
|
410
410
|
- spec/language/next_spec.rb
|
411
411
|
- spec/language/or_spec.rb
|
412
412
|
- spec/language/predefined_spec.rb
|
413
|
+
- spec/language/proc_spec.rb
|
413
414
|
- spec/language/regexp_spec.rb
|
414
415
|
- spec/language/send_spec.rb
|
415
416
|
- spec/language/singleton_class_spec.rb
|
@@ -799,6 +800,7 @@ test_files:
|
|
799
800
|
- spec/language/next_spec.rb
|
800
801
|
- spec/language/or_spec.rb
|
801
802
|
- spec/language/predefined_spec.rb
|
803
|
+
- spec/language/proc_spec.rb
|
802
804
|
- spec/language/regexp_spec.rb
|
803
805
|
- spec/language/send_spec.rb
|
804
806
|
- spec/language/singleton_class_spec.rb
|