browser/devtools/webconsole/test/test-bug-632347-iterators-generators.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial