summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/object-keys-00.js
blob: 497823e2e26ae0d584905ace5f5418184146391b (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
// This test case is used to test the optimized code path where the computation
// of `Object.keys(...).length` no longer compute `Object.keys(...)` as an
// intermediate result.
//
// This test verifies that the result remain consistent after the optimization.

function cmp_keys_length(a, b) {
    return Object.keys(a).length == Object.keys(b).length;
}

let objs = [
    {x:0, a: 1, b: 2},
    {x:1, b: 1, c: 2},
    {x:2, c: 1, d: 2},
    {x:3, a: 1, b: 2, c: 3},
    {x:4, b: 1, c: 2, d: 3},
    {x:5, a: 1, b: 2, c: 3, d: 4}
];

function max_of(o) {
    return o?.d ?? o?.c ?? o?.b ?? 0;
}

with({}) {}
for (let i = 0; i < 1000; i++) {
    for (let o1 of objs) {
        for (let o2 of objs) {
            assertEq(cmp_keys_length(o1, o2), max_of(o1) == max_of(o2));
        }
    }
}