| 1 |
// validate the common behavior of of Debugger.adoptFrame |
| 2 |
|
| 3 |
load(libdir + "asserts.js"); |
| 4 |
|
| 5 |
const g = newGlobal({ newCompartment: true }); |
| 6 |
|
| 7 |
const dbg1 = new Debugger(); |
| 8 |
const gDO1 = dbg1.addDebuggee(g); |
| 9 |
|
| 10 |
let suspendedFrame; |
| 11 |
dbg1.onDebuggerStatement = function() { |
| 12 |
// Test working with an onStack frame. |
| 13 |
const frame1 = dbg1.getNewestFrame(); |
| 14 |
|
| 15 |
const dbg = new Debugger(); |
| 16 |
assertErrorMessage( |
| 17 |
() => dbg.adoptFrame(frame1), |
| 18 |
Error, |
| 19 |
"Debugger.Frame's global is not a debuggee" |
| 20 |
); |
| 21 |
|
| 22 |
dbg.addDebuggee(g); |
| 23 |
|
| 24 |
const frame2 = dbg.adoptFrame(frame1); |
| 25 |
|
| 26 |
assertMatchingFrame(frame1, frame2); |
| 27 |
|
| 28 |
suspendedFrame = frame1; |
| 29 |
}; |
| 30 |
const generator = g.eval(` |
| 31 |
function* fn() { |
| 32 |
debugger; |
| 33 |
yield; |
| 34 |
} |
| 35 |
fn(); |
| 36 |
`); |
| 37 |
generator.next(); |
| 38 |
|
| 39 |
(function() { |
| 40 |
// Test working with a suspended generator frame. |
| 41 |
const dbg = new Debugger(); |
| 42 |
assertErrorMessage( |
| 43 |
() => dbg.adoptFrame(suspendedFrame), |
| 44 |
Error, |
| 45 |
"Debugger.Frame's global is not a debuggee" |
| 46 |
); |
| 47 |
|
| 48 |
dbg.addDebuggee(g); |
| 49 |
|
| 50 |
const frame2 = dbg.adoptFrame(suspendedFrame); |
| 51 |
|
| 52 |
assertMatchingFrame(frame2, suspendedFrame); |
| 53 |
})(); |
| 54 |
|
| 55 |
generator.next(); |
| 56 |
const deadFrame = suspendedFrame; |
| 57 |
|
| 58 |
(function() { |
| 59 |
// Test working with a dead frame. |
| 60 |
const dbg = new Debugger(); |
| 61 |
|
| 62 |
// This doesn't throw because the dead frame doesn't have any |
| 63 |
// debuggee-specific data associated with it anymore. |
| 64 |
dbg.adoptFrame(deadFrame); |
| 65 |
|
| 66 |
dbg.addDebuggee(g); |
| 67 |
|
| 68 |
const frame2 = dbg.adoptFrame(deadFrame); |
| 69 |
|
| 70 |
assertMatchingFrame(frame2, deadFrame); |
| 71 |
})(); |
| 72 |
|
| 73 |
function assertMatchingFrame(frame1, frame2) { |
| 74 |
assertEq(frame2.onStack, frame1.onStack); |
| 75 |
assertEq(frame2.terminated, frame1.terminated); |
| 76 |
|
| 77 |
if (!frame2.terminated) { |
| 78 |
assertEq(frame2.type, frame1.type); |
| 79 |
assertEq(frame2.offset, frame1.offset); |
| 80 |
} |
| 81 |
} |