Debian Codegraph @

js/src/jit-test/tests/debug/optimized-out-arrow-this.js

raw
1 var g = newGlobal({newCompartment: true});
2 var dbg = new Debugger(g);
3
4 g.eval(`
5 function f() {
6 // |this| in arrow-functions refers to the |this| binding in outer functions.
7 // So when |frame.eval("this")| is executed, the outer |this| binding should
8 // be returned, unless it has been optimised out.
9 (() => {})();
10
11 // Ensure a |this| binding is created for |f|.
12 return this;
13 }
14 `);
15
16 var errors = [];
17
18 function enterFrame(frame) {
19 // Disable the handler so we don't call it recursively through |frame.eval|.
20 dbg.onEnterFrame = undefined;
21
22 // Store the error when resolving |this| was unsuccessful.
23 var r = frame.eval("this");
24 if (r.throw) {
25 errors.push(r.throw);
26 }
27
28 // Re-enable the handler.
29 dbg.onEnterFrame = enterFrame;
30 };
31
32 dbg.onEnterFrame = enterFrame;
33
34 g.f();
35
36 assertEq(errors.length, 1);
37 assertEq(errors[0].unsafeDereference().toString(),
38 "Error: variable 'this' has been optimized out");