Debian Codegraph @

js/src/jit-test/tests/ion/object-keys-01.js

raw
1
2 // This test case is used to test one common configuration seen in the wild and
3 // that we expect to be successful at optimizing properly.
4
5 // Similar functions are part of popular framework such as React and Angular.
6 function shallowEqual(o1, o2) {
7 var k1 = Object.keys(o1);
8 var k2 = Object.keys(o2);
9 if (k1.length != k2.length) {
10 return false;
11 }
12 for (var k = 0; k < k1.length; k++) {
13 if (!Object.hasOwnProperty.call(o2, k1[k]) || !Object.is(o1[k1[k]], o2[k1[k]])) {
14 return false;
15 }
16 }
17 return true;
18 }
19
20 let objs = [
21 {x:0, a: 1, b: 2},
22 {x:1, b: 1, c: 2},
23 {x:2, c: 1, d: 2},
24 {x:3, a: 1, b: 2, c: 3},
25 {x:4, b: 1, c: 2, d: 3},
26 {x:5, a: 1, b: 2, c: 3, d: 4}
27 ];
28
29 with({}) {}
30 for (let i = 0; i < 1000; i++) {
31 for (let o1 of objs) {
32 for (let o2 of objs) {
33 assertEq(shallowEqual(o1, o2), Object.is(o1, o2));
34 }
35 }
36 }