Debian Codegraph @

js/src/jit-test/tests/debug/Environment-calleeScript-01.js

raw
1 // Debugger.Environment.prototype.calleeScript reveals the script of function
2 // environments.
3
4 var g = newGlobal({newCompartment: true});
5 var dbg = new Debugger;
6 var gw = dbg.addDebuggee(g);
7
8 function check(code, expectedType, expectedCallee) {
9 print("check(" + JSON.stringify(code) + ")");
10 var hits;
11 dbg.onDebuggerStatement = function (frame) {
12 hits++;
13 var env = frame.environment;
14 assertEq(env.type, expectedType);
15 assertEq(env.calleeScript, expectedCallee ? expectedCallee.script : null);
16 };
17 hits = 0;
18 g.eval(code);
19 assertEq(hits, 1);
20 }
21
22 check('debugger;', 'declarative', 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 // All evals get a lexical scope.
34 check('"use strict"; eval("debugger");', 'declarative', null);
35 g.eval('function j() { "use strict"; eval("debugger;"); }');
36 check('j()', 'declarative', null);
37
38 // All evals get a lexical scope.
39 check('eval("debugger");', 'declarative', null);
40
41 g.eval('function* m() { debugger; yield true; }');
42 check('m().next();', 'declarative', gw.makeDebuggeeValue(g.m));
43
44 g.eval('function n() { { let x = 1; debugger; } }');
45 check('n()', 'declarative', null);
46
47 g.eval('function* o() { debugger; yield true; }');
48 check('o().next();', 'declarative', gw.makeDebuggeeValue(g.o));