summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/cacheir/setelem-id-guard.js
blob: 5f5ef82c586c8788784aa5a963958ba0630720e8 (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
function setSlot() {
    var o = {x: 1, y: 2};
    for (var i=0; i<100; i++) {
        var p = (i & 1) ? "x" : "y";
        o[p] = i;
        assertEq((i & 1) ? o.x : o.y, i);
    }
}
setSlot();

function setUnboxed() {
    var arr = [];
    for (var i=0; i<100; i++)
        arr.push({x: 1, y: 2});

    for (var i=0; i<100; i++) {
        var o = arr[i];
        var p = (i & 1) ? "x" : "y";
        o[p] = i;
        assertEq((i & 1) ? o.x : o.y, i);
    }
}
setUnboxed();

function setUnboxedExpando() {
    var arr = [];
    for (var i=0; i<100; i++)
        arr.push({x: 1, y: 2});

    for (var i=0; i<100; i++) {
        var o = arr[i];
        o.a = 1;
        o.b = 2;
        var p = (i & 1) ? "a" : "b";
        o[p] = i;
        o[p] = o[p] + 4;
        assertEq((i & 1) ? o.a : o.b, i + 4);
    }
}
setUnboxedExpando();

function setArrayLength() {
    var arr = [];
    for (var i=0; i<100; i++) {
        var p = (i & 1) ? "length" : "x";
        arr[p] = i;
        assertEq((i & 1) ? arr.length : arr.x, i);
    }
}
setArrayLength();

function setter() {
    var c = 0;
    var o = {set x(i) { c += i; }, set y(i) { c += i + 2; }};
    for (var i=0; i<100; i++) {
        var p = (i & 1) ? "x" : "y";
        o[p] = i;
    }
    assertEq(c, 5050);
}
setter();

function addSlot() {
    for (var i=0; i<100; i++) {
        var o = {};
        var p1 = (i & 1) ? "x" : "y";
        var p2 = (i % 3) ? "a" : "b";
        o[p1] = i;
        o[p2] = i;
        assertEq((i & 1) ? o.x : o.y, i);
        assertEq((i % 3) ? o.a : o.b, i);
    }
}
addSlot();

function addExpandoSlot() {
    var arr = [];
    for (var i=0; i<100; i++)
        arr.push({c: 1, d: 2});

    for (var i=0; i<100; i++) {
        var o = arr[i];
        var p1 = (i & 1) ? "x" : "y";
        var p2 = (i % 3) ? "a" : "b";
        o[p1] = i;
        o[p2] = i;
        assertEq((i & 1) ? o.x : o.y, i);
        assertEq((i % 3) ? o.a : o.b, i);
    }
}
addExpandoSlot();