michael@0: // The value of frame.environment is the same Environment object at different michael@0: // times within a single visit to a scope. michael@0: michael@0: var g = newGlobal(); michael@0: var dbg = Debugger(g); michael@0: g.eval("function h() { debugger; }"); michael@0: var hits, env; michael@0: dbg.onDebuggerStatement = function (hframe) { michael@0: var frame = hframe.older; michael@0: var e = frame.environment; michael@0: michael@0: // frame.environment is at least cached from one moment to the next. michael@0: assertEq(e, frame.environment); michael@0: michael@0: // frame.environment is cached from statement to statement within a call frame. michael@0: if (env === undefined) michael@0: env = e; michael@0: else michael@0: assertEq(e, env); michael@0: michael@0: hits++; michael@0: }; michael@0: michael@0: hits = 0; michael@0: env = undefined; michael@0: g.eval("function f() { (function () { var i = 0; h(); var j = 2; h(); })(); }"); michael@0: g.f(); michael@0: assertEq(hits, 2); michael@0: michael@0: hits = 0; michael@0: env = undefined; michael@0: g.eval("function f2() { { let i = 0; h(); let j = 2; h(); } }"); michael@0: g.f2(); michael@0: assertEq(hits, 2); michael@0: michael@0: hits = 0; michael@0: env = undefined; michael@0: g.eval("function f3() { { let i; for (i = 0; i < 2; i++) h(); } }"); michael@0: g.f3(); michael@0: assertEq(hits, 2);