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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial