Debian Codegraph @

rhino/testsrc/tests/js1_7/geniter/multiple-close.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 var gTestfile = 'multiple-close.js';
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = "(none)";
9 var summary = "calling it.close multiple times is harmless";
10 var actual, expect;
11
12 printBugNumber(BUGNUMBER);
13 printStatus(summary);
14
15 /**************
16 * BEGIN TEST *
17 **************/
18
19 function fib()
20 {
21 yield 0; // 0
22 yield 1; // 1
23 yield 1; // 2
24 yield 2; // 3
25 yield 3; // 4
26 yield 5; // 5
27 yield 8; // 6
28 }
29
30 var failed = false;
31 var it = fib();
32
33 try
34 {
35 if (it.next() != 0)
36 throw "0 failed";
37
38 // closing an already-closed generator is a no-op
39 it.close();
40 it.close();
41 it.close();
42
43 var stopPassed = false;
44 try
45 {
46 it.next();
47 }
48 catch (e)
49 {
50 if (e === StopIteration)
51 stopPassed = true;
52 }
53 if (!stopPassed)
54 throw "a closed iterator throws StopIteration on next";
55 }
56 catch (e)
57 {
58 failed = e;
59 }
60
61
62
63 expect = false;
64 actual = failed;
65
66 reportCompare(expect, actual, summary);