js/src/tests/ecma_5/Array/toString-01.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/licenses/publicdomain/
     4  * Contributor:
     5  *   Jeff Walden <jwalden+code@mit.edu>
     6  */
     8 //-----------------------------------------------------------------------------
     9 var BUGNUMBER = 562446;
    10 var summary = 'ES5: Array.prototype.toString';
    12 print(BUGNUMBER + ": " + summary);
    14 /**************
    15  * BEGIN TEST *
    16  **************/
    18 var o;
    20 o = { join: function() { assertEq(arguments.length, 0); return "ohai"; } };
    21 assertEq(Array.prototype.toString.call(o), "ohai");
    23 o = {};
    24 assertEq(Array.prototype.toString.call(o), "[object Object]");
    26 Array.prototype.join = function() { return "kthxbai"; };
    27 assertEq(Array.prototype.toString.call([]), "kthxbai");
    29 o = { join: 17 };
    30 assertEq(Array.prototype.toString.call(o), "[object Object]");
    32 o = { get join() { throw 42; } };
    33 try
    34 {
    35   var str = Array.prototype.toString.call(o);
    36   assertEq(true, false,
    37            "expected an exception calling [].toString on an object with a " +
    38            "join getter that throws, got " + str + " instead");
    39 }
    40 catch (e)
    41 {
    42   assertEq(e, 42,
    43            "expected thrown e === 42 when calling [].toString on an object " +
    44            "with a join getter that throws, got " + e);
    45 }
    47 /******************************************************************************/
    49 if (typeof reportCompare === "function")
    50   reportCompare(true, true);
    52 print("All tests passed!");

mercurial