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

     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 }
    17 window._container = {};
    19 _container.gen1 = genFunc();
    20 _container.gen1.next();
    22 var obj = { foo: "bar", baz: "baaz", hay: "stack" };
    23 _container.iter1 = Iterator(obj);
    25 function Range(low, high) {
    26   this.low = low;
    27   this.high = high;
    28 }
    30 function RangeIterator(range) {
    31   this.range = range;
    32   this.current = this.range.low;
    33 }
    35 RangeIterator.prototype.next = function() {
    36   if (this.current > this.range.high) {
    37     throw StopIteration;
    38   } else {
    39     return this.current++;
    40   }
    41 }
    43 Range.prototype.__iterator__ = function() {
    44   return new RangeIterator(this);
    45 }
    47 _container.iter2 = new Range(3, 15);
    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>

mercurial