1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Environments are only inspectable while their globals are debuggees.
load(libdir + 'asserts.js');
var g1 = newGlobal({newCompartment: true});
var g2 = newGlobal({newCompartment: true});
g2.g1 = g1;
g1.g2 = g2;
g1.eval('function f(xf) { return function h(xh) { eval(""); debugger; } }');
g1.eval('var h = f("value of xf");');
// To ensure that xk gets located on the heap, and thus outlives its stack frame, we
// store a function that captures it here. Kind of a kludge.
g2.eval('var capture;');
g2.eval('function k(xk) { capture = function () { return xk; }; g1.h("value of xh"); }');
var dbg = new Debugger;
dbg.addDebuggee(g1);
dbg.addDebuggee(g2);
dbg.onDebuggerStatement = debuggerHandler;
var log = '';
g1.eval('g2.k("value of xk");');
var he, ke, ee;
function debuggerHandler(frame) {
log += 'd';
assertEq(frame.type, 'call');
he = frame.environment;
assertEq(frame.older.type, 'call');
ke = frame.older.environment;
assertEq(frame.older.older.type, 'eval');
ee = frame.older.older.environment;
assertEq(he.inspectable, true);
assertEq(he.getVariable('xh'), 'value of xh');
assertEq(he.parent.parent.getVariable('xf'), 'value of xf');
assertEq(ke.inspectable, true);
assertEq(ke.getVariable('xk'), 'value of xk');
assertEq(ee.inspectable, true);
assertEq(ee.type, 'declarative');
assertEq(ee.parent.type, 'object');
dbg.removeDebuggee(g2);
assertEq(he.inspectable, true);
assertEq(he.type, 'declarative');
assertEq(ke.inspectable, false);
assertThrowsInstanceOf(() => ke.getVariable('xk'), Error);
assertEq(ee.inspectable, true);
assertEq(ee.type, 'declarative');
assertEq(ee.parent.type, 'object');
dbg.removeDebuggee(g1);
assertEq(he.inspectable, false);
assertThrowsInstanceOf(() => he.getVariable('xh'), Error);
assertEq(ke.inspectable, false);
assertThrowsInstanceOf(() => ke.getVariable('xk'), Error);
assertEq(ee.inspectable, false);
assertThrowsInstanceOf(() => ee.type, Error);
}
assertEq(log, 'd');
dbg.addDebuggee(g2);
assertEq(he.inspectable, false);
assertThrowsInstanceOf(() => he.getVariable('xh'), Error);
assertEq(ke.inspectable, true);
assertEq(ke.getVariable('xk'), 'value of xk');
assertEq(ee.inspectable, false);
assertThrowsInstanceOf(() => ee.type, Error);
|