Debian Codegraph @

js/src/jit-test/tests/fuses/optimized-getiterator-invalidation.js

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