js/src/tests/ecma_5/Array/toString-01.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/toString-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,52 @@
     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 = 562446;
    1.13 +var summary = 'ES5: Array.prototype.toString';
    1.14 +
    1.15 +print(BUGNUMBER + ": " + summary);
    1.16 +
    1.17 +/**************
    1.18 + * BEGIN TEST *
    1.19 + **************/
    1.20 +
    1.21 +var o;
    1.22 +
    1.23 +o = { join: function() { assertEq(arguments.length, 0); return "ohai"; } };
    1.24 +assertEq(Array.prototype.toString.call(o), "ohai");
    1.25 +
    1.26 +o = {};
    1.27 +assertEq(Array.prototype.toString.call(o), "[object Object]");
    1.28 +
    1.29 +Array.prototype.join = function() { return "kthxbai"; };
    1.30 +assertEq(Array.prototype.toString.call([]), "kthxbai");
    1.31 +
    1.32 +o = { join: 17 };
    1.33 +assertEq(Array.prototype.toString.call(o), "[object Object]");
    1.34 +
    1.35 +o = { get join() { throw 42; } };
    1.36 +try
    1.37 +{
    1.38 +  var str = Array.prototype.toString.call(o);
    1.39 +  assertEq(true, false,
    1.40 +           "expected an exception calling [].toString on an object with a " +
    1.41 +           "join getter that throws, got " + str + " instead");
    1.42 +}
    1.43 +catch (e)
    1.44 +{
    1.45 +  assertEq(e, 42,
    1.46 +           "expected thrown e === 42 when calling [].toString on an object " +
    1.47 +           "with a join getter that throws, got " + e);
    1.48 +}
    1.49 +
    1.50 +/******************************************************************************/
    1.51 +
    1.52 +if (typeof reportCompare === "function")
    1.53 +  reportCompare(true, true);
    1.54 +
    1.55 +print("All tests passed!");

mercurial