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