| 1 |
// Debugger.prototype.{addDebuggee,hasDebuggee,removeDebuggee} recognize globals |
| 2 |
// regardless of how they are specified. |
| 3 |
|
| 4 |
var dbg = new Debugger; |
| 5 |
|
| 6 |
// Assert that dbg's debuggees are exactly the set passed as arguments. |
| 7 |
// The arguments are assumed to be Debugger.Object instances referring to |
| 8 |
// globals without wrappers --- which is the sort returned by addDebuggee. |
| 9 |
function assertDebuggees(...expected) { |
| 10 |
print("assertDebuggees([" + expected.map((g) => g.toSource()) + "])"); |
| 11 |
var debuggees = dbg.getDebuggees(); |
| 12 |
assertEq(expected.length, debuggees.length); |
| 13 |
for (let g of expected) |
| 14 |
assertEq(debuggees.indexOf(g) != -1, true); |
| 15 |
} |
| 16 |
|
| 17 |
var g1 = newGlobal({newCompartment: true}); g1.toSource = function () { return "[global g1]"; }; |
| 18 |
var g2 = newGlobal({newCompartment: true}); g2.toSource = function () { return "[global g2]"; }; |
| 19 |
|
| 20 |
assertDebuggees(); |
| 21 |
|
| 22 |
// Produce every possible way to designate g1, for us to play with. |
| 23 |
// Globals can be designated by any of the following: |
| 24 |
// |
| 25 |
// - "CCW": a Cross-Compartment Wrapper (CCW) of a global object |
| 26 |
// - "D.O": a Debugger.Object whose referent is a global object |
| 27 |
// - "D.O of CCW": a Debugger.Object whose referent is a CCW of a |
| 28 |
// global object, where the CCW can be securely unwrapped |
| 29 |
// |
| 30 |
// There's no direct "G", since globals are always in their own |
| 31 |
// compartments, never the debugger's; if we ever viewed them directly, |
| 32 |
// that would be a compartment violation. |
| 33 |
|
| 34 |
// "dg1" means "Debugger.Object referring (directly) to g1". |
| 35 |
var dg1 = dbg.addDebuggee(g1); |
| 36 |
dg1.toSource = function() { return "[Debugger.Object for global g1]"; }; |
| 37 |
assertEq(dg1.unwrap(), dg1); |
| 38 |
assertDebuggees(dg1); |
| 39 |
|
| 40 |
// We need to add g2 as a debuggee; that's the only way to get a D.O referring |
| 41 |
// to it without a wrapper. |
| 42 |
var dg2 = dbg.addDebuggee(g2); |
| 43 |
dg2.toSource = function() { return "[Debugger.Object for global g2]"; }; |
| 44 |
assertEq(dg2.unwrap(), dg2); |
| 45 |
assertDebuggees(dg1, dg2); |
| 46 |
|
| 47 |
// "dwg1" means "Debugger.Object referring to CCW of g1". |
| 48 |
var dwg1 = dg2.makeDebuggeeValue(g1); |
| 49 |
assertEq(dwg1.unwrap(), dg1.makeDebuggeeValue(g1)); |
| 50 |
dwg1.toSource = function() { return "[Debugger.Object for CCW of WindowProxy of g1]"; }; |
| 51 |
|
| 52 |
assertDebuggees(dg1, dg2); |
| 53 |
assertEq(dbg.removeDebuggee(g1), undefined); |
| 54 |
assertEq(dbg.removeDebuggee(g2), undefined); |
| 55 |
assertDebuggees(); |
| 56 |
|
| 57 |
// Systematically cover all the single-global possibilities: |
| 58 |
// |
| 59 |
// | added as | designated as | addDebuggee | hasDebuggee | removeDebuggee | |
| 60 |
// |-------------+---------------+-------------+-------------+----------------| |
| 61 |
// | (not added) | CCW | X | X | X | |
| 62 |
// | | D.O | X | X | X | |
| 63 |
// | | D.O of CCW | X | X | X | |
| 64 |
// |-------------+---------------+-------------+-------------+----------------| |
| 65 |
// | CCW | CCW | X | X | X | |
| 66 |
// | | D.O | X | X | X | |
| 67 |
// | | D.O of CCW | X | X | X | |
| 68 |
// |-------------+---------------+-------------+-------------+----------------| |
| 69 |
// | D.O | CCW | X | X | X | |
| 70 |
// | | D.O | X | X | X | |
| 71 |
// | | D.O of CCW | X | X | X | |
| 72 |
// |-------------+---------------+-------------+-------------+----------------| |
| 73 |
// | D.O of CCW | CCW | X | X | X | |
| 74 |
// | | D.O | X | X | X | |
| 75 |
// | | D.O of CCW | X | X | X | |
| 76 |
|
| 77 |
// Cover the "(not added)" section of the table, other than "addDebuggee": |
| 78 |
assertEq(dbg.hasDebuggee(g1), false); |
| 79 |
assertEq(dbg.hasDebuggee(dg1), false); |
| 80 |
assertEq(dbg.hasDebuggee(dwg1), false); |
| 81 |
|
| 82 |
assertEq(dbg.removeDebuggee(g1), undefined); assertDebuggees(); |
| 83 |
assertEq(dbg.removeDebuggee(dg1), undefined); assertDebuggees(); |
| 84 |
assertEq(dbg.removeDebuggee(dwg1), undefined); assertDebuggees(); |
| 85 |
|
| 86 |
// Try all operations adding the debuggee using |addAs|, and operating on it |
| 87 |
// using |designateAs|, thereby covering one row of the table (outside the '(not |
| 88 |
// added)' section), and one case in the '(not added)', 'designated as' section. |
| 89 |
// |
| 90 |
// |Direct| should be the Debugger.Object referring directly to the debuggee |
| 91 |
// global, for checking the results from addDebuggee and getDebuggees. |
| 92 |
function combo(addAs, designateAs, direct) { |
| 93 |
print("combo(" + JSON.stringify(addAs) + ", " + JSON.stringify(designateAs) + ")"); |
| 94 |
assertDebuggees(); |
| 95 |
assertEq(dbg.addDebuggee(addAs), direct); |
| 96 |
assertDebuggees(direct); |
| 97 |
assertEq(dbg.addDebuggee(designateAs), direct); |
| 98 |
assertDebuggees(direct); |
| 99 |
assertEq(dbg.hasDebuggee(designateAs), true); |
| 100 |
assertEq(dbg.removeDebuggee(designateAs), undefined); |
| 101 |
assertDebuggees(); |
| 102 |
} |
| 103 |
|
| 104 |
combo(g1, g1, dg1); |
| 105 |
combo(dg1, g1, dg1); |
| 106 |
combo(dwg1, g1, dg1); |
| 107 |
|
| 108 |
combo(g1, dg1, dg1); |
| 109 |
combo(dg1, dg1, dg1); |
| 110 |
combo(dwg1, dg1, dg1); |
| 111 |
|
| 112 |
combo(g1, dwg1, dg1); |
| 113 |
combo(dg1, dwg1, dg1); |
| 114 |
combo(dwg1, dwg1, dg1); |