summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/cacheir/has.js
blob: 9dba6330d833aed194d8c303907299e6da3b65bf (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
var max = 40;
var key = "d";
setJitCompilerOption("ion.warmup.trigger", max - 10);

function simple() {
    var array = [{a: 1}, {b: 1, a: 1}, {c: 1, a: 1}];
    for (var i = 0; i < array.length; i++) {
        var x = array[i];
        assertEq("a" in x, true);
        assertEq("d" in x, false);
    }
}

function megamorphic() {
    var array = [{a: 1}, {b: 1, a: 1}, {c: 1, a: 1},
                 {a: 1, b: 1}, {c: 1, e: 1, a: 1},
                 {__proto__:{e: 1, f: 1, a: 1, g: 1}},
                 {__proto__:{e: 1, f: 1, a: 1, g: 1, h: 1}}];
    for (var i = 0; i < array.length; i++) {
        var x = array[i];
        assertEq("a" in x, true);
        assertEq("d" in x, false);
    }
}

function protoSetProp() {
    var base = {a: 1};
    var array = [{__proto__: base},
                 {__proto__: base, b: 1, a: 1},
                 {__proto__: base, c: 1, a: 1}];
    for (var j = 0; j < 2; j++) {
        for (var i = 0; i < array.length; i++) {
            var x = array[i];
            assertEq("a" in x, true);
            assertEq("d" in x, (j > 0));
        }
        base.d = 1; // Define property on prototype
    }
}

function protoSetElem() {
    var base = {a: 1};
    var array = [{__proto__: base},
                 {__proto__: base, b: 1, a: 1},
                 {__proto__: base, c: 1, a: 1}];
    for (var j = 0; j < 2; j++) {
        for (var i = 0; i < array.length; i++) {
            var x = array[i];
            assertEq("a" in x, true);
            assertEq("d" in x, (j > 0));
        }
        base[key] = 1; // Define property on prototype
    }
}

function test() {
    for (var i = 0; i < max; i++) {
        simple();
        megamorphic();
        protoSetProp();
        protoSetElem();
    }
}

test();
test();