Debian Codegraph @

rhino/testsrc/tests/js1_5/extensions/regress-350312-03.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 = 'regress-350312-03.js';
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = 350312;
9 var summary = 'Accessing wrong stack slot with nested catch/finally';
10 var actual = '';
11 var expect = '';
12
13
14 //-----------------------------------------------------------------------------
15 test();
16 //-----------------------------------------------------------------------------
17
18 function test()
19 {
20 enterFunc ('test');
21 printBugNumber(BUGNUMBER);
22 printStatus (summary);
23
24 var pfx = "(function (x) {try {if (x > 41) throw x}",
25 cg1a = " catch (e if e === 42) {var v = 'catch guard 1 ' + e; actual += v + ',';print(v);}"
26 cg1b = " catch (e if e === 42) {var v = 'catch guard 1 + throw ' + e; actual += v + ',';print(v); throw e;}"
27 cg2 = " catch (e if e === 43) {var v = 'catch guard 2 ' + e; actual += v + ',';print(v)}"
28 cat = " catch (e) {var v = 'catch all ' + e; print(v); if (e == 44) throw e}"
29 fin = " finally{var v = 'fin'; actual += v + ',';print(v)}",
30 end = "})";
31
32 var exphash = {
33 pfx: "(function (y) { var result = ''; y = y + ',';",
34 cg1a: " result += (y === '42,') ? ('catch guard 1 ' + y):'';",
35 cg1b: " result += (y === '42,') ? ('catch guard 1 + throw ' + y):'';",
36 cg2: " result += (y === '43,') ? ('catch guard 2 ' + y):'';",
37 cat: " result += (y > 41) ? ('catch all ' + y):'';",
38 fin: " result += 'fin,';",
39 end: "return result;})"
40 };
41
42 var src = [
43 pfx + fin + end,
44 pfx + cat + end,
45 pfx + cat + fin + end,
46 pfx + cg1a + end,
47 pfx + cg1a + fin + end,
48 pfx + cg1a + cat + end,
49 pfx + cg1a + cat + fin + end,
50 pfx + cg1a + cg2 + end,
51 pfx + cg1a + cg2 + fin + end,
52 pfx + cg1a + cg2 + cat + end,
53 pfx + cg1a + cg2 + cat + fin + end,
54 pfx + cg1b + end,
55 pfx + cg1b + fin + end,
56 pfx + cg1b + cat + end,
57 pfx + cg1b + cat + fin + end,
58 pfx + cg1b + cg2 + end,
59 pfx + cg1b + cg2 + fin + end,
60 pfx + cg1b + cg2 + cat + end,
61 pfx + cg1b + cg2 + cat + fin + end,
62 ];
63
64 var expsrc = [
65 exphash.pfx + exphash.fin + exphash.end,
66 exphash.pfx + exphash.cat + exphash.end,
67 exphash.pfx + exphash.cat + exphash.fin + exphash.end,
68 exphash.pfx + exphash.cg1a + exphash.end,
69 exphash.pfx + exphash.cg1a + exphash.fin + exphash.end,
70 exphash.pfx + exphash.cg1a + exphash.cat + exphash.end,
71 exphash.pfx + exphash.cg1a + exphash.cat + exphash.fin + exphash.end,
72 exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.end,
73 exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.fin + exphash.end,
74 exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.cat + exphash.end,
75 exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.cat + exphash.fin + exphash.end,
76 exphash.pfx + exphash.cg1b + exphash.end,
77 exphash.pfx + exphash.cg1b + exphash.fin + exphash.end,
78 exphash.pfx + exphash.cg1b + exphash.cat + exphash.end,
79 exphash.pfx + exphash.cg1b + exphash.cat + exphash.fin + exphash.end,
80 exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.end,
81 exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.fin + exphash.end,
82 exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.cat + exphash.end,
83 exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.cat + exphash.fin + exphash.end,
84 ];
85
86 for (var i in src) {
87 print("\n=== " + i + ": " + src[i]);
88 var f = eval(src[i]);
89 var exp = eval(expsrc[i]);
90 // dis(f);
91 print('decompiling: ' + f);
92 //print('decompiling exp: ' + exp);
93
94 actual = '';
95 try { expect = exp(41); f(41) } catch (e) { print('tried f(41), caught ' + e) }
96 reportCompare(expect, actual, summary);
97
98 actual = '';
99 try { expect = exp(42); f(42) } catch (e) { print('tried f(42), caught ' + e) }
100 reportCompare(expect, actual, summary);
101
102 actual = '';
103 try { expect = exp(43); f(43) } catch (e) { print('tried f(43), caught ' + e) }
104 reportCompare(expect, actual, summary);
105
106 actual = '';
107 try { expect = exp(44); f(44) } catch (e) { print('tried f(44), caught ' + e) }
108 reportCompare(expect, actual, summary);
109
110 actual = '';
111 try { expect = exp(45); f(45) } catch (e) { print('tried f(44), caught ' + e) }
112 reportCompare(expect, actual, summary);
113
114 }
115
116 exitFunc ('test');
117 }