js/src/tests/ecma_5/Array/length-set-object.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 = 657298;
    10 var summary = 'Various quirks of setting array length properties to objects';
    12 print(BUGNUMBER + ": " + summary);
    14 /**************
    15  * BEGIN TEST *
    16  **************/
    18 function invokeConversionTwice1()
    19 {
    20   var count = 0;
    21   [].length = { valueOf: function() { count++; return 1; } };
    22   assertEq(count, 2);
    23 }
    24 invokeConversionTwice1();
    26 function invokeConversionTwice2()
    27 {
    28   var count = 0;
    29   [].length = { toString: function() { count++; return 1; }, valueOf: null };
    30   assertEq(count, 2);
    31 }
    32 invokeConversionTwice2();
    34 function dontOverwriteError1()
    35 {
    36   try
    37   {
    38     [].length = { valueOf: {}, toString: {} };
    39     throw new Error("didn't throw a TypeError");
    40   }
    41   catch (e)
    42   {
    43     assertEq(e instanceof TypeError, true,
    44              "expected a TypeError running out of conversion options, got " + e);
    45   }
    46 }
    47 dontOverwriteError1();
    49 function dontOverwriteError2()
    50 {
    51   try
    52   {
    53     [].length = { valueOf: function() { throw "error"; } };
    54     throw new Error("didn't throw a TypeError");
    55   }
    56   catch (e)
    57   {
    58     assertEq(e, "error", "expected 'error' from failed conversion, got " + e);
    59   }
    60 }
    61 dontOverwriteError2();
    63 /******************************************************************************/
    65 if (typeof reportCompare === "function")
    66   reportCompare(true, true);
    68 print("All tests passed!");

mercurial