js/src/tests/js1_5/Array/regress-465980-02.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_5/Array/regress-465980-02.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,170 @@
     1.4 +// |reftest| skip -- slow
     1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +//-----------------------------------------------------------------------------
    1.11 +var BUGNUMBER = 465980;
    1.12 +var summary = 'Do not crash @ InitArrayElements';
    1.13 +var actual = '';
    1.14 +var expect = '';
    1.15 +
    1.16 +
    1.17 +//-----------------------------------------------------------------------------
    1.18 +test();
    1.19 +//-----------------------------------------------------------------------------
    1.20 +
    1.21 +function test()
    1.22 +{
    1.23 +  enterFunc ('test');
    1.24 +  printBugNumber(BUGNUMBER);
    1.25 +  printStatus (summary);
    1.26 +
    1.27 +  function describe(name, startLength, pushArgs, expectThrow, expectLength)
    1.28 +  {
    1.29 +    return name + "(" + startLength + ", " +
    1.30 +      "[" + pushArgs.join(", ") + "], " +
    1.31 +      expectThrow + ", " +
    1.32 +      expectLength + ")";
    1.33 +  }
    1.34 +
    1.35 +  var push = Array.prototype.push;
    1.36 +  var unshift = Array.prototype.unshift;
    1.37 +
    1.38 +  function testArrayPush(startLength, pushArgs, expectThrow, expectLength)
    1.39 +  {
    1.40 +    print("running testArrayPush(" +
    1.41 +          startLength + ", " +
    1.42 +          "[" + pushArgs.join(", ") + "], " +
    1.43 +          expectThrow + ", " +
    1.44 +          expectLength + ")...");
    1.45 +    var a = new Array(startLength);
    1.46 +    try
    1.47 +    {
    1.48 +      push.apply(a, pushArgs);
    1.49 +      if (expectThrow)
    1.50 +      {
    1.51 +        throw "expected to throw for " +
    1.52 +          describe("testArrayPush", startLength, pushArgs, expectThrow,
    1.53 +                   expectLength);
    1.54 +      }
    1.55 +    }
    1.56 +    catch (e)
    1.57 +    {
    1.58 +      if (!(e instanceof RangeError))
    1.59 +      {
    1.60 +        throw "unexpected exception type thrown: " + e + " for " +
    1.61 +          describe("testArrayPush", startLength, pushArgs, expectThrow,
    1.62 +                   expectLength);
    1.63 +      }
    1.64 +      if (!expectThrow)
    1.65 +      {
    1.66 +        throw "unexpected exception " + e + " for " +
    1.67 +          describe("testArrayPush", startLength, pushArgs, expectThrow,
    1.68 +                   expectLength);
    1.69 +      }
    1.70 +    }
    1.71 +
    1.72 +    if (a.length !== expectLength)
    1.73 +    {
    1.74 +      throw "unexpected modified-array length for " +
    1.75 +        describe("testArrayPush", startLength, pushArgs, expectThrow,
    1.76 +                 expectLength);
    1.77 +    }
    1.78 +
    1.79 +    for (var i = 0, sz = pushArgs.length; i < sz; i++)
    1.80 +    {
    1.81 +      var index = i + startLength;
    1.82 +      if (a[index] !== pushArgs[i])
    1.83 +      {
    1.84 +        throw "unexpected value " + a[index] +
    1.85 +          " at index " + index + " (" + i + ") during " +
    1.86 +          describe("testArrayPush", startLength, pushArgs, expectThrow,
    1.87 +                   expectLength) + ", expected " + pushArgs[i];
    1.88 +      }
    1.89 +    }
    1.90 +  }
    1.91 +
    1.92 +  function testArrayUnshift(startLength, unshiftArgs, expectThrow, expectLength)
    1.93 +  {
    1.94 +    print("running testArrayUnshift(" +
    1.95 +          startLength + ", " +
    1.96 +          "[" + unshiftArgs.join(", ") + "], " +
    1.97 +          expectThrow + ", " +
    1.98 +          expectLength + ")...");
    1.99 +    var a = new Array(startLength);
   1.100 +    try
   1.101 +    {
   1.102 +      unshift.apply(a, unshiftArgs);
   1.103 +      if (expectThrow)
   1.104 +      {
   1.105 +        throw "expected to throw for " +
   1.106 +          describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,
   1.107 +                   expectLength);
   1.108 +      }
   1.109 +    }
   1.110 +    catch (e)
   1.111 +    {
   1.112 +      if (!(e instanceof RangeError))
   1.113 +      {
   1.114 +        throw "unexpected exception type thrown: " + e + " for " +
   1.115 +          describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,
   1.116 +                   expectLength);
   1.117 +      }
   1.118 +      if (!expectThrow)
   1.119 +      {
   1.120 +        throw "unexpected exception " + e + " for " +
   1.121 +          describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,
   1.122 +                   expectLength);
   1.123 +      }
   1.124 +    }
   1.125 +
   1.126 +    if (a.length !== expectLength)
   1.127 +    {
   1.128 +      throw "unexpected modified-array length for " +
   1.129 +        describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,
   1.130 +                 expectLength);
   1.131 +    }
   1.132 +
   1.133 +    for (var i = 0, sz = unshiftArgs.length; i < sz; i++)
   1.134 +    {
   1.135 +      if (a[i] !== unshiftArgs[i])
   1.136 +      {
   1.137 +        throw "unexpected value at index " + i + " during " +
   1.138 +          describe("testArrayUnshift", startLength, unshiftArgs, expectThrow,
   1.139 +                   expectLength);
   1.140 +      }
   1.141 +    }
   1.142 +  }
   1.143 +
   1.144 +  var failed = true;
   1.145 +
   1.146 +  try
   1.147 +  {
   1.148 +    var foo = "foo", bar = "bar", baz = "baz";
   1.149 +
   1.150 +    testArrayPush(4294967294, [foo], false, 4294967295);
   1.151 +    testArrayPush(4294967294, [foo, bar], true, 4294967295);
   1.152 +    testArrayPush(4294967294, [foo, bar, baz], true, 4294967295);
   1.153 +    testArrayPush(4294967295, [foo], true, 4294967295);
   1.154 +    testArrayPush(4294967295, [foo, bar], true, 4294967295);
   1.155 +    testArrayPush(4294967295, [foo, bar, baz], true, 4294967295);
   1.156 +
   1.157 +    testArrayUnshift(4294967294, [foo], false, 4294967295);
   1.158 +    testArrayUnshift(4294967294, [foo, bar], true, 4294967294);
   1.159 +    testArrayUnshift(4294967294, [foo, bar, baz], true, 4294967294);
   1.160 +    testArrayUnshift(4294967295, [foo], true, 4294967295);
   1.161 +    testArrayUnshift(4294967295, [foo, bar], true, 4294967295);
   1.162 +    testArrayUnshift(4294967295, [foo, bar, baz], true, 4294967295);
   1.163 +
   1.164 +  }
   1.165 +  catch (e)
   1.166 +  {
   1.167 +    actual = e + '';
   1.168 +  }
   1.169 +
   1.170 +  reportCompare(expect, actual, summary);
   1.171 +
   1.172 +  exitFunc ('test');
   1.173 +}

mercurial