Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Asking for the script of a Debugger.Object should work, even when lazy |
michael@0 | 2 | // functions are involved. |
michael@0 | 3 | |
michael@0 | 4 | // Note that we never hand out the scripts of non-debuggee functions, and |
michael@0 | 5 | // putting a compartment in debug mode automatically de-lazifies all its |
michael@0 | 6 | // functions. (This ensures that findScripts works, too.) |
michael@0 | 7 | // |
michael@0 | 8 | // So here we create a reference to a non-debuggee function, verify that we |
michael@0 | 9 | // can't access its interesting properties, make it a debuggee, and verify |
michael@0 | 10 | // that everything becomes available. |
michael@0 | 11 | |
michael@0 | 12 | // Create functions f, g in a non-debuggee compartment. |
michael@0 | 13 | var g1 = newGlobal(); |
michael@0 | 14 | g1.eval('function f() { return "from f"; }'); |
michael@0 | 15 | g1.eval('function g() { return "from g"; }'); |
michael@0 | 16 | |
michael@0 | 17 | // Create a debuggee compartment with CCWs referring to f and g. |
michael@0 | 18 | var g2 = newGlobal(); |
michael@0 | 19 | var dbg = new Debugger; |
michael@0 | 20 | var g2w = dbg.addDebuggee(g2); |
michael@0 | 21 | g2.f = g1.f; |
michael@0 | 22 | g2.g = g1.g; |
michael@0 | 23 | |
michael@0 | 24 | // At this point, g1.f should still be a lazy function. Unwrapping a D.O |
michael@0 | 25 | // referring to g2's CCW of f should yield a D.O referring to f directly. |
michael@0 | 26 | // Asking for that second D.O's script should yield null, because it's not |
michael@0 | 27 | // a debuggee. |
michael@0 | 28 | var fDO = g2w.getOwnPropertyDescriptor('f').value; |
michael@0 | 29 | assertEq(fDO.global, g2w); |
michael@0 | 30 | assertEq(fDO.unwrap().global === g2w, false); |
michael@0 | 31 | assertEq(fDO.unwrap().script, null); |
michael@0 | 32 | |
michael@0 | 33 | // Similarly for g1.g, and asking for its parameter names. |
michael@0 | 34 | var gDO = g2w.getOwnPropertyDescriptor('g').value; |
michael@0 | 35 | assertEq(gDO.global, g2w); |
michael@0 | 36 | assertEq(gDO.unwrap().global === g2w, false); |
michael@0 | 37 | assertEq(gDO.unwrap().parameterNames, undefined); |
michael@0 | 38 | |
michael@0 | 39 | // Add g1 as a debuggee, and verify that we can get everything. |
michael@0 | 40 | dbg.addDebuggee(g1); |
michael@0 | 41 | assertEq(fDO.unwrap().script instanceof Debugger.Script, true); |
michael@0 | 42 | assertEq(gDO.unwrap().parameterNames instanceof Array, true); |
michael@0 | 43 |