1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/extensions/regress-346494-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +//----------------------------------------------------------------------------- 1.10 +var BUGNUMBER = 346494; 1.11 +var summary = 'various try...catch tests'; 1.12 +var actual = ''; 1.13 +var expect = ''; 1.14 + 1.15 + 1.16 +//----------------------------------------------------------------------------- 1.17 +test(); 1.18 +//----------------------------------------------------------------------------- 1.19 + 1.20 +function test() 1.21 +{ 1.22 + enterFunc ('test'); 1.23 + printBugNumber(BUGNUMBER); 1.24 + printStatus (summary); 1.25 + 1.26 + var pfx = "(function (x) {try {throw x}", 1.27 + cg1 = " catch (e if e === 42) {var v = 'catch guard 1 ' + e; actual += v + ','; print(v);}" 1.28 + cg2 = " catch (e if e === 43) {var v = 'catch guard 2 ' + e; actual += v + ','; print(v);}" 1.29 + cat = " catch (e) {var v = 'catch all ' + e; actual += v + ','; print(v);}" 1.30 + fin = " finally{var v = 'fin'; actual += v + ','; print(v)}", 1.31 + end = "})"; 1.32 + 1.33 + var exphash = { 1.34 + pfx: "(function (y) { var result = ''; y = y + ',';", 1.35 + cg1: "result += (y === '42,') ? ('catch guard 1 ' + y):'';", 1.36 + cg2: "result += (y === '43,') ? ('catch guard 2 ' + y):'';", 1.37 + cat: "result += /catch guard/.test(result) ? '': ('catch all ' + y);", 1.38 + fin: "result += 'fin,';", 1.39 + end: "return result;})" 1.40 + }; 1.41 + 1.42 + var src = [ 1.43 + pfx + fin + end, 1.44 + pfx + cat + end, 1.45 + pfx + cat + fin + end, 1.46 + pfx + cg1 + end, 1.47 + pfx + cg1 + fin + end, 1.48 + pfx + cg1 + cat + end, 1.49 + pfx + cg1 + cat + fin + end, 1.50 + pfx + cg1 + cg2 + end, 1.51 + pfx + cg1 + cg2 + fin + end, 1.52 + pfx + cg1 + cg2 + cat + end, 1.53 + pfx + cg1 + cg2 + cat + fin + end, 1.54 + ]; 1.55 + 1.56 + var expsrc = [ 1.57 + exphash.pfx + exphash.fin + exphash.end, 1.58 + exphash.pfx + exphash.cat + exphash.end, 1.59 + exphash.pfx + exphash.cat + exphash.fin + exphash.end, 1.60 + exphash.pfx + exphash.cg1 + exphash.end, 1.61 + exphash.pfx + exphash.cg1 + exphash.fin + exphash.end, 1.62 + exphash.pfx + exphash.cg1 + exphash.cat + exphash.end, 1.63 + exphash.pfx + exphash.cg1 + exphash.cat + exphash.fin + exphash.end, 1.64 + exphash.pfx + exphash.cg1 + exphash.cg2 + exphash.end, 1.65 + exphash.pfx + exphash.cg1 + exphash.cg2 + exphash.fin + exphash.end, 1.66 + exphash.pfx + exphash.cg1 + exphash.cg2 + exphash.cat + exphash.end, 1.67 + exphash.pfx + exphash.cg1 + exphash.cg2 + exphash.cat + exphash.fin + exphash.end, 1.68 + ]; 1.69 + 1.70 + for (var i in src) { 1.71 + print("\n=== " + src[i]); 1.72 + var f = eval(src[i]); 1.73 + print(src[i]); 1.74 + var exp = eval(expsrc[i]); 1.75 + // dis(f); 1.76 + print('decompiling: ' + f); 1.77 + 1.78 + actual = ''; 1.79 + try { expect = exp(42); f(42) } catch (e) { print('tried f(42), caught ' + e) } 1.80 + reportCompare(expect, actual, summary); 1.81 + 1.82 + actual = ''; 1.83 + try { expect = exp(43); f(43) } catch (e) { print('tried f(43), caught ' + e) } 1.84 + reportCompare(expect, actual, summary); 1.85 + 1.86 + actual = ''; 1.87 + try { expect = exp(44); f(44) } catch (e) { print('tried f(44), caught ' + e) } 1.88 + reportCompare(expect, actual, summary); 1.89 + } 1.90 + 1.91 + 1.92 + exitFunc ('test'); 1.93 +}