summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/cacheir/has-sparse.js
blob: 2b3b2c8451aca960e1b97451dec2e467ba85bd1b (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
function sparse() {
    var o = {0: 0, 0x10000: 0};

    var tests = [[1, false], [0, true], [-2, false], [0x10000, true], [0x20000, false]];
    for (var [key, has] of tests) {
        assertEq(key in o, has);
        assertEq(o.hasOwnProperty(key), has);
    }
}

function typedArray() {
    var o = {0: 0, 0x10000: 0};
    var t = new Int32Array(0x10001)

    // Only use Int32Array after we attached the sparse stub
    //                in o,  in t
    var tests = [[1, [false, true]],
                 [0, [true, true]],
                 [-2, [false, false]],
                 [0x10000, [true, true]],
                 [0x20000, [false, false]]];

    for (var i = 0; i < 10; i++) {
        for (var [key, has] of tests) {
            assertEq(key in o, has[i > 5 ? 1 : 0]);
            assertEq(o.hasOwnProperty(key), has[i > 5 ? 1 : 0]);
        }

        if (i == 5)
            o = t;
    }
}

function protoChange() {
    var o = {0: 0, 0x10000: 0};

    var tests = [[1, [false, true]],
                 [0, [true, true]],
                 [-2, [false, false]],
                 [0x10000, [true, true]],
                 [0x20000, [false, false]]];

    for (var i = 0; i < 10; i++) {
        for (var [key, has] of tests) {
            assertEq(key in o, has[i > 5 ? 1 : 0]);
            // Proto change doesn't affect hasOwnProperty.
            assertEq(o.hasOwnProperty(key), has[0]);
        }

        if (i == 5)
            o.__proto__ = [1, 1, 1, 1];
    }
}

sparse();
typedArray();
protoChange();