tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

regress-192465.js (3029B)


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