michael@0: // Environment.prototype.find finds bindings that are function arguments, 'let' michael@0: // bindings, or FunctionExpression names. michael@0: michael@0: var g = newGlobal(); michael@0: g.eval("function h() { debugger; }"); michael@0: michael@0: var dbg = new Debugger(g); michael@0: michael@0: function test1(code) { michael@0: var hits = 0; michael@0: dbg.onDebuggerStatement = function (frame) { michael@0: var env = frame.older.environment.find('X'); michael@0: assertEq(env.names().indexOf('X') !== -1, true); michael@0: assertEq(env.type, 'declarative'); michael@0: assertEq(env.parent !== null, true); michael@0: hits++; michael@0: }; michael@0: g.eval(code); michael@0: assertEq(hits, 1); michael@0: } michael@0: michael@0: var manyNames = ''; michael@0: for (var i = 0; i < 2048; i++) michael@0: manyNames += 'x' + i + ', '; michael@0: manyNames += 'X'; michael@0: michael@0: function test2(code) { michael@0: print(code + " : one"); michael@0: test1(code.replace('@@', 'X')); michael@0: print(code + " : many"); michael@0: test1(code.replace('@@', manyNames)); michael@0: } michael@0: michael@0: test2('function f(@@) { h(); } f(1);'); michael@0: test2('function f(@@) { h(); } f();'); michael@0: test2('function f(@@) { return function g() { h(X); }; } f(1)();'); michael@0: test2('function f(@@) { return function g() { h(X); }; } f()();'); michael@0: michael@0: test2(' { let @@ = 0; h(); }'); michael@0: test2('function f(a, b, c) { let @@ = 0; h(); } f(1, 2, 3);'); michael@0: test2(' { let @@ = 0; { let y = 0; h(); } }'); michael@0: test2('function f() { let @@ = 0; { let y = 0; h(); } } f();'); michael@0: test2(' { for (let @@ = 0; X < 1; X++) h(); }'); michael@0: test2('function f() { for (let @@ = 0; X < 1; X++) h(); } f();'); michael@0: test2(' { (let (@@ = 0) let (y = 2, z = 3) h()); }'); michael@0: test2('function f() { return (let (@@ = 0) let (y = 2, z = 3) h()); } f();'); michael@0: michael@0: test1('(function X() { h(); })();'); michael@0: test1('(function X(a, b, c) { h(); })(1, 2, 3);');