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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial