Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / js1_7 / geniter / message-value-passing.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is JavaScript Engine testing utilities.
16  *
17  * The Initial Developer of the Original Code is
18  * Jeff Walden.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37
38 //-----------------------------------------------------------------------------
39 var BUGNUMBER     = 326466;
40 var summary = "Generator value/exception passing";
41 var actual, expect;
42
43 printBugNumber(BUGNUMBER);
44 printStatus(summary);
45
46 /**************
47  * BEGIN TEST *
48  **************/
49
50 function gen()
51 {
52   var rv, rv2, rv3, rv4;
53   rv = yield 1;
54
55   if (rv)
56     rv2 = yield rv;
57   else
58     rv3 = yield 2;
59
60   try
61   {
62     if (rv2)
63       yield rv2;
64     else
65       rv3 = yield 3;
66   }
67   catch (e)
68   {
69     if (e == 289)
70       yield "exception caught";
71   }
72
73   yield 5;
74 }
75
76 var failed = false;
77 var it = gen();
78
79 try
80 {
81   if (it.next() != 1)
82     throw "failed on 1";
83
84   if (it.send(17) != 17)
85     throw "failed on 17";
86
87   if (it.next() != 3)
88     throw "failed on 3";
89
90   if (it.throw(289) != "exception caught")
91     throw "it.throw(289) failed";
92
93   if (it.next() != 5)
94     throw "failed on 5";
95
96   var stopPassed = false;
97   try
98   {
99     it.next();
100   }
101   catch (e)
102   {
103     if (e === StopIteration)
104       stopPassed = true;
105   }
106
107   if (!stopPassed)
108     throw "missing or incorrect StopIteration";
109 }
110 catch (e)
111 {
112   failed = e;
113 }
114
115
116
117 expect = false;
118 actual = failed;
119
120 reportCompare(expect, actual, summary);