test-bug-632347-iterators-generators.html 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. window._container = {};
  17. _container.gen1 = genFunc();
  18. _container.gen1.next();
  19. var obj = { foo: "bar", baz: "baaz", hay: "stack" };
  20. _container.iter1 = Iterator(obj);
  21. function Range(low, high) {
  22. this.low = low;
  23. this.high = high;
  24. }
  25. function RangeIterator(range) {
  26. this.range = range;
  27. this.current = this.range.low;
  28. }
  29. RangeIterator.prototype.next = function() {
  30. if (this.current > this.range.high) {
  31. throw StopIteration;
  32. } else {
  33. return this.current++;
  34. }
  35. }
  36. Range.prototype.__iterator__ = function() {
  37. return new RangeIterator(this);
  38. }
  39. _container.iter2 = new Range(3, 15);
  40. _container.gen2 = (function* () { for (let i in _container.iter2) yield i * 2; })();
  41. })();
  42. </script>
  43. </head>
  44. <body>
  45. <p>Web Console test for bug 632347 - iterators and generators.</p>
  46. </body>
  47. </html>