js/src/tests/js1_5/extensions/regress-192465.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:96c7a31f7c9e
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/. */
5
6 /*
7 *
8 * Date: 10 February 2003
9 * SUMMARY: Object.toSource() recursion should check stack overflow
10 *
11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=192465
12 *
13 * MODIFIED: 27 February 2003
14 *
15 * We are adding an early return to this testcase, since it is causing
16 * big problems on Linux RedHat8! For a discussion of this issue, see
17 * http://bugzilla.mozilla.org/show_bug.cgi?id=174341#c24 and following.
18 *
19 *
20 * MODIFIED: 20 March 2003
21 *
22 * Removed the early return and changed |N| below from 1000 to 90.
23 * Note |make_deep_nest(N)| returns an object graph of length N(N+1).
24 * So the graph has now been reduced from 1,001,000 to 8190.
25 *
26 * With this reduction, the bug still manifests on my WinNT and Linux
27 * boxes (crash due to stack overflow). So the testcase is again of use
28 * on those boxes. At the same time, Linux RedHat8 boxes can now run
29 * the test in a reasonable amount of time.
30 */
31 //-----------------------------------------------------------------------------
32 var UBound = 0;
33 var BUGNUMBER = 192465;
34 var summary = 'Object.toSource() recursion should check stack overflow';
35 var status = '';
36 var statusitems = [];
37 var actual = '';
38 var actualvalues = [];
39 var expect= '';
40 var expectedvalues = [];
41
42
43 /*
44 * We're just testing that this script will compile and run.
45 * Set both |actual| and |expect| to a dummy value.
46 */
47 status = inSection(1);
48 var N = 90;
49 try
50 {
51 make_deep_nest(N);
52 }
53 catch (e)
54 {
55 // An exception is OK, as the runtime can throw one in response to too deep
56 // recursion. We haven't crashed; good! Continue on to set the dummy values -
57 }
58 actual = 1;
59 expect = 1;
60 addThis();
61
62
63
64 //-----------------------------------------------------------------------------
65 test();
66 //-----------------------------------------------------------------------------
67
68
69 /*
70 * EXAMPLE:
71 *
72 * If the global variable |N| is 2, then for |level| == 0, 1, 2, the return
73 * value of this function will be toSource() of these objects, respectively:
74 *
75 * {next:{next:END}}
76 * {next:{next:{next:{next:END}}}}
77 * {next:{next:{next:{next:{next:{next:END}}}}}}
78 *
79 */
80 function make_deep_nest(level)
81 {
82 var head = {};
83 var cursor = head;
84
85 for (var i=0; i!=N; ++i)
86 {
87 cursor.next = {};
88 cursor = cursor.next;
89 }
90
91 cursor.toSource = function()
92 {
93 if (level != 0)
94 return make_deep_nest(level - 1);
95 return "END";
96 }
97
98 return head.toSource();
99 }
100
101
102 function addThis()
103 {
104 statusitems[UBound] = status;
105 actualvalues[UBound] = actual;
106 expectedvalues[UBound] = expect;
107 UBound++;
108 }
109
110
111 function test()
112 {
113 enterFunc('test');
114 printBugNumber(BUGNUMBER);
115 printStatus(summary);
116
117 for (var i=0; i<UBound; i++)
118 {
119 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
120 }
121
122 exitFunc ('test');
123 }

mercurial