michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 350312; michael@0: var summary = 'Accessing wrong stack slot with nested catch/finally'; michael@0: var actual = ''; michael@0: var expect = ''; michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: var pfx = "(function (x) {try {if (x > 41) throw x}", michael@0: cg1a = " catch (e if e === 42) {var v = 'catch guard 1 ' + e; actual += v + ',';print(v);}" michael@0: cg1b = " catch (e if e === 42) {var v = 'catch guard 1 + throw ' + e; actual += v + ',';print(v); throw e;}" michael@0: cg2 = " catch (e if e === 43) {var v = 'catch guard 2 ' + e; actual += v + ',';print(v)}" michael@0: cat = " catch (e) {var v = 'catch all ' + e; print(v); if (e == 44) throw e}" michael@0: fin = " finally{var v = 'fin'; actual += v + ',';print(v)}", michael@0: end = "})"; michael@0: michael@0: var exphash = { michael@0: pfx: "(function (y) { var result = ''; y = y + ',';", michael@0: cg1a: " result += (y === '42,') ? ('catch guard 1 ' + y):'';", michael@0: cg1b: " result += (y === '42,') ? ('catch guard 1 + throw ' + y):'';", michael@0: cg2: " result += (y === '43,') ? ('catch guard 2 ' + y):'';", michael@0: cat: " result += (y > 41) ? ('catch all ' + y):'';", michael@0: fin: " result += 'fin,';", michael@0: end: "return result;})" michael@0: }; michael@0: michael@0: var src = [ michael@0: pfx + fin + end, michael@0: pfx + cat + end, michael@0: pfx + cat + fin + end, michael@0: pfx + cg1a + end, michael@0: pfx + cg1a + fin + end, michael@0: pfx + cg1a + cat + end, michael@0: pfx + cg1a + cat + fin + end, michael@0: pfx + cg1a + cg2 + end, michael@0: pfx + cg1a + cg2 + fin + end, michael@0: pfx + cg1a + cg2 + cat + end, michael@0: pfx + cg1a + cg2 + cat + fin + end, michael@0: pfx + cg1b + end, michael@0: pfx + cg1b + fin + end, michael@0: pfx + cg1b + cat + end, michael@0: pfx + cg1b + cat + fin + end, michael@0: pfx + cg1b + cg2 + end, michael@0: pfx + cg1b + cg2 + fin + end, michael@0: pfx + cg1b + cg2 + cat + end, michael@0: pfx + cg1b + cg2 + cat + fin + end, michael@0: ]; michael@0: michael@0: var expsrc = [ michael@0: exphash.pfx + exphash.fin + exphash.end, michael@0: exphash.pfx + exphash.cat + exphash.end, michael@0: exphash.pfx + exphash.cat + exphash.fin + exphash.end, michael@0: exphash.pfx + exphash.cg1a + exphash.end, michael@0: exphash.pfx + exphash.cg1a + exphash.fin + exphash.end, michael@0: exphash.pfx + exphash.cg1a + exphash.cat + exphash.end, michael@0: exphash.pfx + exphash.cg1a + exphash.cat + exphash.fin + exphash.end, michael@0: exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.end, michael@0: exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.fin + exphash.end, michael@0: exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.cat + exphash.end, michael@0: exphash.pfx + exphash.cg1a + exphash.cg2 + exphash.cat + exphash.fin + exphash.end, michael@0: exphash.pfx + exphash.cg1b + exphash.end, michael@0: exphash.pfx + exphash.cg1b + exphash.fin + exphash.end, michael@0: exphash.pfx + exphash.cg1b + exphash.cat + exphash.end, michael@0: exphash.pfx + exphash.cg1b + exphash.cat + exphash.fin + exphash.end, michael@0: exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.end, michael@0: exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.fin + exphash.end, michael@0: exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.cat + exphash.end, michael@0: exphash.pfx + exphash.cg1b + exphash.cg2 + exphash.cat + exphash.fin + exphash.end, michael@0: ]; michael@0: michael@0: for (var i in src) { michael@0: print("\n=== " + i + ": " + src[i]); michael@0: var f = eval(src[i]); michael@0: var exp = eval(expsrc[i]); michael@0: // dis(f); michael@0: print('decompiling: ' + f); michael@0: //print('decompiling exp: ' + exp); michael@0: michael@0: actual = ''; michael@0: try { expect = exp(41); f(41) } catch (e) { print('tried f(41), caught ' + e) } michael@0: reportCompare(expect, actual, summary); michael@0: michael@0: actual = ''; michael@0: try { expect = exp(42); f(42) } catch (e) { print('tried f(42), caught ' + e) } michael@0: reportCompare(expect, actual, summary); michael@0: michael@0: actual = ''; michael@0: try { expect = exp(43); f(43) } catch (e) { print('tried f(43), caught ' + e) } michael@0: reportCompare(expect, actual, summary); michael@0: michael@0: actual = ''; michael@0: try { expect = exp(44); f(44) } catch (e) { print('tried f(44), caught ' + e) } michael@0: reportCompare(expect, actual, summary); michael@0: michael@0: actual = ''; michael@0: try { expect = exp(45); f(45) } catch (e) { print('tried f(44), caught ' + e) } michael@0: reportCompare(expect, actual, summary); michael@0: michael@0: } michael@0: michael@0: exitFunc ('test'); michael@0: }