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 | // Environments are only inspectable while their globals are debuggees. |
michael@0 | 2 | |
michael@0 | 3 | load(libdir + 'asserts.js'); |
michael@0 | 4 | |
michael@0 | 5 | var g1 = newGlobal(); |
michael@0 | 6 | var g2 = newGlobal(); |
michael@0 | 7 | g2.g1 = g1; |
michael@0 | 8 | g1.g2 = g2; |
michael@0 | 9 | |
michael@0 | 10 | g1.eval('function f(xf) { return function h(xh) { debugger; } }'); |
michael@0 | 11 | g1.eval('var h = f("value of xf");'); |
michael@0 | 12 | |
michael@0 | 13 | // To ensure that xk gets located on the heap, and thus outlives its stack frame, we |
michael@0 | 14 | // store a function that captures it here. Kind of a kludge. |
michael@0 | 15 | g2.eval('var capture;'); |
michael@0 | 16 | g2.eval('function k(xk) { capture = function () { return xk; }; g1.h("value of xh"); }'); |
michael@0 | 17 | |
michael@0 | 18 | var dbg = new Debugger; |
michael@0 | 19 | dbg.addDebuggee(g1); |
michael@0 | 20 | dbg.addDebuggee(g2); |
michael@0 | 21 | |
michael@0 | 22 | dbg.onDebuggerStatement = debuggerHandler; |
michael@0 | 23 | |
michael@0 | 24 | var log = ''; |
michael@0 | 25 | |
michael@0 | 26 | g1.eval('g2.k("value of xk");'); |
michael@0 | 27 | |
michael@0 | 28 | var he, ke, ee; |
michael@0 | 29 | |
michael@0 | 30 | function debuggerHandler(frame) { |
michael@0 | 31 | log += 'd'; |
michael@0 | 32 | |
michael@0 | 33 | assertEq(frame.type, 'call'); |
michael@0 | 34 | he = frame.environment; |
michael@0 | 35 | |
michael@0 | 36 | assertEq(frame.older.type, 'call'); |
michael@0 | 37 | ke = frame.older.environment; |
michael@0 | 38 | |
michael@0 | 39 | assertEq(frame.older.older.type, 'eval'); |
michael@0 | 40 | ee = frame.older.older.environment; |
michael@0 | 41 | |
michael@0 | 42 | assertEq(he.inspectable, true); |
michael@0 | 43 | assertEq(he.getVariable('xh'), 'value of xh'); |
michael@0 | 44 | assertEq(he.parent.parent.getVariable('xf'), 'value of xf'); |
michael@0 | 45 | assertEq(ke.inspectable, true); |
michael@0 | 46 | assertEq(ke.getVariable('xk'), 'value of xk'); |
michael@0 | 47 | assertEq(ee.inspectable, true); |
michael@0 | 48 | assertEq(ee.type, 'object'); |
michael@0 | 49 | |
michael@0 | 50 | dbg.removeDebuggee(g2); |
michael@0 | 51 | |
michael@0 | 52 | assertEq(he.inspectable, true); |
michael@0 | 53 | assertEq(he.type, 'declarative'); |
michael@0 | 54 | assertEq(ke.inspectable, false); |
michael@0 | 55 | assertThrowsInstanceOf(() => ke.getVariable('xk'), Error); |
michael@0 | 56 | assertEq(ee.inspectable, true); |
michael@0 | 57 | assertEq(ee.type, 'object'); |
michael@0 | 58 | |
michael@0 | 59 | dbg.removeDebuggee(g1); |
michael@0 | 60 | |
michael@0 | 61 | assertEq(he.inspectable, false); |
michael@0 | 62 | assertThrowsInstanceOf(() => he.getVariable('xh'), Error); |
michael@0 | 63 | assertEq(ke.inspectable, false); |
michael@0 | 64 | assertThrowsInstanceOf(() => ke.getVariable('xk'), Error); |
michael@0 | 65 | assertEq(ee.inspectable, false); |
michael@0 | 66 | assertThrowsInstanceOf(() => ee.type, Error); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | assertEq(log, 'd'); |
michael@0 | 70 | |
michael@0 | 71 | dbg.addDebuggee(g2); |
michael@0 | 72 | |
michael@0 | 73 | assertEq(he.inspectable, false); |
michael@0 | 74 | assertThrowsInstanceOf(() => he.getVariable('xh'), Error); |
michael@0 | 75 | assertEq(ke.inspectable, true); |
michael@0 | 76 | assertEq(ke.getVariable('xk'), 'value of xk'); |
michael@0 | 77 | assertEq(ee.inspectable, false); |
michael@0 | 78 | assertThrowsInstanceOf(() => ee.type, Error); |