1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/extensions/regress-104077.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,196 @@ 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 + * 1.11 + * Date: 10 October 2001 1.12 + * SUMMARY: Regression test for Bugzilla bug 104077 1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=104077 1.14 + * "JS crash: with/finally/return" 1.15 + * 1.16 + * Also http://bugzilla.mozilla.org/show_bug.cgi?id=120571 1.17 + * "JS crash: try/catch/continue." 1.18 + * 1.19 + * SpiderMonkey crashed on this code - it shouldn't. 1.20 + * 1.21 + * NOTE: the finally-blocks below should execute even if their try-blocks 1.22 + * have return or throw statements in them: 1.23 + * 1.24 + * ------- Additional Comment #76 From Mike Shaver 2001-12-07 01:21 ------- 1.25 + * finally trumps return, and all other control-flow constructs that cause 1.26 + * program execution to jump out of the try block: throw, break, etc. Once you 1.27 + * enter a try block, you will execute the finally block after leaving the try, 1.28 + * regardless of what happens to make you leave the try. 1.29 + * 1.30 + */ 1.31 +//----------------------------------------------------------------------------- 1.32 +var UBound = 0; 1.33 +var BUGNUMBER = 104077; 1.34 +var summary = "Just testing that we don't crash on with/finally/return -"; 1.35 +var status = ''; 1.36 +var statusitems = []; 1.37 +var actual = ''; 1.38 +var actualvalues = []; 1.39 +var expect= ''; 1.40 +var expectedvalues = []; 1.41 + 1.42 + 1.43 +function addValues_3(obj) 1.44 +{ 1.45 + var sum = 0; 1.46 + 1.47 + with (obj) 1.48 + { 1.49 + try 1.50 + { 1.51 + sum = arg1 + arg2; 1.52 + with (arg3) 1.53 + { 1.54 + while (sum < 10) 1.55 + { 1.56 + try 1.57 + { 1.58 + if (sum > 5) 1.59 + return sum; 1.60 + sum += 1; 1.61 + } 1.62 + catch (e) 1.63 + { 1.64 + sum += 1; 1.65 + } 1.66 + } 1.67 + } 1.68 + } 1.69 + finally 1.70 + { 1.71 + try 1.72 + { 1.73 + sum +=1; 1.74 + print("In finally block of addValues_3() function: sum = " + sum); 1.75 + } 1.76 + catch (e if e == 42) 1.77 + { 1.78 + sum +=1; 1.79 + print('In finally catch block of addValues_3() function: sum = ' + sum + ', e = ' + e); 1.80 + } 1.81 + finally 1.82 + { 1.83 + sum +=1; 1.84 + print("In finally finally block of addValues_3() function: sum = " + sum); 1.85 + return sum; 1.86 + } 1.87 + } 1.88 + } 1.89 +} 1.90 + 1.91 +status = inSection(9); 1.92 +obj = new Object(); 1.93 +obj.arg1 = 1; 1.94 +obj.arg2 = 2; 1.95 +obj.arg3 = new Object(); 1.96 +obj.arg3.a = 10; 1.97 +obj.arg3.b = 20; 1.98 +actual = addValues_3(obj); 1.99 +expect = 8; 1.100 +captureThis(); 1.101 + 1.102 + 1.103 + 1.104 + 1.105 +function addValues_4(obj) 1.106 +{ 1.107 + var sum = 0; 1.108 + 1.109 + with (obj) 1.110 + { 1.111 + try 1.112 + { 1.113 + sum = arg1 + arg2; 1.114 + with (arg3) 1.115 + { 1.116 + while (sum < 10) 1.117 + { 1.118 + try 1.119 + { 1.120 + if (sum > 5) 1.121 + return sum; 1.122 + sum += 1; 1.123 + } 1.124 + catch (e) 1.125 + { 1.126 + sum += 1; 1.127 + } 1.128 + } 1.129 + } 1.130 + } 1.131 + finally 1.132 + { 1.133 + try 1.134 + { 1.135 + sum += 1; 1.136 + print("In finally block of addValues_4() function: sum = " + sum); 1.137 + } 1.138 + catch (e if e == 42) 1.139 + { 1.140 + sum += 1; 1.141 + print("In 1st finally catch block of addValues_4() function: sum = " + sum + ", e = " + e); 1.142 + } 1.143 + catch (e if e == 43) 1.144 + { 1.145 + sum += 1; 1.146 + print("In 2nd finally catch block of addValues_4() function: sum = " + sum + ", e = " + e); 1.147 + } 1.148 + finally 1.149 + { 1.150 + sum += 1; 1.151 + print("In finally finally block of addValues_4() function: sum = " + sum); 1.152 + return sum; 1.153 + } 1.154 + } 1.155 + } 1.156 +} 1.157 + 1.158 +status = inSection(10); 1.159 +obj = new Object(); 1.160 +obj.arg1 = 1; 1.161 +obj.arg2 = 2; 1.162 +obj.arg3 = new Object(); 1.163 +obj.arg3.a = 10; 1.164 +obj.arg3.b = 20; 1.165 +actual = addValues_4(obj); 1.166 +expect = 8; 1.167 +captureThis(); 1.168 + 1.169 + 1.170 + 1.171 + 1.172 +//----------------------------------------------------------------------------- 1.173 +test(); 1.174 +//----------------------------------------------------------------------------- 1.175 + 1.176 + 1.177 + 1.178 +function captureThis() 1.179 +{ 1.180 + statusitems[UBound] = status; 1.181 + actualvalues[UBound] = actual; 1.182 + expectedvalues[UBound] = expect; 1.183 + UBound++; 1.184 +} 1.185 + 1.186 + 1.187 +function test() 1.188 +{ 1.189 + enterFunc ('test'); 1.190 + printBugNumber(BUGNUMBER); 1.191 + printStatus (summary); 1.192 + 1.193 + for (var i=0; i<UBound; i++) 1.194 + { 1.195 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.196 + } 1.197 + 1.198 + exitFunc ('test'); 1.199 +}