1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/debug/Script-staticLevel.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,43 @@ 1.4 +// Debugger.Script.prototype.staticLevel returns the script's static level. 1.5 +load(libdir + 'asserts.js'); 1.6 + 1.7 +var g = newGlobal(); 1.8 +var dbg = Debugger(); 1.9 +var gw = dbg.addDebuggee(g); 1.10 + 1.11 +function test(expr, level) { 1.12 + var log; 1.13 + dbg.onDebuggerStatement = function (frame) { 1.14 + log += 'd'; 1.15 + assertEq(frame.script.staticLevel, level); 1.16 + }; 1.17 + 1.18 + print("Testing: " + expr); 1.19 + 1.20 + log = ''; 1.21 + // The shell's 'evaluate' runs its argument as global code. 1.22 + g.evaluate(expr); 1.23 + assertEq(log, 'd'); 1.24 +} 1.25 + 1.26 + 1.27 +test("debugger;", 0); 1.28 +test("(function () { debugger; })()", 1); 1.29 +test("(function () { (function () { debugger; })(); })()", 2); 1.30 +test("(function () { (function () { (function () { debugger; })(); })(); })()", 3); 1.31 + 1.32 +test("eval('debugger;');", 1); 1.33 +test("eval('eval(\\\'debugger;\\\');');", 2); 1.34 +test("evil = eval; eval('evil(\\\'debugger;\\\');');", 0); // I don't think it's evil at all! 1.35 +test("(function () { eval('debugger;'); })();", 2); 1.36 +test("evil = eval; (function () { evil('debugger;'); })();", 0); 1.37 + 1.38 +// Generators' expressions are within a synthesized function's body. 1.39 +test("((function () { debugger; })() for (x in [1])).next();", 2); 1.40 +test("(x for (x in ((function () { debugger; })(), [1]))).next();", 2); 1.41 + 1.42 +// The staticLevel accessor can't be assigned to. 1.43 +g.eval('function f() {}'); 1.44 +var fw = gw.makeDebuggeeValue(g.f); 1.45 +assertThrowsInstanceOf(function () { "use strict"; fw.script.staticLevel = 10; }, 1.46 + TypeError);