1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/extensions/regress-226507.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,153 @@ 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: 24 Nov 2003 1.12 + * SUMMARY: Testing for recursion check in js_EmitTree 1.13 + * 1.14 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=226507 1.15 + * Igor's comments: 1.16 + * 1.17 + * "For example, with N in the test set to 35, I got on my RedHat 1.18 + * Linux 10 box a segmentation fault from js after setting the stack limit 1.19 + * to 100K. When I set the stack limit to 20K I still got the segmentation fault. 1.20 + * Only after -s was changed to 15K, too-deep recursion was detected: 1.21 + * 1.22 + 1.23 + ~/w/js/x> ulimit -s 1.24 + 100 1.25 + ~/w/js/x> js fintest.js 1.26 + Segmentation fault 1.27 + ~/w/js/x> js -S $((20*1024)) fintest.js 1.28 + Segmentation fault 1.29 + ~/w/js/x> js -S $((15*1024)) fintest.js 1.30 + fintest.js:19: InternalError: too much recursion 1.31 + 1.32 + * 1.33 + * After playing with numbers it seems that while processing try/finally the 1.34 + * recursion in js_Emit takes 10 times more space the corresponding recursion 1.35 + * in the parser." 1.36 + * 1.37 + * 1.38 + * Note the use of the new -S option to the JS shell to limit stack size. 1.39 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=225061. This in turn 1.40 + * can be passed to the JS shell by the test driver's -o option, as in: 1.41 + * 1.42 + * perl jsDriver.pl -e smdebug -fTEST.html -o "-S 100" -l js1_5/Regress 1.43 + * 1.44 + */ 1.45 +//----------------------------------------------------------------------------- 1.46 +var UBound = 0; 1.47 +var BUGNUMBER = 226507; 1.48 +var summary = 'Testing for recursion check in js_EmitTree'; 1.49 +var status = ''; 1.50 +var statusitems = []; 1.51 +var actual = ''; 1.52 +var actualvalues = []; 1.53 +var expect= ''; 1.54 +var expectedvalues = []; 1.55 + 1.56 + 1.57 +/* 1.58 + * With stack limit 100K on Linux debug build even N=30 already can cause 1.59 + * stack overflow; use 35 to trigger it for sure. 1.60 + */ 1.61 +var N = 350; 1.62 + 1.63 +var counter = 0; 1.64 +function f() 1.65 +{ 1.66 + ++counter; 1.67 +} 1.68 + 1.69 + 1.70 +/* 1.71 + * Example: if N were 3, this is what |source| 1.72 + * would end up looking like: 1.73 + * 1.74 + * try { f(); } finally { 1.75 + * try { f(); } finally { 1.76 + * try { f(); } finally { 1.77 + * f(1,1,1,1); 1.78 + * }}} 1.79 + * 1.80 + */ 1.81 +var source = "".concat( 1.82 + repeat_str("try { f(); } finally {\n", N), 1.83 + "f(", 1.84 + repeat_str("1,", N), 1.85 + "1);\n", 1.86 + repeat_str("}", N)); 1.87 + 1.88 +// Repeat it for additional stress testing 1.89 +source += source; 1.90 + 1.91 +/* 1.92 + * In Rhino, eval() always uses interpreted mode. 1.93 + * To use compiled mode, use Script.exec() instead. 1.94 + */ 1.95 +if (typeof Script == 'undefined') 1.96 +{ 1.97 + print('Test skipped. Script not defined.'); 1.98 + expect = actual = 0; 1.99 +} 1.100 +else 1.101 +{ 1.102 + try 1.103 + { 1.104 + var script = Script(source); 1.105 + script(); 1.106 + 1.107 + 1.108 + status = inSection(1); 1.109 + actual = counter; 1.110 + expect = (N + 1) * 2; 1.111 + } 1.112 + catch(ex) 1.113 + { 1.114 + actual = ex + ''; 1.115 + } 1.116 +} 1.117 +addThis(); 1.118 + 1.119 + 1.120 +//----------------------------------------------------------------------------- 1.121 +test(); 1.122 +//----------------------------------------------------------------------------- 1.123 + 1.124 + 1.125 + 1.126 +function repeat_str(str, repeat_count) 1.127 +{ 1.128 + var arr = new Array(--repeat_count); 1.129 + while (repeat_count != 0) 1.130 + arr[--repeat_count] = str; 1.131 + return str.concat.apply(str, arr); 1.132 +} 1.133 + 1.134 + 1.135 +function addThis() 1.136 +{ 1.137 + statusitems[UBound] = status; 1.138 + actualvalues[UBound] = actual; 1.139 + expectedvalues[UBound] = expect; 1.140 + UBound++; 1.141 +} 1.142 + 1.143 + 1.144 +function test() 1.145 +{ 1.146 + enterFunc('test'); 1.147 + printBugNumber(BUGNUMBER); 1.148 + printStatus(summary); 1.149 + 1.150 + for (var i=0; i<UBound; i++) 1.151 + { 1.152 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.153 + } 1.154 + 1.155 + exitFunc ('test'); 1.156 +}