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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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