| 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 gTestfile = 'regress-192465.js'; |
| 33 | var UBound = 0; |
| 34 | var BUGNUMBER = 192465; |
| 35 | var summary = 'Object.toSource() recursion should check stack overflow'; |
| 36 | var status = ''; |
| 37 | var statusitems = []; |
| 38 | var actual = ''; |
| 39 | var actualvalues = []; |
| 40 | var expect= ''; |
| 41 | var expectedvalues = []; |
| 42 | |
| 43 | |
| 44 | /* |
| 45 | * We're just testing that this script will compile and run. |
| 46 | * Set both |actual| and |expect| to a dummy value. |
| 47 | */ |
| 48 | status = inSection(1); |
| 49 | var N = 90; |
| 50 | try |
| 51 | { |
| 52 | make_deep_nest(N); |
| 53 | } |
| 54 | catch (e) |
| 55 | { |
| 56 | // An exception is OK, as the runtime can throw one in response to too deep |
| 57 | // recursion. We haven't crashed; good! Continue on to set the dummy values - |
| 58 | } |
| 59 | actual = 1; |
| 60 | expect = 1; |
| 61 | addThis(); |
| 62 | |
| 63 | |
| 64 | |
| 65 | //----------------------------------------------------------------------------- |
| 66 | test(); |
| 67 | //----------------------------------------------------------------------------- |
| 68 | |
| 69 | |
| 70 | /* |
| 71 | * EXAMPLE: |
| 72 | * |
| 73 | * If the global variable |N| is 2, then for |level| == 0, 1, 2, the return |
| 74 | * value of this function will be toSource() of these objects, respectively: |
| 75 | * |
| 76 | * {next:{next:END}} |
| 77 | * {next:{next:{next:{next:END}}}} |
| 78 | * {next:{next:{next:{next:{next:{next:END}}}}}} |
| 79 | * |
| 80 | */ |
| 81 | function make_deep_nest(level) |
| 82 | { |
| 83 | var head = {}; |
| 84 | var cursor = head; |
| 85 | |
| 86 | for (var i=0; i!=N; ++i) |
| 87 | { |
| 88 | cursor.next = {}; |
| 89 | cursor = cursor.next; |
| 90 | } |
| 91 | |
| 92 | cursor.toSource = function() |
| 93 | { |
| 94 | if (level != 0) |
| 95 | return make_deep_nest(level - 1); |
| 96 | return "END"; |
| 97 | } |
| 98 | |
| 99 | return head.toSource(); |
| 100 | } |
| 101 | |
| 102 | |
| 103 | function addThis() |
| 104 | { |
| 105 | statusitems[UBound] = status; |
| 106 | actualvalues[UBound] = actual; |
| 107 | expectedvalues[UBound] = expect; |
| 108 | UBound++; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | function test() |
| 113 | { |
| 114 | enterFunc('test'); |
| 115 | printBugNumber(BUGNUMBER); |
| 116 | printStatus(summary); |
| 117 | |
| 118 | for (var i=0; i<UBound; i++) |
| 119 | { |
| 120 | reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
| 121 | } |
| 122 | |
| 123 | exitFunc ('test'); |
| 124 | } |