michael@0: // Creating a new script with any number of subscripts triggers the newScript hook exactly once. michael@0: michael@0: var g = newGlobal(); michael@0: var dbg = Debugger(g); michael@0: var seen = WeakMap(); michael@0: var hits; michael@0: dbg.onNewScript = function (s) { michael@0: assertEq(s instanceof Debugger.Script, true); michael@0: assertEq(!seen.has(s), true); michael@0: seen.set(s, true); michael@0: hits++; michael@0: }; michael@0: michael@0: dbg.uncaughtExceptionHook = function () { hits = -999; }; michael@0: michael@0: function test(f) { michael@0: hits = 0; michael@0: f(); michael@0: assertEq(hits, 1); michael@0: } michael@0: michael@0: // eval declaring a function michael@0: test(function () { g.eval("function A(m, n) { return m===0?n+1:n===0?A(m-1,1):A(m-1,A(m,n-1)); }"); }); michael@0: michael@0: // evaluate declaring a function michael@0: test(function () { g.eval("function g(a, b) { return b===0?a:g(b,a%b); }"); }); michael@0: michael@0: // eval declaring multiple functions michael@0: test(function () { michael@0: g.eval("function e(i) { return i===0||o(i-1); }\n" + michael@0: "function o(i) { return i!==0&&e(i-1); }\n"); michael@0: }); michael@0: michael@0: // eval declaring nested functions michael@0: test(function () { g.eval("function plus(x) { return function plusx(y) { return x + y; }; }"); }); michael@0: michael@0: // eval with a function-expression michael@0: test(function () { g.eval("[3].map(function (i) { return -i; });"); }); michael@0: michael@0: // eval with getters and setters michael@0: test(function () { g.eval("var obj = {get x() { return 1; }, set x(v) { print(v); }};"); }); michael@0: michael@0: // Function with nested functions michael@0: test(function () { return g.Function("a", "b", "return b - a;"); }); michael@0: michael@0: // cloning a function with nested functions michael@0: test(function () { g.clone(evaluate("(function(x) { return x + 1; })", {compileAndGo: false})); }); michael@0: michael@0: // eval declaring a generator michael@0: test(function () { g.eval("function r(n) { for (var i=0;i