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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/debug/Environment-callee-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +// Debugger.Environment.prototype.callee reveals the callee of environments
     1.5 +// that have them.
     1.6 +
     1.7 +var g = newGlobal();
     1.8 +var dbg = new Debugger;
     1.9 +var gw = dbg.addDebuggee(g);
    1.10 +
    1.11 +function check(code, expectedType, expectedCallee) {
    1.12 +  print("check(" + uneval(code) + ")");
    1.13 +  var hits;
    1.14 +  dbg.onDebuggerStatement = function (frame) {
    1.15 +    hits++;
    1.16 +    var env = frame.environment;
    1.17 +    assertEq(env.type, expectedType);
    1.18 +    assertEq(env.callee, expectedCallee);
    1.19 +  };
    1.20 +  hits = 0;
    1.21 +  g.eval(code);
    1.22 +  assertEq(hits, 1);
    1.23 +}
    1.24 +
    1.25 +check('debugger;', 'object', null);
    1.26 +check('with({}) { debugger; };', 'with', null);
    1.27 +check('let (x=1) { debugger; };', 'declarative', null);
    1.28 +
    1.29 +g.eval('function f() { debugger; }');
    1.30 +check('f()', 'declarative', gw.makeDebuggeeValue(g.f));
    1.31 +
    1.32 +g.eval('function g() { h(); }');
    1.33 +g.eval('function h() { debugger; }');
    1.34 +check('g()', 'declarative', gw.makeDebuggeeValue(g.h));
    1.35 +
    1.36 +// Strict direct eval gets its own environment.
    1.37 +check('"use strict"; eval("debugger");', 'declarative', null);
    1.38 +g.eval('function j() { "use strict"; eval("debugger;"); }');
    1.39 +check('j()', 'declarative', null);
    1.40 +
    1.41 +// Lenient direct eval shares eval's caller's environment,
    1.42 +// although this is a great evil.
    1.43 +check('eval("debugger");', 'object', null);
    1.44 +g.eval('function k() { eval("debugger;"); }');
    1.45 +check('k()', 'declarative', gw.makeDebuggeeValue(g.k));
    1.46 +
    1.47 +g.eval('function m() { debugger; yield true; }');
    1.48 +check('m().next();', 'declarative', gw.makeDebuggeeValue(g.m));
    1.49 +
    1.50 +g.eval('function n() { let (x = 1) { debugger; } }');
    1.51 +check('n()', 'declarative', null);
    1.52 +
    1.53 +g.eval('function* o() { debugger; yield true; }');
    1.54 +check('o().next();', 'declarative', gw.makeDebuggeeValue(g.o));

mercurial