summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/inlining/object-is-stricteq.js
blob: 059c3f210c0d4733f2164b3e5a0fdc4acbed13c9 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Test when Object.is() is inlined as JSOP_STRICTEQ

function SameValue(x, y) {
    if (x === y) {
        return (x !== 0) || (1 / x === 1 / y);
    }
    return (x !== x && y !== y);
}

var compareTemplate = function compare(name, xs, ys) {
    // Compare each entry in xs with each entry in ys and ensure Object.is
    // computes the same result as SameValue.
    for (var i = 0; i < 1000; ++i) {
        var xi = (i % xs.length) | 0;
        var yi = ((i + ((i / ys.length) | 0)) % ys.length) | 0;

        assertEq(Object.is(xs[xi], ys[yi]), SameValue(xs[xi], ys[yi]), name);
    }
}

const objects = {
    plain: {},
    function: function(){},
    proxy: new Proxy({}, {}),
};

const sym = Symbol();

const testCases = [
    {
        name: "Homogenous-Int32",
        xs: [-1, 0, 1, 2, 0x7fffffff],
        ys: [2, 1, 0, -5, -0x80000000],
    },
    {
        name: "Homogenous-Boolean",
        xs: [true, false],
        ys: [true, false],
    },
    {
        name: "Homogenous-Object",
        xs: [{}, [], objects.plain, objects.proxy],
        ys: [{}, objects.function, objects.plain, objects.proxy],
    },
    {
        name: "Homogenous-String",
        xs: ["", "abc", "αβγαβγ", "𝐀𝐁𝐂𝐀𝐁𝐂", "ABCabc"],
        ys: ["abc", "ABC", "ABCABC", "αβγαβγ", "𝐀𝐁𝐂𝐀𝐁𝐂"],
    },
    {
        name: "Homogenous-Symbol",
        xs: [Symbol.iterator, Symbol(), Symbol.for("object-is"), sym],
        ys: [sym, Symbol.match, Symbol(), Symbol.for("object-is-two")],
    },
    {
        name: "Homogenous-Null",
        xs: [null, null],
        ys: [null, null],
    },
    {
        name: "Homogenous-Undefined",
        xs: [undefined, undefined],
        ys: [undefined, undefined],
    },

    // Note: Values must not include floating-point types!
    {
        name: "String-Value",
        xs: ["", "abc", "αβγαβγ", "𝐀𝐁𝐂𝐀𝐁𝐂"],
        ys: [null, undefined, sym, true, 0, "", {}],
    },
    {
        name: "Null-Value",
        xs: [null, null],
        ys: [null, undefined, sym, true, 0, "", {}],
    },
    {
        name: "Undefined-Value",
        xs: [undefined, undefined],
        ys: [null, undefined, sym, true, 0, "", {}],
    },
    {
        name: "Boolean-Value",
        xs: [true, false],
        ys: [null, undefined, sym, true, 0, "", {}],
    },

    // Note: Values must not include floating-point types!
    {
        name: "Value-String",
        xs: [null, undefined, sym, true, 0, "", {}],
        ys: ["", "abc", "αβγαβγ", "𝐀𝐁𝐂𝐀𝐁𝐂"],
    },
    {
        name: "Value-Null",
        xs: [null, undefined, sym, true, 0, "", {}],
        ys: [null, null],
    },
    {
        name: "Value-Undefined",
        xs: [null, undefined, sym, true, 0, "", {}],
        ys: [undefined, undefined],
    },
    {
        name: "Value-Boolean",
        xs: [null, undefined, sym, true, 0, "", {}],
        ys: [undefined, undefined],
    },

    // Strict-equal comparison can be optimized to bitwise comparison when
    // string types are not possible.
    // Note: Values must not include floating-point types!
    {
        name: "Value-Value",
        xs: [null, undefined, sym, true, 0, {}],
        ys: [null, undefined, sym, true, 0, {}],
    },
    {
        name: "ValueMaybeString-ValueMaybeString",
        xs: [null, undefined, sym, true, 0, "", {}],
        ys: [null, undefined, sym, true, 0, "", {}],
    },
    {
        name: "Value-ValueMaybeString",
        xs: [null, undefined, sym, true, 0, {}],
        ys: [null, undefined, sym, true, 0, "", {}],
    },
    {
        name: "ValueMaybeString-Value",
        xs: [null, undefined, sym, true, 0, "", {}],
        ys: [null, undefined, sym, true, 0, {}],
    },
];

for (let {name, xs, ys} of testCases) {
    // Create a separate function for each test case.
    // Use indirect eval to avoid possible direct eval deopts.
    const compare = (0, eval)(`(${compareTemplate})`);

    for (let i = 0; i < 5; ++i) {
        compare(name, xs, ys);
    }
}