megamorphic-permissive.js (1023B)
1 var throwCount = 0; 2 3 var objs = [ 4 // This is just bread and butter trigger-the-megamorphic-path stuff 5 {x: 2, a: 1}, 6 {x: 2, b: 1}, 7 {x: 2, c: 1}, 8 {x: 2, d: 1}, 9 {x: 2, e: 1}, 10 {x: 2, f: 1}, 11 12 // These ensure we hit the megamorphic permissive case 13 { get x() { return 2; }, l: 2 }, 14 { get x() { return 2; }, m: 2 }, 15 { get x() { return 2; }, n: 2 }, 16 { get x() { return 2; }, o: 2 }, 17 { get x() { return 2; }, p: 2 }, 18 { get x() { return 2; }, q: 2 }, 19 ]; 20 21 function bar(o) { 22 return o.x; 23 } 24 25 with({}){} 26 27 var count = 0; 28 29 for (var i = 0; i < 1000; i++) { 30 count += bar(objs[i % objs.length]); 31 } 32 33 34 try { 35 // Throw once during a cache miss 36 count += bar({ get x() { throwCount++; throw new Error("foo"); }, z: 2 }); 37 } catch(e) {} 38 39 try { 40 // Populate the shape so we get a cache hit, and then throw during that cache hit 41 count += bar({ get x() { return 2 }, z: 2 }); 42 count += bar({ get x() { throwCount++; throw new Error("foo"); }, z: 2 }); 43 } catch(e) {} 44 45 assertEq(count, 2002); 46 assertEq(throwCount, 2);