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