summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/setelem.js
blob: 34b900d59637ef20d69578f8bf47d292127561fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
function testInt32() {
    function f(arr, i) {
        arr[0] = 1;
        arr[1] = arr[0] + 1;
        arr[2] = arr[1] + arr[0];
        var x = arr[2]; // 3
        arr[x] = arr[x-1] + 1;
        arr[x+1] = arr[x] + i;
        return arr[4];
    }
    var a = [1, 2, 3, 4, 5, 6, 7, 8];
    for (var i=0; i<70; i++) {
        assertEq(f(a, i), i + 4);
    }
}
testInt32();

function testDouble() {
    function f(arr, d) {
        arr[0] = d;
        for (var i=1; i<8; i++) {
            arr[i] = arr[i-1] + d;
        }
        return arr[7];
    }
    var a = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
    for (var i=0; i<50; i++) {
        assertEq(f(a, Math.PI + i)|0, ((Math.PI + i) * 8)|0);
    }
}
testDouble();

function testOutOfBounds() {
    function f(arr, i, v) {
        arr[i] = v;
    }
    var a = [1, 2];
    for (var i=0; i<90; i++) {
        f(a, 1, i);
    }
    assertEq(a[1], 89);

    f(a, 2, 40);
    f(a, 100, 50);
    f(a, -1, 3);

    assertEq(a[2], 40);
    assertEq(a[100], 50);
    assertEq(a[-1], 3);
}
testOutOfBounds();

function testClassGuard() {
    function f(arr, v) {
        arr[1] = v;
    }
    var a = [1, 2, 3, 4];
    for (var i=0; i<90; i++) {
        f(a, i);
    }
    assertEq(a[1], 89);

    var b = {};
    f(b, 100);
    assertEq(b[1], 100);
}
testClassGuard();

function testMultipleTypes() {
    function f(arr, v) {
        arr[1] = v;
    }
    var a = [1, 2, 3, 4];
    var b = [1.1, -233.2, 3.3];

    for (var i=0; i<90; i++) {
        f(a, i);
    }
    assertEq(a[1], 89);
    f(b, 20);
    assertEq(b[1], 20);
}
testMultipleTypes();

function testNull() {
    function f(arr) {
        arr[0] = null;
    }

    var arr = [undefined];
    for (var i=0; i<100; i++) {
        f(arr);
    }
    assertEq(arr[0], null);
}
testNull();

// Bug 722245.
function testConstantGcThing() {
    function f(arr, x) {
        arr[x] = "abc";
    }
    var arr = ["", ""];
    for (var i=0; i<100; i++) {
        f(arr, 1);
    }
    assertEq(arr[1], "abc");
}
testConstantGcThing();