Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 *
8 * Date: 08 February 2003
9 * SUMMARY: Parser recursion should check stack overflow
10 *
11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=192414
12 *
13 */
14 //-----------------------------------------------------------------------------
15 var UBound = 0;
16 var BUGNUMBER = 192414;
17 var summary = 'Parser recursion should check stack overflow';
18 var status = '';
19 var statusitems = [];
20 var actual = '';
21 var actualvalues = [];
22 var expect= '';
23 var expectedvalues = [];
25 /*
26 * We will form an eval string to set the result-variable |actual|.
27 * To get a feel for this, suppose N were 3. Then the eval string is
28 * 'actual = (1&(1&(1&1)));' The expected value after eval() is 1.
29 */
30 status = inSection(1);
31 var N = 10000;
32 var left = repeat_str('(1&', N);
33 var right = repeat_str(')', N);
34 var str = 'actual = '.concat(left, '1', right, ';');
35 try
36 {
37 eval(str);
38 }
39 catch (e)
40 {
41 /*
42 * An exception during this eval is OK, as the runtime can throw one
43 * in response to too deep recursion. We haven't crashed; good!
44 */
45 actual = 1;
46 }
47 expect = 1;
48 addThis();
52 //-----------------------------------------------------------------------------
53 test();
54 //-----------------------------------------------------------------------------
58 function repeat_str(str, repeat_count)
59 {
60 var arr = new Array(--repeat_count);
61 while (repeat_count != 0)
62 arr[--repeat_count] = str;
63 return str.concat.apply(str, arr);
64 }
67 function addThis()
68 {
69 statusitems[UBound] = status;
70 actualvalues[UBound] = actual;
71 expectedvalues[UBound] = expect;
72 UBound++;
73 }
76 function test()
77 {
78 enterFunc('test');
79 printBugNumber(BUGNUMBER);
80 printStatus(summary);
82 for (var i=0; i<UBound; i++)
83 {
84 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
85 }
87 exitFunc ('test');
88 }