|
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 = 349331; |
|
8 var summary = 'generator.close without GeneratorExit'; |
|
9 var actual = ''; |
|
10 var expect = ''; |
|
11 |
|
12 |
|
13 //----------------------------------------------------------------------------- |
|
14 test(); |
|
15 //----------------------------------------------------------------------------- |
|
16 |
|
17 function test() |
|
18 { |
|
19 enterFunc ('test'); |
|
20 printBugNumber(BUGNUMBER); |
|
21 printStatus (summary); |
|
22 |
|
23 var catch1, catch2, catch3, finally1, finally2, finally3; |
|
24 var iter; |
|
25 |
|
26 function gen() |
|
27 { |
|
28 yield 1; |
|
29 try { |
|
30 try { |
|
31 try { |
|
32 yield 2; |
|
33 } catch (e) { |
|
34 catch1 = true; |
|
35 } finally { |
|
36 finally1 = true; |
|
37 } |
|
38 } catch (e) { |
|
39 catch2 = true; |
|
40 } finally { |
|
41 finally2 = true; |
|
42 } |
|
43 } catch (e) { |
|
44 catch3 = true; |
|
45 } finally { |
|
46 finally3 = true; |
|
47 } |
|
48 } |
|
49 |
|
50 // test explicit close call |
|
51 catch1 = catch2 = catch3 = finally1 = finally2 = finally3 = false; |
|
52 iter = gen(); |
|
53 iter.next(); |
|
54 iter.next(); |
|
55 iter.close(); |
|
56 |
|
57 var passed = !catch1 && !catch2 && !catch3 && finally1 && finally2 && |
|
58 finally3; |
|
59 |
|
60 if (!passed) { |
|
61 print("Failed!"); |
|
62 print("catch1=" + catch1 + " catch2=" + catch2 + " catch3=" + |
|
63 catch3); |
|
64 print("finally1=" + finally1 + " finally2=" + finally2 + |
|
65 " finally3=" + finally3); |
|
66 } |
|
67 |
|
68 reportCompare(true, passed, 'test explicit close call'); |
|
69 |
|
70 // test for-in invoked close |
|
71 catch1 = catch2 = catch3 = finally1 = finally2 = finally3 = false; |
|
72 iter = gen(); |
|
73 for (var i in iter) { |
|
74 if (i == 2) |
|
75 break; |
|
76 } |
|
77 |
|
78 var passed = !catch1 && !catch2 && !catch3 && finally1 && finally2 && |
|
79 finally3; |
|
80 |
|
81 if (!passed) { |
|
82 print("Failed!"); |
|
83 print("catch1=" + catch1 + " catch2=" + catch2 + " catch3=" + |
|
84 catch3); |
|
85 print("finally1=" + finally1 + " finally2=" + finally2 + |
|
86 " finally3="+finally3); |
|
87 } |
|
88 reportCompare(true, passed, 'test GC-invoke close'); |
|
89 |
|
90 reportCompare(expect, actual, summary); |
|
91 |
|
92 exitFunc ('test'); |
|
93 } |