object-keys-00.js (792B)
1 // This test case is used to test the optimized code path where the computation 2 // of `Object.keys(...).length` no longer compute `Object.keys(...)` as an 3 // intermediate result. 4 // 5 // This test verifies that the result remain consistent after the optimization. 6 7 function cmp_keys_length(a, b) { 8 return Object.keys(a).length == Object.keys(b).length; 9 } 10 11 let objs = [ 12 {x:0, a: 1, b: 2}, 13 {x:1, b: 1, c: 2}, 14 {x:2, c: 1, d: 2}, 15 {x:3, a: 1, b: 2, c: 3}, 16 {x:4, b: 1, c: 2, d: 3}, 17 {x:5, a: 1, b: 2, c: 3, d: 4} 18 ]; 19 20 function max_of(o) { 21 return o?.d ?? o?.c ?? o?.b ?? 0; 22 } 23 24 with({}) {} 25 for (let i = 0; i < 1000; i++) { 26 for (let o1 of objs) { 27 for (let o2 of objs) { 28 assertEq(cmp_keys_length(o1, o2), max_of(o1) == max_of(o2)); 29 } 30 } 31 }