js/src/jit-test/tests/debug/Debugger-debuggees-18.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/debug/Debugger-debuggees-18.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,117 @@
     1.4 +// Debugger.prototype.{addDebuggee,hasDebuggee,removeDebuggee} recognize globals
     1.5 +// regardless of how they are specified.
     1.6 +
     1.7 +var dbg = new Debugger;
     1.8 +
     1.9 +// Assert that dbg's debuggees are exactly the set passed as arguments.
    1.10 +// The arguments are assumed to be Debugger.Object instances referring to
    1.11 +// globals without wrappers --- which is the sort returned by addDebuggee.
    1.12 +function assertDebuggees() {
    1.13 +  print("assertDebuggees([" + [g.toSource() for each (g in arguments)] + "])");
    1.14 +  var debuggees = dbg.getDebuggees();
    1.15 +  assertEq(arguments.length, debuggees.length);
    1.16 +  for each (g in arguments)
    1.17 +    assertEq(debuggees.indexOf(g) != -1, true);
    1.18 +}
    1.19 +
    1.20 +var g1 = newGlobal(); g1.toSource = function () { return "[global g1]"; };
    1.21 +var g2 = newGlobal(); g2.toSource = function () { return "[global g2]"; };
    1.22 +
    1.23 +assertDebuggees();
    1.24 +
    1.25 +// Produce every possible way to designate g1, for us to play with.
    1.26 +// Globals can be designated by any of the following:
    1.27 +//
    1.28 +// - "CCW": a Cross-Compartment Wrapper (CCW) of a global object
    1.29 +// - "D.O": a Debugger.Object whose referent is a global object
    1.30 +// - "D.O of CCW": a Debugger.Object whose referent is a CCW of a
    1.31 +//   global object, where the CCW can be securely unwrapped
    1.32 +//
    1.33 +// There's no direct "G", since globals are always in their own
    1.34 +// compartments, never the debugger's; if we ever viewed them directly,
    1.35 +// that would be a compartment violation.
    1.36 +
    1.37 +// "dg1" means "Debugger.Object referring (directly) to g1".
    1.38 +var dg1 = dbg.addDebuggee(g1);
    1.39 +dg1.toSource = function() { return "[Debugger.Object for global g1]"; };
    1.40 +assertEq(dg1.global, dg1);
    1.41 +assertEq(dg1.unwrap(), dg1);
    1.42 +assertDebuggees(dg1);
    1.43 +
    1.44 +// We need to add g2 as a debuggee; that's the only way to get a D.O referring
    1.45 +// to it without a wrapper.
    1.46 +var dg2 = dbg.addDebuggee(g2);
    1.47 +dg2.toSource = function() { return "[Debugger.Object for global g2]"; };
    1.48 +assertEq(dg2.global, dg2);
    1.49 +assertEq(dg2.unwrap(), dg2);
    1.50 +assertDebuggees(dg1, dg2);
    1.51 +
    1.52 +// "dwg1" means "Debugger.Object referring to CCW of g1".
    1.53 +var dwg1 = dg2.makeDebuggeeValue(g1);
    1.54 +assertEq(dwg1.global, dg2);
    1.55 +assertEq(dwg1.unwrap(), dg1);
    1.56 +dwg1.toSource = function() { return "[Debugger.Object for CCW of global g1]"; };
    1.57 +
    1.58 +assertDebuggees(dg1, dg2);
    1.59 +assertEq(dbg.removeDebuggee(g1), undefined);
    1.60 +assertEq(dbg.removeDebuggee(g2), undefined);
    1.61 +assertDebuggees();
    1.62 +
    1.63 +// Systematically cover all the single-global possibilities:
    1.64 +//
    1.65 +//  | added as    | designated as | addDebuggee | hasDebuggee | removeDebuggee |
    1.66 +//  |-------------+---------------+-------------+-------------+----------------|
    1.67 +//  | (not added) | CCW           | X           | X           | X              |
    1.68 +//  |             | D.O           | X           | X           | X              |
    1.69 +//  |             | D.O of CCW    | X           | X           | X              |
    1.70 +//  |-------------+---------------+-------------+-------------+----------------|
    1.71 +//  | CCW         | CCW           | X           | X           | X              |
    1.72 +//  |             | D.O           | X           | X           | X              |
    1.73 +//  |             | D.O of CCW    | X           | X           | X              |
    1.74 +//  |-------------+---------------+-------------+-------------+----------------|
    1.75 +//  | D.O         | CCW           | X           | X           | X              |
    1.76 +//  |             | D.O           | X           | X           | X              |
    1.77 +//  |             | D.O of CCW    | X           | X           | X              |
    1.78 +//  |-------------+---------------+-------------+-------------+----------------|
    1.79 +//  | D.O of CCW  | CCW           | X           | X           | X              |
    1.80 +//  |             | D.O           | X           | X           | X              |
    1.81 +//  |             | D.O of CCW    | X           | X           | X              |
    1.82 +
    1.83 +// Cover the "(not added)" section of the table, other than "addDebuggee":
    1.84 +assertEq(dbg.hasDebuggee(g1), false);
    1.85 +assertEq(dbg.hasDebuggee(dg1), false);
    1.86 +assertEq(dbg.hasDebuggee(dwg1), false);
    1.87 +
    1.88 +assertEq(dbg.removeDebuggee(g1), undefined); assertDebuggees();
    1.89 +assertEq(dbg.removeDebuggee(dg1), undefined); assertDebuggees();
    1.90 +assertEq(dbg.removeDebuggee(dwg1), undefined); assertDebuggees();
    1.91 +
    1.92 +// Try all operations adding the debuggee using |addAs|, and operating on it
    1.93 +// using |designateAs|, thereby covering one row of the table (outside the '(not
    1.94 +// added)' section), and one case in the '(not added)', 'designated as' section.
    1.95 +//
    1.96 +// |Direct| should be the Debugger.Object referring directly to the debuggee
    1.97 +// global, for checking the results from addDebuggee and getDebuggees.
    1.98 +function combo(addAs, designateAs, direct) {
    1.99 +  print("combo(" + uneval(addAs) + ", " + uneval(designateAs) + ")");
   1.100 +  assertDebuggees();
   1.101 +  assertEq(dbg.addDebuggee(addAs), direct);
   1.102 +  assertDebuggees(direct);
   1.103 +  assertEq(dbg.addDebuggee(designateAs), direct);
   1.104 +  assertDebuggees(direct);
   1.105 +  assertEq(dbg.hasDebuggee(designateAs), true);
   1.106 +  assertEq(dbg.removeDebuggee(designateAs), undefined);
   1.107 +  assertDebuggees();
   1.108 +}
   1.109 +
   1.110 +combo(g1, g1, dg1);
   1.111 +combo(dg1, g1, dg1);
   1.112 +combo(dwg1, g1, dg1);
   1.113 +
   1.114 +combo(g1, dg1, dg1);
   1.115 +combo(dg1, dg1, dg1);
   1.116 +combo(dwg1, dg1, dg1);
   1.117 +
   1.118 +combo(g1, dwg1, dg1);
   1.119 +combo(dg1, dwg1, dg1);
   1.120 +combo(dwg1, dwg1, dg1);

mercurial