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