js/src/tests/ecma_5/Array/length-set-object.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_5/Array/length-set-object.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     1.4 +/*
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/licenses/publicdomain/
     1.7 + * Contributor:
     1.8 + *   Jeff Walden <jwalden+code@mit.edu>
     1.9 + */
    1.10 +
    1.11 +//-----------------------------------------------------------------------------
    1.12 +var BUGNUMBER = 657298;
    1.13 +var summary = 'Various quirks of setting array length properties to objects';
    1.14 +
    1.15 +print(BUGNUMBER + ": " + summary);
    1.16 +
    1.17 +/**************
    1.18 + * BEGIN TEST *
    1.19 + **************/
    1.20 +
    1.21 +function invokeConversionTwice1()
    1.22 +{
    1.23 +  var count = 0;
    1.24 +  [].length = { valueOf: function() { count++; return 1; } };
    1.25 +  assertEq(count, 2);
    1.26 +}
    1.27 +invokeConversionTwice1();
    1.28 +
    1.29 +function invokeConversionTwice2()
    1.30 +{
    1.31 +  var count = 0;
    1.32 +  [].length = { toString: function() { count++; return 1; }, valueOf: null };
    1.33 +  assertEq(count, 2);
    1.34 +}
    1.35 +invokeConversionTwice2();
    1.36 +
    1.37 +function dontOverwriteError1()
    1.38 +{
    1.39 +  try
    1.40 +  {
    1.41 +    [].length = { valueOf: {}, toString: {} };
    1.42 +    throw new Error("didn't throw a TypeError");
    1.43 +  }
    1.44 +  catch (e)
    1.45 +  {
    1.46 +    assertEq(e instanceof TypeError, true,
    1.47 +             "expected a TypeError running out of conversion options, got " + e);
    1.48 +  }
    1.49 +}
    1.50 +dontOverwriteError1();
    1.51 +
    1.52 +function dontOverwriteError2()
    1.53 +{
    1.54 +  try
    1.55 +  {
    1.56 +    [].length = { valueOf: function() { throw "error"; } };
    1.57 +    throw new Error("didn't throw a TypeError");
    1.58 +  }
    1.59 +  catch (e)
    1.60 +  {
    1.61 +    assertEq(e, "error", "expected 'error' from failed conversion, got " + e);
    1.62 +  }
    1.63 +}
    1.64 +dontOverwriteError2();
    1.65 +
    1.66 +/******************************************************************************/
    1.67 +
    1.68 +if (typeof reportCompare === "function")
    1.69 +  reportCompare(true, true);
    1.70 +
    1.71 +print("All tests passed!");

mercurial