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