summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/inlining/getelem-getter-id-mismatch.js
blob: 57a2c0ff68d5f2def714895e8bb3534af7aa92da (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
110
111
112
113
// Ensure BaselineInspector properly handles mixed atom/symbols when determining
// whether or not a jsop_getelem access to a getter can be inlined.

// Defined outside of the test functions to ensure they're recognised as
// constants in Ion.
var atom1 = "prop1";
var atom2 = "prop2";
var sym1 = Symbol();
var sym2 = Symbol();

function testAtomAtom() {
    var holder = {
        get [atom1]() { return 1; },
        get [atom2]() { return 2; },
    };

    function get(name) {
        // Single access point called with different atoms.
        return holder[name];
    }

    function f() {
        for (var i = 0; i < 1000; ++i) {
            var x = get(atom1);
            var y = get(atom2);
            assertEq(x, 1);
            assertEq(y, 2);
        }
    }

    for (var i = 0; i < 2; i++) {
        f();
    }
}
testAtomAtom();

function testAtomSymbol() {
    var holder = {
        get [atom1]() { return 1; },
        get [sym2]() { return 2; },
    };

    function get(name) {
        // Single access point called with atom and symbol.
        return holder[name];
    }

    function f() {
        for (var i = 0; i < 1000; ++i) {
            var x = get(atom1);
            var y = get(sym2);
            assertEq(x, 1);
            assertEq(y, 2);
        }
    }

    for (var i = 0; i < 2; i++) {
        f();
    }
}
testAtomSymbol();

function testSymbolAtom() {
    var holder = {
        get [sym1]() { return 1; },
        get [atom2]() { return 2; },
    };

    function get(name) {
        // Single access point called with symbol and atom.
        return holder[name];
    }

    function f() {
        for (var i = 0; i < 1000; ++i) {
            var x = get(sym1);
            var y = get(atom2);
            assertEq(x, 1);
            assertEq(y, 2);
        }
    }

    for (var i = 0; i < 2; i++) {
        f();
    }
}
testSymbolAtom();

function testSymbolSymbol() {
    var holder = {
        get [sym1]() { return 1; },
        get [sym2]() { return 2; },
    };

    function get(name) {
        // Single access point called with different symbols.
        return holder[name];
    }

    function f() {
        for (var i = 0; i < 1000; ++i) {
            var x = get(sym1);
            var y = get(sym2);
            assertEq(x, 1);
            assertEq(y, 2);
        }
    }

    for (var i = 0; i < 2; i++) {
        f();
    }
}
testSymbolSymbol();