|
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.throw(ex) returns ex for an exhausted gen"; |
|
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 // throw works even on newly-initialized generators |
|
31 var thrown = "foobar"; |
|
32 var doThrow = true; |
|
33 try |
|
34 { |
|
35 it.throw(thrown); |
|
36 } |
|
37 catch (e) |
|
38 { |
|
39 if (e === thrown) |
|
40 doThrow = false; |
|
41 } |
|
42 if (doThrow) |
|
43 throw "it.throw(\"" + thrown + "\") failed"; |
|
44 |
|
45 // you can throw stuff at a generator which hasn't |
|
46 // been used yet forever |
|
47 thrown = "baz"; |
|
48 doThrow = true; |
|
49 try |
|
50 { |
|
51 it.throw(thrown); |
|
52 } |
|
53 catch (e) |
|
54 { |
|
55 if (e === thrown) |
|
56 doThrow = false; |
|
57 } |
|
58 if (doThrow) |
|
59 throw "it.throw(\"" + thrown + "\") failed"; |
|
60 |
|
61 // don't execute a yield -- the uncaught exception |
|
62 // exhausted the generator |
|
63 var stopPassed = false; |
|
64 try |
|
65 { |
|
66 it.next(); |
|
67 } |
|
68 catch (e) |
|
69 { |
|
70 if (e === StopIteration) |
|
71 stopPassed = true; |
|
72 } |
|
73 |
|
74 if (!stopPassed) |
|
75 throw "missing or incorrect StopIteration"; |
|
76 } |
|
77 catch (e) |
|
78 { |
|
79 failed = e; |
|
80 } |
|
81 |
|
82 expect = false; |
|
83 actual = failed; |
|
84 |
|
85 reportCompare(expect, actual, summary); |