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 | // Debugger.Environment.prototype.callee reveals the callee of environments |
michael@0 | 2 | // that have them. |
michael@0 | 3 | |
michael@0 | 4 | var g = newGlobal(); |
michael@0 | 5 | var dbg = new Debugger; |
michael@0 | 6 | var gw = dbg.addDebuggee(g); |
michael@0 | 7 | |
michael@0 | 8 | function check(code, expectedType, expectedCallee) { |
michael@0 | 9 | print("check(" + uneval(code) + ")"); |
michael@0 | 10 | var hits; |
michael@0 | 11 | dbg.onDebuggerStatement = function (frame) { |
michael@0 | 12 | hits++; |
michael@0 | 13 | var env = frame.environment; |
michael@0 | 14 | assertEq(env.type, expectedType); |
michael@0 | 15 | assertEq(env.callee, expectedCallee); |
michael@0 | 16 | }; |
michael@0 | 17 | hits = 0; |
michael@0 | 18 | g.eval(code); |
michael@0 | 19 | assertEq(hits, 1); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | check('debugger;', 'object', null); |
michael@0 | 23 | check('with({}) { debugger; };', 'with', null); |
michael@0 | 24 | check('let (x=1) { debugger; };', 'declarative', null); |
michael@0 | 25 | |
michael@0 | 26 | g.eval('function f() { debugger; }'); |
michael@0 | 27 | check('f()', 'declarative', gw.makeDebuggeeValue(g.f)); |
michael@0 | 28 | |
michael@0 | 29 | g.eval('function g() { h(); }'); |
michael@0 | 30 | g.eval('function h() { debugger; }'); |
michael@0 | 31 | check('g()', 'declarative', gw.makeDebuggeeValue(g.h)); |
michael@0 | 32 | |
michael@0 | 33 | // Strict direct eval gets its own environment. |
michael@0 | 34 | check('"use strict"; eval("debugger");', 'declarative', null); |
michael@0 | 35 | g.eval('function j() { "use strict"; eval("debugger;"); }'); |
michael@0 | 36 | check('j()', 'declarative', null); |
michael@0 | 37 | |
michael@0 | 38 | // Lenient direct eval shares eval's caller's environment, |
michael@0 | 39 | // although this is a great evil. |
michael@0 | 40 | check('eval("debugger");', 'object', null); |
michael@0 | 41 | g.eval('function k() { eval("debugger;"); }'); |
michael@0 | 42 | check('k()', 'declarative', gw.makeDebuggeeValue(g.k)); |
michael@0 | 43 | |
michael@0 | 44 | g.eval('function m() { debugger; yield true; }'); |
michael@0 | 45 | check('m().next();', 'declarative', gw.makeDebuggeeValue(g.m)); |
michael@0 | 46 | |
michael@0 | 47 | g.eval('function n() { let (x = 1) { debugger; } }'); |
michael@0 | 48 | check('n()', 'declarative', null); |
michael@0 | 49 | |
michael@0 | 50 | g.eval('function* o() { debugger; yield true; }'); |
michael@0 | 51 | check('o().next();', 'declarative', gw.makeDebuggeeValue(g.o)); |