Object-getPromiseReactions-04.js (1481B)
1 // Debugger.Object.prototype.getPromiseReactions reports reaction records 2 // created by `await` expressions in async functions. 3 4 const g = newGlobal({ newCompartment: true }); 5 const dbg = new Debugger; 6 const DOg = dbg.addDebuggee(g); 7 8 g.eval(` 9 var pResolve, pReject; 10 var p0 = new Promise((resolve, reject) => { pResolve = resolve; pReject = reject }); 11 12 // In this case, promiseReactions encounters a Debugger.Frame we had already 13 // associated with the generator, when we hit the debugger statement. 14 async function f1() { debugger; await p0; } 15 16 // In this case, promiseReactions must construct the Debugger.Frame itself, 17 // since it is the first to encounter the generator. 18 async function f2() { await p0; debugger; } 19 `); 20 21 let DFf1, DFf2; 22 dbg.onDebuggerStatement = (frame) => { 23 DFf1 = frame; 24 dbg.onDebuggerStatement = (frame) => { 25 DFf2 = frame; 26 dbg.onDebuggerStatement = () => { throw "Shouldn't fire twice"; }; 27 }; 28 }; 29 30 g.eval(`var p1 = f1();`); 31 assertEq(DFf1.callee.name, "f1"); 32 33 g.eval(`var p2 = f2();`); 34 assertEq(DFf2, undefined); 35 36 const [DOp0, DOp1, DOp2] = 37 [g.p0, g.p1, g.p2].map(p => DOg.makeDebuggeeValue(p)); 38 39 const reactions = DOp0.getPromiseReactions(); 40 assertEq(reactions.length, 2); 41 assertEq(reactions[0], DFf1); 42 assertEq(true, reactions[1] instanceof Debugger.Frame); 43 44 // Let f2 run until it hits its debugger statement. 45 g.pResolve(42); 46 drainJobQueue(); 47 assertEq(DFf2.terminated, true); 48 assertEq(reactions[1], DFf2);