Environment-module-tla-env-after-pop.js (1348B)
1 // Accessing the variables in the snapshot after popping the module 2 // should work until the module's top-level script's evaluation finishes. 3 4 var g = newGlobal({newCompartment: true}); 5 g.eval(` 6 var accessVarInSnapshot = null; 7 `); 8 g.eval(` 9 var resolve; 10 var p = new Promise(r => resolve = r); 11 `); 12 var dbg = new Debugger; 13 var gw = dbg.addDebuggee(g); 14 dbg.onDebuggerStatement = function (frame) { 15 assertEq(frame.environment.getVariable("x"), 10); 16 frame.eval("accessVarInSnapshot = function() { return ++x }"); 17 assertEq(gw.executeInGlobal("accessVarInSnapshot()").return, 11); 18 }; 19 const m = g.parseModule(` 20 let x = 10; 21 await 20; 22 debugger; 23 await p; 24 `); 25 moduleLink(m); 26 27 // Run until `await p`. 28 moduleEvaluate(m); 29 30 drainJobQueue(); 31 32 assertEq(g.accessVarInSnapshot !== null, true); 33 34 // At this point, the module's top-level script's evaluation isn't yet finished, 35 // and the module's ScriptSlot is still alive. 36 // Accessing the snapshot should work. 37 assertEq(g.accessVarInSnapshot(), 12); 38 39 // Continue the module's top-level script's evaluation. 40 g.eval(` 41 resolve(); 42 `); 43 44 drainJobQueue(); 45 46 // At this point, the module's ScriptSlot is cleared and accessing the 47 // snapshot doesn't work. 48 try { 49 g.accessVarInSnapshot(); 50 // the above should throw. 51 assertEq(true, false); 52 } catch (e) { 53 assertEq(e+"", "ReferenceError: x is not defined"); 54 }