|
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 = 326466; |
|
8 var summary = "Generator value/exception passing"; |
|
9 var actual, expect; |
|
10 |
|
11 printBugNumber(BUGNUMBER); |
|
12 printStatus(summary); |
|
13 |
|
14 /************** |
|
15 * BEGIN TEST * |
|
16 **************/ |
|
17 |
|
18 function gen() |
|
19 { |
|
20 var rv, rv2, rv3, rv4; |
|
21 rv = yield 1; |
|
22 |
|
23 if (rv) |
|
24 rv2 = yield rv; |
|
25 else |
|
26 rv3 = yield 2; |
|
27 |
|
28 try |
|
29 { |
|
30 if (rv2) |
|
31 yield rv2; |
|
32 else |
|
33 rv3 = yield 3; |
|
34 } |
|
35 catch (e) |
|
36 { |
|
37 if (e == 289) |
|
38 yield "exception caught"; |
|
39 } |
|
40 |
|
41 yield 5; |
|
42 } |
|
43 |
|
44 var failed = false; |
|
45 var it = gen(); |
|
46 |
|
47 try |
|
48 { |
|
49 if (it.next() != 1) |
|
50 throw "failed on 1"; |
|
51 |
|
52 if (it.send(17) != 17) |
|
53 throw "failed on 17"; |
|
54 |
|
55 if (it.next() != 3) |
|
56 throw "failed on 3"; |
|
57 |
|
58 if (it.throw(289) != "exception caught") |
|
59 throw "it.throw(289) failed"; |
|
60 |
|
61 if (it.next() != 5) |
|
62 throw "failed on 5"; |
|
63 |
|
64 var stopPassed = false; |
|
65 try |
|
66 { |
|
67 it.next(); |
|
68 } |
|
69 catch (e) |
|
70 { |
|
71 if (e === StopIteration) |
|
72 stopPassed = true; |
|
73 } |
|
74 |
|
75 if (!stopPassed) |
|
76 throw "missing or incorrect StopIteration"; |
|
77 } |
|
78 catch (e) |
|
79 { |
|
80 failed = e; |
|
81 } |
|
82 |
|
83 |
|
84 |
|
85 expect = false; |
|
86 actual = failed; |
|
87 |
|
88 reportCompare(expect, actual, summary); |