1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/extensions/regress-350312-03.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,116 @@ 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 = 350312; 1.11 +var summary = 'Accessing wrong stack slot with nested catch/finally'; 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 {if (x > 41) throw x}", 1.27 + cg1a = " catch (e if e === 42) {var v = 'catch guard 1 ' + e; actual += v + ',';print(v);}" 1.28 + cg1b = " catch (e if e === 42) {var v = 'catch guard 1 + throw ' + e; actual += v + ',';print(v); throw e;}" 1.29 + cg2 = " catch (e if e === 43) {var v = 'catch guard 2 ' + e; actual += v + ',';print(v)}" 1.30 + cat = " catch (e) {var v = 'catch all ' + e; print(v); if (e == 44) throw e}" 1.31 + fin = " finally{var v = 'fin'; actual += v + ',';print(v)}", 1.32 + end = "})"; 1.33 + 1.34 + var exphash = { 1.35 + pfx: "(function (y) { var result = ''; y = y + ',';", 1.36 + cg1a: " result += (y === '42,') ? ('catch guard 1 ' + y):'';", 1.37 + cg1b: " result += (y === '42,') ? ('catch guard 1 + throw ' + y):'';", 1.38 + cg2: " result += (y === '43,') ? ('catch guard 2 ' + y):'';", 1.39 + cat: " result += (y > 41) ? ('catch all ' + y):'';", 1.40 + fin: " result += 'fin,';", 1.41 + end: "return result;})" 1.42 + }; 1.43 + 1.44 + var src = [ 1.45 + pfx + fin + end, 1.46 + pfx + cat + end, 1.47 + pfx + cat + fin + end, 1.48 + pfx + cg1a + end, 1.49 + pfx + cg1a + fin + end, 1.50 + pfx + cg1a + cat + end, 1.51 + pfx + cg1a + cat + fin + end, 1.52 + pfx + cg1a + cg2 + end, 1.53 + pfx + cg1a + cg2 + fin + end, 1.54 + pfx + cg1a + cg2 + cat + end, 1.55 + pfx + cg1a + cg2 + cat + fin + end, 1.56 + pfx + cg1b + end, 1.57 + pfx + cg1b + fin + end, 1.58 + pfx + cg1b + cat + end, 1.59 + pfx + cg1b + cat + fin + end, 1.60 + pfx + cg1b + cg2 + end, 1.61 + pfx + cg1b + cg2 + fin + end, 1.62 + pfx + cg1b + cg2 + cat + end, 1.63 + pfx + cg1b + cg2 + cat + fin + end, 1.64 + ]; 1.65 + 1.66 + var expsrc = [ 1.67 + exphash.pfx + exphash.fin + exphash.end, 1.68 + exphash.pfx + exphash.cat + exphash.end, 1.69 + exphash.pfx + exphash.cat + exphash.fin + exphash.end, 1.70 + exphash.pfx + exphash.cg1a + exphash.end, 1.71 + exphash.pfx + exphash.cg1a + exphash.fin + exphash.end, 1.72 + exphash.pfx + exphash.cg1a + exphash.cat + exphash.end, 1.73 + exphash.pfx + exphash.cg1a + exphash.cat + exphash.fin + exphash.end, 1.74 + exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.end, 1.75 + exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.fin + exphash.end, 1.76 + exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.cat + exphash.end, 1.77 + exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.cat + exphash.fin + exphash.end, 1.78 + exphash.pfx + exphash.cg1b + exphash.end, 1.79 + exphash.pfx + exphash.cg1b + exphash.fin + exphash.end, 1.80 + exphash.pfx + exphash.cg1b + exphash.cat + exphash.end, 1.81 + exphash.pfx + exphash.cg1b + exphash.cat + exphash.fin + exphash.end, 1.82 + exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.end, 1.83 + exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.fin + exphash.end, 1.84 + exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.cat + exphash.end, 1.85 + exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.cat + exphash.fin + exphash.end, 1.86 + ]; 1.87 + 1.88 + for (var i in src) { 1.89 + print("\n=== " + i + ": " + src[i]); 1.90 + var f = eval(src[i]); 1.91 + var exp = eval(expsrc[i]); 1.92 + // dis(f); 1.93 + print('decompiling: ' + f); 1.94 + //print('decompiling exp: ' + exp); 1.95 + 1.96 + actual = ''; 1.97 + try { expect = exp(41); f(41) } catch (e) { print('tried f(41), caught ' + e) } 1.98 + reportCompare(expect, actual, summary); 1.99 + 1.100 + actual = ''; 1.101 + try { expect = exp(42); f(42) } catch (e) { print('tried f(42), caught ' + e) } 1.102 + reportCompare(expect, actual, summary); 1.103 + 1.104 + actual = ''; 1.105 + try { expect = exp(43); f(43) } catch (e) { print('tried f(43), caught ' + e) } 1.106 + reportCompare(expect, actual, summary); 1.107 + 1.108 + actual = ''; 1.109 + try { expect = exp(44); f(44) } catch (e) { print('tried f(44), caught ' + e) } 1.110 + reportCompare(expect, actual, summary); 1.111 + 1.112 + actual = ''; 1.113 + try { expect = exp(45); f(45) } catch (e) { print('tried f(44), caught ' + e) } 1.114 + reportCompare(expect, actual, summary); 1.115 + 1.116 + } 1.117 + 1.118 + exitFunc ('test'); 1.119 +}