Debian Codegraph @

rhino/testsrc/tests/js1_7/geniter/throw-forever.js

raw symbols SCIP
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 var gTestfile = 'throw-forever.js';
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = "(none)";
9 var summary = "gen.throw(ex) returns ex for an exhausted gen";
10 var actual, expect;
11
12 printBugNumber(BUGNUMBER);
13 printStatus(summary);
14
15 /**************
16 * BEGIN TEST *
17 **************/
18
19 function gen()
20 {
21 var x = 5, y = 7;
22 var z = x + y;
23 yield z;
24 }
25
26 var failed = false;
27 var it = gen();
28
29 try
30 {
31 // throw works even on newly-initialized generators
32 var thrown = "foobar";
33 var doThrow = true;
34 try
35 {
36 it.throw(thrown);
37 }
38 catch (e)
39 {
40 if (e === thrown)
41 doThrow = false;
42 }
43 if (doThrow)
44 throw "it.throw(\"" + thrown + "\") failed";
45
46 // you can throw stuff at a generator which hasn't
47 // been used yet forever
48 thrown = "baz";
49 doThrow = true;
50 try
51 {
52 it.throw(thrown);
53 }
54 catch (e)
55 {
56 if (e === thrown)
57 doThrow = false;
58 }
59 if (doThrow)
60 throw "it.throw(\"" + thrown + "\") failed";
61
62 // don't execute a yield -- the uncaught exception
63 // exhausted the generator
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 expect = false;
84 actual = failed;
85
86 reportCompare(expect, actual, summary);