|
1 <!DOCTYPE html> |
|
2 <html lang="en"> |
|
3 <head> |
|
4 <meta charset="utf-8"> |
|
5 <title>Web Console test for bug 632347 - iterators and generators</title> |
|
6 <!-- Any copyright is dedicated to the Public Domain. |
|
7 http://creativecommons.org/publicdomain/zero/1.0/ --> |
|
8 <script type="application/javascript;version=1.8"> |
|
9 (function(){ |
|
10 function genFunc() { |
|
11 var a = 5; |
|
12 while (a < 10) { |
|
13 yield a++; |
|
14 } |
|
15 } |
|
16 |
|
17 window._container = {}; |
|
18 |
|
19 _container.gen1 = genFunc(); |
|
20 _container.gen1.next(); |
|
21 |
|
22 var obj = { foo: "bar", baz: "baaz", hay: "stack" }; |
|
23 _container.iter1 = Iterator(obj); |
|
24 |
|
25 function Range(low, high) { |
|
26 this.low = low; |
|
27 this.high = high; |
|
28 } |
|
29 |
|
30 function RangeIterator(range) { |
|
31 this.range = range; |
|
32 this.current = this.range.low; |
|
33 } |
|
34 |
|
35 RangeIterator.prototype.next = function() { |
|
36 if (this.current > this.range.high) { |
|
37 throw StopIteration; |
|
38 } else { |
|
39 return this.current++; |
|
40 } |
|
41 } |
|
42 |
|
43 Range.prototype.__iterator__ = function() { |
|
44 return new RangeIterator(this); |
|
45 } |
|
46 |
|
47 _container.iter2 = new Range(3, 15); |
|
48 |
|
49 _container.gen2 = (i * 2 for (i in _container.iter2)); |
|
50 })(); |
|
51 </script> |
|
52 </head> |
|
53 <body> |
|
54 <p>Web Console test for bug 632347 - iterators and generators.</p> |
|
55 </body> |
|
56 </html> |