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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/extensions/regress-192465.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,123 @@
     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:    10 February 2003
    1.12 + * SUMMARY: Object.toSource() recursion should check stack overflow
    1.13 + *
    1.14 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=192465
    1.15 + *
    1.16 + * MODIFIED: 27 February 2003
    1.17 + *
    1.18 + * We are adding an early return to this testcase, since it is causing
    1.19 + * big problems on Linux RedHat8! For a discussion of this issue, see
    1.20 + * http://bugzilla.mozilla.org/show_bug.cgi?id=174341#c24 and following.
    1.21 + *
    1.22 + *
    1.23 + * MODIFIED: 20 March 2003
    1.24 + *
    1.25 + * Removed the early return and changed |N| below from 1000 to 90.
    1.26 + * Note |make_deep_nest(N)| returns an object graph of length N(N+1).
    1.27 + * So the graph has now been reduced from 1,001,000 to 8190.
    1.28 + *
    1.29 + * With this reduction, the bug still manifests on my WinNT and Linux
    1.30 + * boxes (crash due to stack overflow). So the testcase is again of use
    1.31 + * on those boxes. At the same time, Linux RedHat8 boxes can now run
    1.32 + * the test in a reasonable amount of time.
    1.33 + */
    1.34 +//-----------------------------------------------------------------------------
    1.35 +var UBound = 0;
    1.36 +var BUGNUMBER = 192465;
    1.37 +var summary = 'Object.toSource() recursion should check stack overflow';
    1.38 +var status = '';
    1.39 +var statusitems = [];
    1.40 +var actual = '';
    1.41 +var actualvalues = [];
    1.42 +var expect= '';
    1.43 +var expectedvalues = [];
    1.44 +
    1.45 +
    1.46 +/*
    1.47 + * We're just testing that this script will compile and run.
    1.48 + * Set both |actual| and |expect| to a dummy value.
    1.49 + */
    1.50 +status = inSection(1);
    1.51 +var N = 90;
    1.52 +try
    1.53 +{
    1.54 +  make_deep_nest(N);
    1.55 +}
    1.56 +catch (e)
    1.57 +{
    1.58 +  // An exception is OK, as the runtime can throw one in response to too deep
    1.59 +  // recursion. We haven't crashed; good! Continue on to set the dummy values -
    1.60 +}
    1.61 +actual = 1;
    1.62 +expect = 1;
    1.63 +addThis();
    1.64 +
    1.65 +
    1.66 +
    1.67 +//-----------------------------------------------------------------------------
    1.68 +test();
    1.69 +//-----------------------------------------------------------------------------
    1.70 +
    1.71 +
    1.72 +/*
    1.73 + * EXAMPLE:
    1.74 + *
    1.75 + * If the global variable |N| is 2, then for |level| == 0, 1, 2, the return
    1.76 + * value of this function will be toSource() of these objects, respectively:
    1.77 + *
    1.78 + * {next:{next:END}}
    1.79 + * {next:{next:{next:{next:END}}}}
    1.80 + * {next:{next:{next:{next:{next:{next:END}}}}}}
    1.81 + *
    1.82 + */
    1.83 +function make_deep_nest(level)
    1.84 +{
    1.85 +  var head = {};
    1.86 +  var cursor = head;
    1.87 +
    1.88 +  for (var i=0; i!=N; ++i)
    1.89 +  {
    1.90 +    cursor.next = {};
    1.91 +    cursor = cursor.next;
    1.92 +  }
    1.93 +
    1.94 +  cursor.toSource = function()
    1.95 +    {
    1.96 +      if (level != 0)
    1.97 +	return make_deep_nest(level - 1);
    1.98 +      return "END";
    1.99 +    }
   1.100 +
   1.101 +  return head.toSource();
   1.102 +}
   1.103 +
   1.104 +
   1.105 +function addThis()
   1.106 +{
   1.107 +  statusitems[UBound] = status;
   1.108 +  actualvalues[UBound] = actual;
   1.109 +  expectedvalues[UBound] = expect;
   1.110 +  UBound++;
   1.111 +}
   1.112 +
   1.113 +
   1.114 +function test()
   1.115 +{
   1.116 +  enterFunc('test');
   1.117 +  printBugNumber(BUGNUMBER);
   1.118 +  printStatus(summary);
   1.119 +
   1.120 +  for (var i=0; i<UBound; i++)
   1.121 +  {
   1.122 +    reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
   1.123 +  }
   1.124 +
   1.125 +  exitFunc ('test');
   1.126 +}

mercurial