js/src/tests/ecma_5/Array/length-truncate-with-indexed.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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 = 858381;
    10 var summary =
    11   "Array length setting/truncating with non-dense, indexed elements";
    13 print(BUGNUMBER + ": " + summary);
    15 /**************
    16  * BEGIN TEST *
    17  **************/
    19 function testTruncateDenseAndSparse()
    20 {
    21   var arr;
    23   // initialized length 16, capacity same
    24   arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
    26   // plus a sparse element
    27   arr[987654321] = 987654321;
    29   // lop off the sparse element and half the dense elements, shrink capacity
    30   arr.length = 8;
    32   assertEq(987654321 in arr, false);
    33   assertEq(arr[987654321], undefined);
    34   assertEq(arr.length, 8);
    35 }
    36 testTruncateDenseAndSparse();
    38 function testTruncateSparse()
    39 {
    40   // initialized length 8, capacity same
    41   var arr = [0, 1, 2, 3, 4, 5, 6, 7];
    43   // plus a sparse element
    44   arr[987654321] = 987654321;
    46   // lop off the sparse element, leave initialized length/capacity unchanged
    47   arr.length = 8;
    49   assertEq(987654321 in arr, false);
    50   assertEq(arr[987654321], undefined);
    51   assertEq(arr.length, 8);
    52 }
    53 testTruncateSparse();
    55 function testTruncateDenseAndSparseShrinkCapacity()
    56 {
    57   // initialized length 11, capacity...somewhat larger, likely 16
    58   var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    60   // plus a sparse element
    61   arr[987654321] = 987654321;
    63   // lop off the sparse element, reduce initialized length, reduce capacity
    64   arr.length = 8;
    66   assertEq(987654321 in arr, false);
    67   assertEq(arr[987654321], undefined);
    68   assertEq(arr.length, 8);
    69 }
    70 testTruncateDenseAndSparseShrinkCapacity();
    72 function testTruncateSparseShrinkCapacity()
    73 {
    74   // initialized length 8, capacity same
    75   var arr = [0, 1, 2, 3, 4, 5, 6, 7];
    77   // capacity expands to accommodate, initialized length remains same (not equal
    78   // to capacity or length)
    79   arr[15] = 15;
    81   // now no elements past initialized length
    82   delete arr[15];
    84   // ...except a sparse element
    85   arr[987654321] = 987654321;
    87   // trims sparse element, doesn't change initialized length, shrinks capacity
    88   arr.length = 8;
    90   assertEq(987654321 in arr, false);
    91   assertEq(arr[987654321], undefined);
    92   assertEq(arr.length, 8);
    93 }
    94 testTruncateSparseShrinkCapacity();
    96 /******************************************************************************/
    98 if (typeof reportCompare === "function")
    99   reportCompare(true, true);
   101 print("Tests complete");

mercurial