Debian Codegraph @

js/src/jit-test/tests/debug/Environment-module-02.js

raw
1 // Debug environments for module environments should be able to access closed
2 // over variables after the module script has executed.
3
4 var g = newGlobal({newCompartment: true});
5 var dbg = Debugger(g);
6
7 const m = g.parseModule(`
8 var x = 42;
9 export function foo() { return x; }
10 foo();
11 `);
12 moduleLink(m);
13
14 let fooFunction;
15 dbg.onEnterFrame = function (frame) {
16 fooFunction = frame.callee;
17 };
18
19 moduleEvaluate(m);
20 assertEq(fooFunction instanceof Debugger.Object, true);
21
22 dbg.onEnterFrame = function (frame) {
23 const env = frame.environment.parent;
24 assertEq(env.names().join(','), "foo,x");
25 assertEq(env.getVariable('x'), 42);
26 env.setVariable('x', 3);
27 assertEq(env.getVariable('x'), 3);
28 };
29
30 fooFunction.call();