js/src/jit-test/tests/ion/bug851792.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.

michael@0 1 // Based on tests/ion/typed-arrays-1.js, but with string indexes
michael@0 2 function testInt8() {
michael@0 3 var arr1 = new Int8Array(50);
michael@0 4 var arr2 = new Uint8Array(50);
michael@0 5 var arr3 = new Uint8ClampedArray(50);
michael@0 6
michael@0 7 for (var i=0; i<arr1.length; i++) {
michael@0 8 arr1[i] = arr2[i] = arr3[i] = i * 8;
michael@0 9 }
michael@0 10 var res = 0;
michael@0 11 for (var i=0; i<arr1.length; i++) {
michael@0 12 res += arr1[i+""] + arr2[i+""] + arr3[i+""] + arr2["10".concat("")];
michael@0 13 }
michael@0 14 assertEq(res, 18334);
michael@0 15 }
michael@0 16 testInt8();
michael@0 17
michael@0 18 function testInt16() {
michael@0 19 var arr1 = new Int16Array(70);
michael@0 20 var arr2 = new Uint16Array(70);
michael@0 21
michael@0 22 for (var i=0; i<arr1.length; i++) {
michael@0 23 arr1[i] = arr2[i] = i * 1000;
michael@0 24 }
michael@0 25 var res = 0;
michael@0 26 for (var i=0; i<arr1.length; i++) {
michael@0 27 res += arr1[i+""] + arr2[i+""] + arr2["1".concat("")] + arr1["3".concat("")];
michael@0 28 }
michael@0 29 assertEq(res, 2423024);
michael@0 30 }
michael@0 31 testInt16();
michael@0 32
michael@0 33 function testInt32() {
michael@0 34 var arr = new Int32Array(60);
michael@0 35 arr[0] = -50;
michael@0 36 for (var i=1; i<arr.length; i++) {
michael@0 37 arr[i] = arr[(i-1)+""] + arr["0".concat("")];
michael@0 38 ++arr[0];
michael@0 39 }
michael@0 40 assertEq(arr[(arr.length-1)+""], -1289);
michael@0 41 }
michael@0 42 testInt32();
michael@0 43
michael@0 44 function testUint32() {
michael@0 45 function sum(arr) {
michael@0 46 var res = 0;
michael@0 47 for (var i=0; i<arr.length; i++) {
michael@0 48 res += arr[i+""];
michael@0 49 }
michael@0 50 return res;
michael@0 51 }
michael@0 52 var arr = new Uint32Array(100);
michael@0 53 for (var i=0; i<arr.length; i++) {
michael@0 54 arr[i] = i;
michael@0 55 }
michael@0 56
michael@0 57 // Compile sum() to read int32 values.
michael@0 58 assertEq(sum(arr), 4950);
michael@0 59
michael@0 60 // Add a large uint32 so that the sum no longer fits in an
michael@0 61 // int32. sum() should be recompiled to return a double.
michael@0 62 arr[50] = 0xffffeeee;
michael@0 63 assertEq(sum(arr), 4294967826);
michael@0 64 }
michael@0 65 testUint32();
michael@0 66
michael@0 67 function testFloat() {
michael@0 68 var arr1 = new Float32Array(75);
michael@0 69 var arr2 = new Float64Array(75);
michael@0 70 arr1[0] = arr2[0] = Math.PI * 1234567.8;
michael@0 71
michael@0 72 for (var i=1; i<75; i++) {
michael@0 73 arr1[i] = arr1[(i-1)+""] + arr1[0];
michael@0 74 arr2[i] = arr2[(i-1)+""] + arr2[0];
michael@0 75 }
michael@0 76 assertEq(arr1["74".concat("")] > 290888255, true);
michael@0 77 assertEq(arr1["74".concat("")] < 290888257, true);
michael@0 78
michael@0 79 assertEq(arr2["74".concat("")] > 290888184, true);
michael@0 80 assertEq(arr2["74".concat("")] < 290888185, true);
michael@0 81 }
michael@0 82 testFloat();
michael@0 83
michael@0 84 function testCanonicalNaN() {
michael@0 85 // NaN values have to be canonicalized. Otherwise, malicious scripts could
michael@0 86 // construct arbitrary Value's (due to our NaN boxing Value representation).
michael@0 87 var buf = new ArrayBuffer(16);
michael@0 88 var uint32 = new Uint32Array(buf);
michael@0 89 var f64 = new Float64Array(buf);
michael@0 90 var f32 = new Float32Array(buf);
michael@0 91
michael@0 92 // Evil: write a JSVAL_TYPE_OBJECT type tag...
michael@0 93 uint32[0] = 0xffffff87;
michael@0 94 uint32[1] = 0xffffff87;
michael@0 95
michael@0 96 // Make sure this value is interpreted as a double.
michael@0 97 for (var i=0; i<3; i++) {
michael@0 98 assertEq(isNaN(f64["0".concat("")]), true);
michael@0 99 assertEq(isNaN(f32["0".concat("")]), true);
michael@0 100 }
michael@0 101 }
michael@0 102 testCanonicalNaN();
michael@0 103
michael@0 104 function testOutOfBounds() {
michael@0 105 var buf = new ArrayBuffer(16);
michael@0 106 var uint32 = new Uint32Array(buf);
michael@0 107
michael@0 108 uint32[0] = 0;
michael@0 109 uint32[1] = 1;
michael@0 110
michael@0 111 for (var i=0; i<3; i++) {
michael@0 112 assertEq(uint32["0".concat("")], 0);
michael@0 113 assertEq(uint32["1".concat("")], 1);
michael@0 114 assertEq(uint32["2".concat("")], 0);
michael@0 115 assertEq(uint32["17".concat("")], undefined);
michael@0 116 }
michael@0 117 }
michael@0 118 testOutOfBounds();
michael@0 119
michael@0 120 function testStrangeIndexes() {
michael@0 121 var buf = new ArrayBuffer(16);
michael@0 122 var uint32 = new Uint32Array(buf);
michael@0 123
michael@0 124 uint32[0] = 0;
michael@0 125 uint32[1] = 1;
michael@0 126
michael@0 127 indexes = ["0", "1", "2", "3", "17", "3.5", "NaN", "undefined", "null"];
michael@0 128 solutions = [0, 1, 0, 0, undefined, undefined, undefined, undefined, undefined];
michael@0 129
michael@0 130 for (var i=0; i<indexes.length; i++) {
michael@0 131 assertEq(uint32[indexes[i]], solutions[i]);
michael@0 132 }
michael@0 133 }
michael@0 134 testStrangeIndexes();
michael@0 135

mercurial