michael@0: // setVariable throws if no binding exists. michael@0: michael@0: load(libdir + "asserts.js"); michael@0: michael@0: function test(code) { michael@0: var g = newGlobal(); michael@0: var dbg = new Debugger(g); michael@0: var hits = 0; michael@0: dbg.onDebuggerStatement = function (frame) { michael@0: var env = frame.older.environment; michael@0: assertThrowsInstanceOf(function () { env.setVariable("y", 2); }, Error); michael@0: hits++; michael@0: }; michael@0: g.eval("var y = 0; function d() { debugger; }"); michael@0: michael@0: assertEq(g.eval(code), 0); michael@0: michael@0: assertEq(g.y, 0); michael@0: assertEq(hits, 1); michael@0: } michael@0: michael@0: // local scope of non-heavyweight function michael@0: test("function f() { var x = 1; d(); return y; } f();"); michael@0: michael@0: // block scope michael@0: test("function h(x) { if (x) { let x = 1; d(); return y; } } h(3);"); michael@0: michael@0: // strict eval scope michael@0: test("'use strict'; eval('d(); y;');");