Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 4 | * Contributor: |
michael@0 | 5 | * Jeff Walden <jwalden+code@mit.edu> |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | //----------------------------------------------------------------------------- |
michael@0 | 9 | var BUGNUMBER = 858381; |
michael@0 | 10 | var summary = |
michael@0 | 11 | "Array length setting/truncating with non-dense, indexed elements"; |
michael@0 | 12 | |
michael@0 | 13 | print(BUGNUMBER + ": " + summary); |
michael@0 | 14 | |
michael@0 | 15 | /************** |
michael@0 | 16 | * BEGIN TEST * |
michael@0 | 17 | **************/ |
michael@0 | 18 | |
michael@0 | 19 | function testTruncateDenseAndSparse() |
michael@0 | 20 | { |
michael@0 | 21 | var arr; |
michael@0 | 22 | |
michael@0 | 23 | // initialized length 16, capacity same |
michael@0 | 24 | arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; |
michael@0 | 25 | |
michael@0 | 26 | // plus a sparse element |
michael@0 | 27 | arr[987654321] = 987654321; |
michael@0 | 28 | |
michael@0 | 29 | // lop off the sparse element and half the dense elements, shrink capacity |
michael@0 | 30 | arr.length = 8; |
michael@0 | 31 | |
michael@0 | 32 | assertEq(987654321 in arr, false); |
michael@0 | 33 | assertEq(arr[987654321], undefined); |
michael@0 | 34 | assertEq(arr.length, 8); |
michael@0 | 35 | } |
michael@0 | 36 | testTruncateDenseAndSparse(); |
michael@0 | 37 | |
michael@0 | 38 | function testTruncateSparse() |
michael@0 | 39 | { |
michael@0 | 40 | // initialized length 8, capacity same |
michael@0 | 41 | var arr = [0, 1, 2, 3, 4, 5, 6, 7]; |
michael@0 | 42 | |
michael@0 | 43 | // plus a sparse element |
michael@0 | 44 | arr[987654321] = 987654321; |
michael@0 | 45 | |
michael@0 | 46 | // lop off the sparse element, leave initialized length/capacity unchanged |
michael@0 | 47 | arr.length = 8; |
michael@0 | 48 | |
michael@0 | 49 | assertEq(987654321 in arr, false); |
michael@0 | 50 | assertEq(arr[987654321], undefined); |
michael@0 | 51 | assertEq(arr.length, 8); |
michael@0 | 52 | } |
michael@0 | 53 | testTruncateSparse(); |
michael@0 | 54 | |
michael@0 | 55 | function testTruncateDenseAndSparseShrinkCapacity() |
michael@0 | 56 | { |
michael@0 | 57 | // initialized length 11, capacity...somewhat larger, likely 16 |
michael@0 | 58 | var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
michael@0 | 59 | |
michael@0 | 60 | // plus a sparse element |
michael@0 | 61 | arr[987654321] = 987654321; |
michael@0 | 62 | |
michael@0 | 63 | // lop off the sparse element, reduce initialized length, reduce capacity |
michael@0 | 64 | arr.length = 8; |
michael@0 | 65 | |
michael@0 | 66 | assertEq(987654321 in arr, false); |
michael@0 | 67 | assertEq(arr[987654321], undefined); |
michael@0 | 68 | assertEq(arr.length, 8); |
michael@0 | 69 | } |
michael@0 | 70 | testTruncateDenseAndSparseShrinkCapacity(); |
michael@0 | 71 | |
michael@0 | 72 | function testTruncateSparseShrinkCapacity() |
michael@0 | 73 | { |
michael@0 | 74 | // initialized length 8, capacity same |
michael@0 | 75 | var arr = [0, 1, 2, 3, 4, 5, 6, 7]; |
michael@0 | 76 | |
michael@0 | 77 | // capacity expands to accommodate, initialized length remains same (not equal |
michael@0 | 78 | // to capacity or length) |
michael@0 | 79 | arr[15] = 15; |
michael@0 | 80 | |
michael@0 | 81 | // now no elements past initialized length |
michael@0 | 82 | delete arr[15]; |
michael@0 | 83 | |
michael@0 | 84 | // ...except a sparse element |
michael@0 | 85 | arr[987654321] = 987654321; |
michael@0 | 86 | |
michael@0 | 87 | // trims sparse element, doesn't change initialized length, shrinks capacity |
michael@0 | 88 | arr.length = 8; |
michael@0 | 89 | |
michael@0 | 90 | assertEq(987654321 in arr, false); |
michael@0 | 91 | assertEq(arr[987654321], undefined); |
michael@0 | 92 | assertEq(arr.length, 8); |
michael@0 | 93 | } |
michael@0 | 94 | testTruncateSparseShrinkCapacity(); |
michael@0 | 95 | |
michael@0 | 96 | /******************************************************************************/ |
michael@0 | 97 | |
michael@0 | 98 | if (typeof reportCompare === "function") |
michael@0 | 99 | reportCompare(true, true); |
michael@0 | 100 | |
michael@0 | 101 | print("Tests complete"); |