Debian Codegraph @

js/src/jit-test/tests/ion/monomorphic-inlining.js

raw
1 // |jit-test| --ion-offthread-compile=off;
2
3 function foo(f, a, b) {
4 return f(a, b);
5 }
6
7 function bar(a, b) {
8 let result = a + b;
9 if (result >= fns.length) {
10 return b + a;
11 }
12 return result;
13 }
14
15 function baz(a, b) {
16 return a + b;
17 }
18
19 let fns = [];
20
21 // This is pretty fiddly. What we are trying to test here is a specific path
22 // in the bailout code which needs to know which ICScript to load, and has to
23 // decide between the script's own ICScript, or the trial-inlined ICScript
24 // which belongs to the outer script. It uses the ICFallbackStub's
25 // trialInliningState to make this decision, which can change out from
26 // underneath us if the inlined call fails. So what were doing here is getting
27 // into a state where we've monomorphic inlined a function, and gone to Ion
28 // with it. We then cause the inlined call to fail by calling a function which
29 // doesn't match what we expect, which transitions us to a failed
30 // trialInliningState. We then will bail out *inside* bar, due to the
31 // previously unseen inside of the result >= fns.length check, exercising the
32 // bailout code in question.
33 for (let i = 0; i < 2000; i++) {
34 fns.push(bar);
35 }
36
37 fns.push(baz);
38 fns.push(bar);
39
40 for (let i = 0; i < fns.length; i++) {
41 assertEq(foo(fns[i], i, 1), i + 1);
42 }