michael@0: // Basic newScript hook tests. michael@0: michael@0: var g = newGlobal(); michael@0: var dbg = Debugger(g); michael@0: var seen = WeakMap(); michael@0: var hits = 0; michael@0: dbg.onNewScript = function (s) { michael@0: // Exceptions thrown from onNewScript are swept under the rug, but they michael@0: // will at least prevent hits from being the expected number. 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: // eval code michael@0: hits = 0; michael@0: assertEq(g.eval("2 + 2"), 4); michael@0: assertEq(hits, 1); michael@0: michael@0: hits = 0; michael@0: assertEq(g.eval("eval('2 + 3')"), 5); michael@0: assertEq(hits, 2); michael@0: michael@0: // global code michael@0: hits = 0; michael@0: g.evaluate("3 + 4"); michael@0: assertEq(hits, 1); michael@0: michael@0: // function code michael@0: hits = 0; michael@0: var fn = g.Function("a", "return 5 + a;"); michael@0: assertEq(hits, 1); michael@0: assertEq(fn(8), 13); michael@0: assertEq(hits, 1); michael@0: michael@0: // cloning functions across compartments michael@0: fn = g.evaluate("(function(a) { return 5 + a; })", {compileAndGo: false}); michael@0: var g2 = newGlobal(); michael@0: dbg.addDebuggee(g2, dbg); michael@0: hits = 0; michael@0: g2.clone(fn); michael@0: assertEq(hits, 1);