|
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 //----------------------------------------------------------------------------- |
|
7 var BUGNUMBER = 346494; |
|
8 var summary = 'various try...catch tests'; |
|
9 var actual = ''; |
|
10 var expect = ''; |
|
11 |
|
12 |
|
13 //----------------------------------------------------------------------------- |
|
14 test(); |
|
15 //----------------------------------------------------------------------------- |
|
16 |
|
17 function test() |
|
18 { |
|
19 enterFunc ('test'); |
|
20 printBugNumber(BUGNUMBER); |
|
21 printStatus (summary); |
|
22 |
|
23 var pfx = "(function (x) {try {throw x}", |
|
24 cg1 = " catch (e if e === 42) {var v = 'catch guard 1 ' + e; actual += v + ','; print(v);}" |
|
25 cg2 = " catch (e if e === 43) {var v = 'catch guard 2 ' + e; actual += v + ','; print(v);}" |
|
26 cat = " catch (e) {var v = 'catch all ' + e; actual += v + ','; print(v);}" |
|
27 fin = " finally{var v = 'fin'; actual += v + ','; print(v)}", |
|
28 end = "})"; |
|
29 |
|
30 var exphash = { |
|
31 pfx: "(function (y) { var result = ''; y = y + ',';", |
|
32 cg1: "result += (y === '42,') ? ('catch guard 1 ' + y):'';", |
|
33 cg2: "result += (y === '43,') ? ('catch guard 2 ' + y):'';", |
|
34 cat: "result += /catch guard/.test(result) ? '': ('catch all ' + y);", |
|
35 fin: "result += 'fin,';", |
|
36 end: "return result;})" |
|
37 }; |
|
38 |
|
39 var src = [ |
|
40 pfx + fin + end, |
|
41 pfx + cat + end, |
|
42 pfx + cat + fin + end, |
|
43 pfx + cg1 + end, |
|
44 pfx + cg1 + fin + end, |
|
45 pfx + cg1 + cat + end, |
|
46 pfx + cg1 + cat + fin + end, |
|
47 pfx + cg1 + cg2 + end, |
|
48 pfx + cg1 + cg2 + fin + end, |
|
49 pfx + cg1 + cg2 + cat + end, |
|
50 pfx + cg1 + cg2 + cat + fin + end, |
|
51 ]; |
|
52 |
|
53 var expsrc = [ |
|
54 exphash.pfx + exphash.fin + exphash.end, |
|
55 exphash.pfx + exphash.cat + exphash.end, |
|
56 exphash.pfx + exphash.cat + exphash.fin + exphash.end, |
|
57 exphash.pfx + exphash.cg1 + exphash.end, |
|
58 exphash.pfx + exphash.cg1 + exphash.fin + exphash.end, |
|
59 exphash.pfx + exphash.cg1 + exphash.cat + exphash.end, |
|
60 exphash.pfx + exphash.cg1 + exphash.cat + exphash.fin + exphash.end, |
|
61 exphash.pfx + exphash.cg1 + exphash.cg2 + exphash.end, |
|
62 exphash.pfx + exphash.cg1 + exphash.cg2 + exphash.fin + exphash.end, |
|
63 exphash.pfx + exphash.cg1 + exphash.cg2 + exphash.cat + exphash.end, |
|
64 exphash.pfx + exphash.cg1 + exphash.cg2 + exphash.cat + exphash.fin + exphash.end, |
|
65 ]; |
|
66 |
|
67 for (var i in src) { |
|
68 print("\n=== " + src[i]); |
|
69 var f = eval(src[i]); |
|
70 print(src[i]); |
|
71 var exp = eval(expsrc[i]); |
|
72 // dis(f); |
|
73 print('decompiling: ' + f); |
|
74 |
|
75 actual = ''; |
|
76 try { expect = exp(42); f(42) } catch (e) { print('tried f(42), caught ' + e) } |
|
77 reportCompare(expect, actual, summary); |
|
78 |
|
79 actual = ''; |
|
80 try { expect = exp(43); f(43) } catch (e) { print('tried f(43), caught ' + e) } |
|
81 reportCompare(expect, actual, summary); |
|
82 |
|
83 actual = ''; |
|
84 try { expect = exp(44); f(44) } catch (e) { print('tried f(44), caught ' + e) } |
|
85 reportCompare(expect, actual, summary); |
|
86 } |
|
87 |
|
88 |
|
89 exitFunc ('test'); |
|
90 } |