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 | // Storing a typed value. |
michael@0 | 2 | function test1() { |
michael@0 | 3 | var a = []; |
michael@0 | 4 | for (var i=0; i<130; i++) { |
michael@0 | 5 | a[i] = i + 1; |
michael@0 | 6 | } |
michael@0 | 7 | return a; |
michael@0 | 8 | } |
michael@0 | 9 | |
michael@0 | 10 | var arr = test1(); |
michael@0 | 11 | assertEq(arr.length, 130); |
michael@0 | 12 | |
michael@0 | 13 | for (var i=0; i<130; i++) |
michael@0 | 14 | assertEq(arr[i], i + 1); |
michael@0 | 15 | |
michael@0 | 16 | // Storing a Value. |
michael@0 | 17 | function getValue(x) { |
michael@0 | 18 | var y = x & 0x3; |
michael@0 | 19 | if (y == 0) return null; |
michael@0 | 20 | if (y == 1) return true; |
michael@0 | 21 | if (y == 2) return 1.23; |
michael@0 | 22 | if (y == 3) return Math; |
michael@0 | 23 | assertEq(0, 1); |
michael@0 | 24 | } |
michael@0 | 25 | getValue(0); |
michael@0 | 26 | getValue(1); |
michael@0 | 27 | |
michael@0 | 28 | function test2() { |
michael@0 | 29 | var a = []; |
michael@0 | 30 | for (var i=0; i<130; i++) { |
michael@0 | 31 | a[i] = getValue(i); |
michael@0 | 32 | } |
michael@0 | 33 | return a; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | var arr = test2(); |
michael@0 | 37 | assertEq(arr.length, 130); |
michael@0 | 38 | |
michael@0 | 39 | for (var i=0; i<130; i++) |
michael@0 | 40 | assertEq(arr[i], getValue(i)); |
michael@0 | 41 | |
michael@0 | 42 | // Make sure the length-property is not updated if it's greater than |
michael@0 | 43 | // the (new) initialized length. |
michael@0 | 44 | function test3(arr, start, end) { |
michael@0 | 45 | for (var i=start; i<end; i++) { |
michael@0 | 46 | arr[i] = 10; |
michael@0 | 47 | } |
michael@0 | 48 | } |
michael@0 | 49 | var a = new Array(200); |
michael@0 | 50 | test3(a, 10, 130); |
michael@0 | 51 | assertEq(a.length, 200); |
michael@0 | 52 | |
michael@0 | 53 | for (var i=10; i<130; i++) |
michael@0 | 54 | assertEq(a[i], 10); |
michael@0 | 55 | |
michael@0 | 56 | test3(a, 130, 220); |
michael@0 | 57 | assertEq(a.length, 220); |
michael@0 | 58 | |
michael@0 | 59 | // Test constant index. |
michael@0 | 60 | function test4() { |
michael@0 | 61 | var a = [0, 1, 2, 3, 4, 5]; |
michael@0 | 62 | for (var i=0; i<150; i++) { |
michael@0 | 63 | a[6] = i; |
michael@0 | 64 | } |
michael@0 | 65 | return a; |
michael@0 | 66 | } |
michael@0 | 67 | var arr = test4(); |
michael@0 | 68 | assertEq(arr[6], 149); |