summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Debugger-findScripts-optimized-out.js
blob: 1c38bbbf4e117f995d1988c1dc1ea3f675cc5a9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Accessing Debugger.Script's properties which triggers delazification can
// fail if the function for the script is optimized out.
// It shouldn't crash but just throw an error.

load(libdir + "asserts.js");

var g = newGlobal({newCompartment: true});
var dbg = new Debugger(g);
g.eval(`
function enclosing() {
    (function g1() {});
    (function* g2() {});
    (async function g3() {});
    (async function* g4() {});
    () => {};
    async () => {};
}
`);

for (const s of dbg.findScripts()) {
    if (!s.displayName) {
        continue;
    }

    try {
        s.lineCount;  // don't assert
    } catch (exc) {
        // If that didn't throw, it's fine. If it did, check the message.
        assertEq(exc.message, "function is optimized out");
    }
}