optimized-getiterator-invalidation.js (904B)
1 const ITERS = 1000; 2 3 // A function which when warp compiled should use 4 // OptimizedGetIterator elision, and rely on invalidation 5 function f(x) { 6 let sum = 0; 7 for (let i = 0; i < ITERS; i++) { 8 const [a, b, c] = x 9 sum = a + b + c; 10 } 11 return sum 12 } 13 14 // Run the function f 1000 times to warp compile it. Use 4 elements here to ensure 15 // the return property of the ArrayIteratorPrototype is called. 16 let arr = [1, 2, 3, 4]; 17 for (let i = 0; i < 1000; i++) { 18 f(arr); 19 } 20 21 // Initialize the globally scoped counter 22 let counter = 0; 23 const ArrayIteratorPrototype = Object.getPrototypeOf([][Symbol.iterator]()); 24 25 // Setting the return property should invalidate the warp script here. 26 ArrayIteratorPrototype.return = function () { 27 counter++; 28 return { done: true }; 29 }; 30 31 32 // Call f one more time 33 f(arr); 34 35 // Use assertEq to check the value of counter. 36 assertEq(counter, ITERS);