js/src/jit-test/tests/ion/setelem.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 function testInt32() {
michael@0 2 function f(arr, i) {
michael@0 3 arr[0] = 1;
michael@0 4 arr[1] = arr[0] + 1;
michael@0 5 arr[2] = arr[1] + arr[0];
michael@0 6 var x = arr[2]; // 3
michael@0 7 arr[x] = arr[x-1] + 1;
michael@0 8 arr[x+1] = arr[x] + i;
michael@0 9 return arr[4];
michael@0 10 }
michael@0 11 var a = [1, 2, 3, 4, 5, 6, 7, 8];
michael@0 12 for (var i=0; i<70; i++) {
michael@0 13 assertEq(f(a, i), i + 4);
michael@0 14 }
michael@0 15 }
michael@0 16 testInt32();
michael@0 17
michael@0 18 function testDouble() {
michael@0 19 function f(arr, d) {
michael@0 20 arr[0] = d;
michael@0 21 for (var i=1; i<8; i++) {
michael@0 22 arr[i] = arr[i-1] + d;
michael@0 23 }
michael@0 24 return arr[7];
michael@0 25 }
michael@0 26 var a = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
michael@0 27 for (var i=0; i<50; i++) {
michael@0 28 assertEq(f(a, Math.PI + i)|0, ((Math.PI + i) * 8)|0);
michael@0 29 }
michael@0 30 }
michael@0 31 testDouble();
michael@0 32
michael@0 33 function testOutOfBounds() {
michael@0 34 function f(arr, i, v) {
michael@0 35 arr[i] = v;
michael@0 36 }
michael@0 37 var a = [1, 2];
michael@0 38 for (var i=0; i<90; i++) {
michael@0 39 f(a, 1, i);
michael@0 40 }
michael@0 41 assertEq(a[1], 89);
michael@0 42
michael@0 43 f(a, 2, 40);
michael@0 44 f(a, 100, 50);
michael@0 45 f(a, -1, 3);
michael@0 46
michael@0 47 assertEq(a[2], 40);
michael@0 48 assertEq(a[100], 50);
michael@0 49 assertEq(a[-1], 3);
michael@0 50 }
michael@0 51 testOutOfBounds();
michael@0 52
michael@0 53 function testClassGuard() {
michael@0 54 function f(arr, v) {
michael@0 55 arr[1] = v;
michael@0 56 }
michael@0 57 var a = [1, 2, 3, 4];
michael@0 58 for (var i=0; i<90; i++) {
michael@0 59 f(a, i);
michael@0 60 }
michael@0 61 assertEq(a[1], 89);
michael@0 62
michael@0 63 var b = {};
michael@0 64 f(b, 100);
michael@0 65 assertEq(b[1], 100);
michael@0 66 }
michael@0 67 testClassGuard();
michael@0 68
michael@0 69 function testMultipleTypes() {
michael@0 70 function f(arr, v) {
michael@0 71 arr[1] = v;
michael@0 72 }
michael@0 73 var a = [1, 2, 3, 4];
michael@0 74 var b = [1.1, -233.2, 3.3];
michael@0 75
michael@0 76 for (var i=0; i<90; i++) {
michael@0 77 f(a, i);
michael@0 78 }
michael@0 79 assertEq(a[1], 89);
michael@0 80 f(b, 20);
michael@0 81 assertEq(b[1], 20);
michael@0 82 }
michael@0 83 testMultipleTypes();
michael@0 84
michael@0 85 function testNull() {
michael@0 86 function f(arr) {
michael@0 87 arr[0] = null;
michael@0 88 }
michael@0 89
michael@0 90 var arr = [undefined];
michael@0 91 for (var i=0; i<100; i++) {
michael@0 92 f(arr);
michael@0 93 }
michael@0 94 assertEq(arr[0], null);
michael@0 95 }
michael@0 96 testNull();
michael@0 97
michael@0 98 // Bug 722245.
michael@0 99 function testConstantGcThing() {
michael@0 100 function f(arr, x) {
michael@0 101 arr[x] = "abc";
michael@0 102 }
michael@0 103 var arr = ["", ""];
michael@0 104 for (var i=0; i<100; i++) {
michael@0 105 f(arr, 1);
michael@0 106 }
michael@0 107 assertEq(arr[1], "abc");
michael@0 108 }
michael@0 109 testConstantGcThing();

mercurial