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.Script.prototype.staticLevel returns the script's static level. |
michael@0 | 2 | load(libdir + 'asserts.js'); |
michael@0 | 3 | |
michael@0 | 4 | var g = newGlobal(); |
michael@0 | 5 | var dbg = Debugger(); |
michael@0 | 6 | var gw = dbg.addDebuggee(g); |
michael@0 | 7 | |
michael@0 | 8 | function test(expr, level) { |
michael@0 | 9 | var log; |
michael@0 | 10 | dbg.onDebuggerStatement = function (frame) { |
michael@0 | 11 | log += 'd'; |
michael@0 | 12 | assertEq(frame.script.staticLevel, level); |
michael@0 | 13 | }; |
michael@0 | 14 | |
michael@0 | 15 | print("Testing: " + expr); |
michael@0 | 16 | |
michael@0 | 17 | log = ''; |
michael@0 | 18 | // The shell's 'evaluate' runs its argument as global code. |
michael@0 | 19 | g.evaluate(expr); |
michael@0 | 20 | assertEq(log, 'd'); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | |
michael@0 | 24 | test("debugger;", 0); |
michael@0 | 25 | test("(function () { debugger; })()", 1); |
michael@0 | 26 | test("(function () { (function () { debugger; })(); })()", 2); |
michael@0 | 27 | test("(function () { (function () { (function () { debugger; })(); })(); })()", 3); |
michael@0 | 28 | |
michael@0 | 29 | test("eval('debugger;');", 1); |
michael@0 | 30 | test("eval('eval(\\\'debugger;\\\');');", 2); |
michael@0 | 31 | test("evil = eval; eval('evil(\\\'debugger;\\\');');", 0); // I don't think it's evil at all! |
michael@0 | 32 | test("(function () { eval('debugger;'); })();", 2); |
michael@0 | 33 | test("evil = eval; (function () { evil('debugger;'); })();", 0); |
michael@0 | 34 | |
michael@0 | 35 | // Generators' expressions are within a synthesized function's body. |
michael@0 | 36 | test("((function () { debugger; })() for (x in [1])).next();", 2); |
michael@0 | 37 | test("(x for (x in ((function () { debugger; })(), [1]))).next();", 2); |
michael@0 | 38 | |
michael@0 | 39 | // The staticLevel accessor can't be assigned to. |
michael@0 | 40 | g.eval('function f() {}'); |
michael@0 | 41 | var fw = gw.makeDebuggeeValue(g.f); |
michael@0 | 42 | assertThrowsInstanceOf(function () { "use strict"; fw.script.staticLevel = 10; }, |
michael@0 | 43 | TypeError); |