]> git.saurik.com Git - apple/javascriptcore.git/blame_incremental - tests/stress/raise-error-in-iterator-close.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / raise-error-in-iterator-close.js
... / ...
CommitLineData
1
2function createIterator(callback) {
3 var array = [0,1,2,3,4,5];
4 var iterator = array[Symbol.iterator]();
5 iterator.return = function () {
6 iterator.returned = true;
7 if (callback)
8 return callback(this);
9 return { done: true, value: undefined };
10 };
11 iterator.returned = false;
12 return iterator;
13}
14
15(function test() {
16 var outerIterator = createIterator();
17 var innerIterator = createIterator(function () {
18 throw new Error("Inner return called.");
19 });
20 var error = null;
21 try {
22 outer: for (var e1 of outerIterator) {
23 inner: for (var e2 of innerIterator) {
24 break;
25 }
26 }
27 } catch (e) {
28 error = e;
29 }
30 if (!error)
31 throw new Error("no error");
32 if (String(error) !== "Error: Inner return called.")
33 throw new Error("bad error: " + String(error));
34 if (!innerIterator.returned)
35 throw new Error("bad value: " + innerIterator.returned);
36 if (!outerIterator.returned)
37 throw new Error("bad value: " + outerIterator.returned);
38}());
39
40(function test() {
41 var outerIterator = createIterator(function () {
42 throw new Error("Outer return called.");
43 });
44 var innerIterator = createIterator(function () {
45 throw new Error("Inner return called.");
46 });
47 var error = null;
48 try {
49 outer: for (var e1 of outerIterator) {
50 inner: for (var e2 of innerIterator) {
51 break;
52 }
53 }
54 } catch (e) {
55 error = e;
56 }
57 if (!error)
58 throw new Error("no error");
59 if (String(error) !== "Error: Inner return called.")
60 throw new Error("bad error: " + String(error));
61 if (!innerIterator.returned)
62 throw new Error("bad value: " + innerIterator.returned);
63 if (!outerIterator.returned)
64 throw new Error("bad value: " + outerIterator.returned);
65}());
66
67(function test() {
68 var outerIterator = createIterator(function () {
69 throw new Error("Outer return called.");
70 });
71 var innerIterator = createIterator();
72 var error = null;
73 try {
74 outer: for (var e1 of outerIterator) {
75 inner: for (var e2 of innerIterator) {
76 break outer;
77 }
78 }
79 } catch (e) {
80 error = e;
81 }
82 if (!error)
83 throw new Error("no error");
84 if (String(error) !== "Error: Outer return called.")
85 throw new Error("bad error: " + String(error));
86 if (!innerIterator.returned)
87 throw new Error("bad value: " + innerIterator.returned);
88 if (!outerIterator.returned)
89 throw new Error("bad value: " + outerIterator.returned);
90}());
91
92(function test() {
93 var outerIterator = createIterator(function () {
94 throw new Error("Outer return called.");
95 });
96 var innerIterator = createIterator(function () {
97 throw new Error("Inner return called.");
98 });
99 var error = null;
100 try {
101 outer: for (var e1 of outerIterator) {
102 inner: for (var e2 of innerIterator) {
103 throw new Error("Loop raises error.");
104 }
105 }
106 } catch (e) {
107 error = e;
108 }
109 if (!error)
110 throw new Error("no error");
111 if (String(error) !== "Error: Loop raises error.")
112 throw new Error("bad error: " + String(error));
113 if (!innerIterator.returned)
114 throw new Error("bad value: " + innerIterator.returned);
115 if (!outerIterator.returned)
116 throw new Error("bad value: " + outerIterator.returned);
117}());
118