iterator-cache-invalidation.js (1146B)
1 function test(obj, expected) { 2 var result = ""; 3 for (var s in obj) { 4 result += s + ","; 5 } 6 assertEq(result, expected); 7 } 8 9 function runTest(mutate, expectedAfter) { 10 var p = {px: 1, py: 2}; 11 var o = Object.create(p); 12 o.x = 3; 13 o.y = 4; 14 15 var expectedBefore = "x,y,px,py,"; 16 test(o, expectedBefore); 17 mutate(o, p); 18 test(o, expectedAfter); 19 } 20 21 22 function testAddElement() { 23 runTest((o,p) => { o[0] = 5; }, "0,x,y,px,py,"); 24 } 25 function testAddProtoElement() { 26 runTest((o,p) => { p[0] = 5; }, "x,y,0,px,py,"); 27 } 28 function testDelete() { 29 runTest((o,p) => { delete o.x; }, "y,px,py,"); 30 } 31 function testProtoDelete() { 32 runTest((o,p) => { delete p.px; }, "x,y,py,"); 33 } 34 function testMakeUnenumerable() { 35 runTest((o,p) => { 36 Object.defineProperty(o, "x", { value: 1, enumerable: false }); 37 }, "y,px,py,"); 38 } 39 function testMakeProtoUnenumerable() { 40 runTest((o,p) => { 41 Object.defineProperty(p, "px", { value: 1, enumerable: false }); 42 }, "x,y,py,"); 43 } 44 45 for (var i = 0; i < 10; i++) { 46 testAddElement(); 47 testAddProtoElement(); 48 testDelete(); 49 testProtoDelete(); 50 testMakeUnenumerable() 51 testMakeProtoUnenumerable() 52 }