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