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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/test-bug-632347-iterators-generators.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,56 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html lang="en">
     1.6 +  <head>
     1.7 +    <meta charset="utf-8">
     1.8 +    <title>Web Console test for bug 632347 - iterators and generators</title>
     1.9 +    <!-- Any copyright is dedicated to the Public Domain.
    1.10 +         http://creativecommons.org/publicdomain/zero/1.0/ -->
    1.11 +<script type="application/javascript;version=1.8">
    1.12 +(function(){
    1.13 +function genFunc() {
    1.14 +  var a = 5;
    1.15 +  while (a < 10) {
    1.16 +    yield a++;
    1.17 +  }
    1.18 +}
    1.19 +
    1.20 +window._container = {};
    1.21 +
    1.22 +_container.gen1 = genFunc();
    1.23 +_container.gen1.next();
    1.24 +
    1.25 +var obj = { foo: "bar", baz: "baaz", hay: "stack" };
    1.26 +_container.iter1 = Iterator(obj);
    1.27 +
    1.28 +function Range(low, high) {
    1.29 +  this.low = low;
    1.30 +  this.high = high;
    1.31 +}
    1.32 +
    1.33 +function RangeIterator(range) {
    1.34 +  this.range = range;
    1.35 +  this.current = this.range.low;
    1.36 +}
    1.37 +
    1.38 +RangeIterator.prototype.next = function() {
    1.39 +  if (this.current > this.range.high) {
    1.40 +    throw StopIteration;
    1.41 +  } else {
    1.42 +    return this.current++;
    1.43 +  }
    1.44 +}
    1.45 +
    1.46 +Range.prototype.__iterator__ = function() {
    1.47 +  return new RangeIterator(this);
    1.48 +}
    1.49 +
    1.50 +_container.iter2 = new Range(3, 15);
    1.51 +
    1.52 +_container.gen2 = (i * 2 for (i in _container.iter2));
    1.53 +})();
    1.54 +</script>
    1.55 +  </head>
    1.56 +  <body>
    1.57 +    <p>Web Console test for bug 632347 - iterators and generators.</p>
    1.58 +  </body>
    1.59 +</html>

mercurial