Debian Codegraph @

js/src/jit-test/tests/debug/optimized-out-01.js

raw
1 // Tests that we can reflect optimized out values.
2 //
3 // Unfortunately these tests are brittle. They depend on opaque JIT heuristics
4 // kicking in.
5
6 // Use gczeal 0 to keep CGC from invalidating Ion code and causing test failures.
7 gczeal(0);
8
9 load(libdir + "jitopts.js");
10
11 if (!jitTogglesMatch(Opts_Ion2NoOffthreadCompilation))
12 quit(0);
13
14 withJitOptions(Opts_Ion2NoOffthreadCompilation, function () {
15 var g = newGlobal({newCompartment: true});
16 var dbg = new Debugger;
17
18 // Note that this *depends* on CCW scripted functions being opaque to Ion
19 // optimization and not deoptimizing the frames below the call to toggle.
20 g.toggle = function toggle(d) {
21 if (d) {
22 dbg.addDebuggee(g);
23 var frame = dbg.getNewestFrame();
24 assertEq(frame.implementation, "ion");
25 // x is unused and should be elided.
26 assertEq(frame.environment.getVariable("x").optimizedOut, true);
27 assertEq(frame.arguments[1].optimizedOut, true);
28 }
29 };
30
31 g.eval("" + function f(d, x) {
32 "use strict";
33 eval("g(d, x)"); // `eval` to avoid inlining g.
34 });
35
36 g.eval("" + function g(d, x) {
37 "use strict";
38 for (var i = 0; i < 100; i++);
39 toggle(d);
40 });
41
42 g.eval("(" + function test() {
43 for (i = 0; i < 15; i++)
44 f(false, 42);
45 f(true, 42);
46 } + ")();");
47 });