Debian Codegraph @

rhino/testsrc/tests/js1_7/geniter/throw-after-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 = 'throw-after-close.js';
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = "(none)";
9 var summary = "gen.close(); gen.throw(ex) throws ex forever";
10 var actual, expect;
11
12 printBugNumber(BUGNUMBER);
13 printStatus(summary);
14
15 /**************
16 * BEGIN TEST *
17 **************/
18
19 function gen()
20 {
21 var x = 5, y = 7;
22 var z = x + y;
23 yield z;
24 }
25
26 var failed = false;
27 var it = gen();
28
29 try
30 {
31 it.close();
32
33 // throw on closed generators just rethrows
34 var doThrow = true;
35 var thrown = "foobar";
36 try
37 {
38 it.throw(thrown);
39 }
40 catch (e)
41 {
42 if (e === thrown)
43 doThrow = false;
44 }
45
46 if (doThrow)
47 throw "it.throw(\"" + thrown + "\") failed";
48
49 // you can throw stuff at a closed generator forever
50 doThrow = true;
51 thrown = "sparky";
52 try
53 {
54 it.throw(thrown);
55 }
56 catch (e)
57 {
58 if (e === thrown)
59 doThrow = false;
60 }
61
62 if (doThrow)
63 throw "it.throw(\"" + thrown + "\") failed";
64
65 // don't execute a yield -- the uncaught exception
66 // exhausted the generator
67 var stopPassed = false;
68 try
69 {
70 it.next();
71 }
72 catch (e)
73 {
74 if (e === StopIteration)
75 stopPassed = true;
76 }
77
78 if (!stopPassed)
79 throw "invalid or incorrect StopIteration";
80 }
81 catch (e)
82 {
83 failed = e;
84 }
85
86
87
88 expect = false;
89 actual = failed;
90
91 reportCompare(expect, actual, summary);