Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / js1_5 / extensions / regress-350312-03.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  * Mozilla Foundation.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s): Brendan Eich
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 = 350312;
40 var summary = 'Accessing wrong stack slot with nested catch/finally';
41 var actual = '';
42 var expect = '';
43
44
45 //-----------------------------------------------------------------------------
46 test();
47 //-----------------------------------------------------------------------------
48
49 function test()
50 {
51   enterFunc ('test');
52   printBugNumber(BUGNUMBER);
53   printStatus (summary);
54
55   var pfx  = "(function (x) {try {if (x > 41) throw x}",
56     cg1a = " catch (e if e === 42) {var v = 'catch guard 1 ' + e; actual += v + ',';print(v);}"
57     cg1b = " catch (e if e === 42) {var v = 'catch guard 1 + throw ' + e; actual += v + ',';print(v); throw e;}"
58     cg2  = " catch (e if e === 43) {var v = 'catch guard 2 ' + e; actual += v + ',';print(v)}"
59     cat  = " catch (e) {var v = 'catch all ' + e; print(v); if (e == 44) throw e}"
60     fin  = " finally{var v = 'fin'; actual += v + ',';print(v)}",
61     end  = "})";
62
63   var exphash  = {
64     pfx: "(function (y) { var result = ''; y = y + ',';",
65     cg1a: " result += (y === '42,') ? ('catch guard 1 ' + y):'';",
66     cg1b: " result += (y === '42,') ? ('catch guard 1 + throw ' + y):'';",
67     cg2:  " result += (y === '43,') ? ('catch guard 2 ' + y):'';",
68     cat:  " result += (y > 41) ? ('catch all ' + y):'';",
69     fin:  " result += 'fin,';",
70     end:  "return result;})"
71   };
72
73   var src = [
74     pfx + fin + end,
75     pfx + cat + end,
76     pfx + cat + fin + end,
77     pfx + cg1a + end,
78     pfx + cg1a + fin + end,
79     pfx + cg1a + cat + end,
80     pfx + cg1a + cat + fin + end,
81     pfx + cg1a + cg2 + end,
82     pfx + cg1a + cg2 + fin + end,
83     pfx + cg1a + cg2 + cat + end,
84     pfx + cg1a + cg2 + cat + fin + end,
85     pfx + cg1b + end,
86     pfx + cg1b + fin + end,
87     pfx + cg1b + cat + end,
88     pfx + cg1b + cat + fin + end,
89     pfx + cg1b + cg2 + end,
90     pfx + cg1b + cg2 + fin + end,
91     pfx + cg1b + cg2 + cat + end,
92     pfx + cg1b + cg2 + cat + fin + end,
93     ];
94
95   var expsrc = [
96     exphash.pfx + exphash.fin + exphash.end,
97     exphash.pfx + exphash.cat + exphash.end,
98     exphash.pfx + exphash.cat + exphash.fin + exphash.end,
99     exphash.pfx + exphash.cg1a + exphash.end,
100     exphash.pfx + exphash.cg1a + exphash.fin + exphash.end,
101     exphash.pfx + exphash.cg1a + exphash.cat + exphash.end,
102     exphash.pfx + exphash.cg1a + exphash.cat + exphash.fin + exphash.end,
103     exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.end,
104     exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.fin + exphash.end,
105     exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.cat + exphash.end,
106     exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.cat + exphash.fin + exphash.end,
107     exphash.pfx + exphash.cg1b + exphash.end,
108     exphash.pfx + exphash.cg1b + exphash.fin + exphash.end,
109     exphash.pfx + exphash.cg1b + exphash.cat + exphash.end,
110     exphash.pfx + exphash.cg1b + exphash.cat + exphash.fin + exphash.end,
111     exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.end,
112     exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.fin + exphash.end,
113     exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.cat + exphash.end,
114     exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.cat + exphash.fin + exphash.end,
115     ];
116
117   for (var i in src) {
118     print("\n=== " + i + ": " + src[i]);
119     var f = eval(src[i]);
120     var exp = eval(expsrc[i]);
121     // dis(f);
122     print('decompiling: ' + f);
123     //print('decompiling exp: ' + exp);
124
125     actual = '';
126     try { expect = exp(41); f(41) } catch (e) { print('tried f(41), caught ' + e) }
127     reportCompare(expect, actual, summary);
128
129     actual = '';
130     try { expect = exp(42); f(42) } catch (e) { print('tried f(42), caught ' + e) }
131     reportCompare(expect, actual, summary);
132
133     actual = '';
134     try { expect = exp(43); f(43) } catch (e) { print('tried f(43), caught ' + e) }
135     reportCompare(expect, actual, summary);
136
137     actual = '';
138     try { expect = exp(44); f(44) } catch (e) { print('tried f(44), caught ' + e) }
139     reportCompare(expect, actual, summary);
140
141     actual = '';
142     try { expect = exp(45); f(45) } catch (e) { print('tried f(44), caught ' + e) }
143     reportCompare(expect, actual, summary);
144
145   }
146
147   exitFunc ('test');
148 }