Debian Codegraph @

js/src/jit-test/tests/ion/spreadcall-not-optimized-dynamic-6b.js

raw
1 // Tests when JSOP_OPTIMIZE_SPREADCALL no longer apply after the initial Ion
2 // compilation.
3
4 // JSOP_OPTIMIZE_SPREADCALL can be optimised when the following conditions
5 // are fulfilled:
6 // (1) the argument is an array
7 // (2) the array has no hole
8 // (3) array[@@iterator] is not modified
9 // (4) the array's prototype is Array.prototype
10 // (5) Array.prototype[@@iterator] is not modified
11 // (6) %ArrayIteratorPrototype%.next is not modified
12
13 function add(a, b) {
14 return a + b;
15 }
16
17 // %ArrayIteratorPrototype%.next was modified.
18 function test() {
19 function maybeInvalidate() {
20 // Use a WithStatement to prevent Ion-inlining. This ensures any
21 // bailouts due to type changes don't occur in this function, but
22 // instead in the caller.
23 with ({});
24
25 if (i === 1900) {
26 var ArrayIteratorPrototype = Object.getPrototypeOf(Array.prototype[Symbol.iterator]());
27 var ArrayIteratorPrototypeNext = ArrayIteratorPrototype.next;
28 ArrayIteratorPrototype.next = function() {
29 var res = ArrayIteratorPrototypeNext.call(this);
30 if (!res.done) {
31 res.value += 2;
32 }
33 return res;
34 };
35 }
36 }
37 function fn(...rest) {
38 maybeInvalidate();
39 return add(...rest);
40 }
41 for (var i = 0; i < 4000; ++i) {
42 assertEq(fn(1, 2), i < 1900 ? 3 : 7);
43 }
44 }
45 test();