michael@0: // Debugger.Script.prototype.staticLevel returns the script's static level. michael@0: load(libdir + 'asserts.js'); michael@0: michael@0: var g = newGlobal(); michael@0: var dbg = Debugger(); michael@0: var gw = dbg.addDebuggee(g); michael@0: michael@0: function test(expr, level) { michael@0: var log; michael@0: dbg.onDebuggerStatement = function (frame) { michael@0: log += 'd'; michael@0: assertEq(frame.script.staticLevel, level); michael@0: }; michael@0: michael@0: print("Testing: " + expr); michael@0: michael@0: log = ''; michael@0: // The shell's 'evaluate' runs its argument as global code. michael@0: g.evaluate(expr); michael@0: assertEq(log, 'd'); michael@0: } michael@0: michael@0: michael@0: test("debugger;", 0); michael@0: test("(function () { debugger; })()", 1); michael@0: test("(function () { (function () { debugger; })(); })()", 2); michael@0: test("(function () { (function () { (function () { debugger; })(); })(); })()", 3); michael@0: michael@0: test("eval('debugger;');", 1); michael@0: test("eval('eval(\\\'debugger;\\\');');", 2); michael@0: test("evil = eval; eval('evil(\\\'debugger;\\\');');", 0); // I don't think it's evil at all! michael@0: test("(function () { eval('debugger;'); })();", 2); michael@0: test("evil = eval; (function () { evil('debugger;'); })();", 0); michael@0: michael@0: // Generators' expressions are within a synthesized function's body. michael@0: test("((function () { debugger; })() for (x in [1])).next();", 2); michael@0: test("(x for (x in ((function () { debugger; })(), [1]))).next();", 2); michael@0: michael@0: // The staticLevel accessor can't be assigned to. michael@0: g.eval('function f() {}'); michael@0: var fw = gw.makeDebuggeeValue(g.f); michael@0: assertThrowsInstanceOf(function () { "use strict"; fw.script.staticLevel = 10; }, michael@0: TypeError);