michael@0: // Multiple debuggers all get their onPop handlers called, and see each others' effects. michael@0: michael@0: function completionsEqual(c1, c2) { michael@0: if (c1 && c2) { michael@0: if (c1.throw) michael@0: return c1.throw === c2.throw; michael@0: else michael@0: return c1.return === c2.return; michael@0: } michael@0: return c1 === c2; michael@0: } michael@0: michael@0: function completionString(c) { michael@0: if (c == null) michael@0: return 'x'; michael@0: if (c.return) michael@0: return 'r' + c.return; michael@0: if (c.throw) michael@0: return 't' + c.throw; michael@0: return '?'; michael@0: } michael@0: michael@0: var g = newGlobal(); // poor thing michael@0: g.eval('function f() { debugger; return "1"; }'); michael@0: michael@0: // We create a bunch of debuggers, but they all consult this global variable michael@0: // for expectations and responses, so the order in which events get michael@0: // reported to the debuggers doesn't matter. michael@0: // michael@0: // This list includes every pair of transitions, and is of minimal length. michael@0: // As if opportunity cost were just some theoretical concern. michael@0: var sequence = [{ expect: { return: '1' }, resume: { return: '2'} }, michael@0: { expect: { return: '2' }, resume: { throw: '3'} }, michael@0: { expect: { throw: '3' }, resume: { return: '4'} }, michael@0: { expect: { return: '4' }, resume: null }, michael@0: { expect: null, resume: { throw: '5'} }, michael@0: { expect: { throw: '5' }, resume: { throw: '6'} }, michael@0: { expect: { throw: '6' }, resume: null }, michael@0: { expect: null, resume: null }, michael@0: { expect: null, resume: { return: '7'} }]; michael@0: michael@0: // A list of the debuggers' Debugger.Frame instances. When it's all over, michael@0: // we test that they are all marked as no longer live. michael@0: var frames = []; michael@0: michael@0: // We start off the test via Debugger.Frame.prototype.eval, so if we end michael@0: // with a termination, we still catch it, instead of aborting the whole michael@0: // test. (Debugger.Object.prototype.evalInGlobal would simplify this...) michael@0: var dbg0 = new Debugger(g); michael@0: dbg0.onEnterFrame = function handleOriginalEnter(frame) { michael@0: dbg0.log += '('; michael@0: dbg0.onEnterFrame = undefined; michael@0: michael@0: assertEq(frame.live, true); michael@0: frames.push(frame); michael@0: michael@0: var dbgs = []; michael@0: var log; michael@0: michael@0: // Create a separate debugger to carry out each item in sequence. michael@0: for (s in sequence) { michael@0: // Each debugger's handlers close over a distinct 'dbg', but michael@0: // that's the only distinction between them. Otherwise, they're michael@0: // driven entirely by global data, so the order in which events are michael@0: // dispatched to them shouldn't matter. michael@0: let dbg = new Debugger(g); michael@0: dbgs.push(dbg); michael@0: michael@0: dbg.onDebuggerStatement = function handleDebuggerStatement(f) { michael@0: log += 'd'; michael@0: assertEq(f.live, true); michael@0: frames.push(f); michael@0: }; michael@0: michael@0: // First expect the 'eval'... michael@0: dbg.onEnterFrame = function handleEnterEval(f) { michael@0: log += 'e'; michael@0: assertEq(f.type, 'eval'); michael@0: assertEq(f.live, true); michael@0: frames.push(f); michael@0: michael@0: // Then expect the call. michael@0: dbg.onEnterFrame = function handleEnterCall(f) { michael@0: log += '('; michael@0: assertEq(f.type, 'call'); michael@0: assertEq(f.live, true); michael@0: frames.push(f); michael@0: michael@0: // Don't expect any further frames. michael@0: dbg.onEnterFrame = function handleExtraEnter(f) { michael@0: log += 'z'; michael@0: }; michael@0: michael@0: f.onPop = function handlePop(c) { michael@0: log += ')' + completionString(c); michael@0: assertEq(this.live, true); michael@0: frames.push(this); michael@0: michael@0: // Check that this debugger is in the list, and then remove it. michael@0: var i = dbgs.indexOf(dbg); michael@0: assertEq(i != -1, true); michael@0: dbgs.splice(i,1); michael@0: michael@0: // Check the frame's completion value against 'sequence'. michael@0: assertEq(completionsEqual(c, sequence[0].expect), true); michael@0: michael@0: // Provide the next resumption value from 'sequence'. michael@0: return sequence.shift().resume; michael@0: }; michael@0: }; michael@0: }; michael@0: } michael@0: michael@0: log = ''; michael@0: assertEq(completionsEqual(frame.eval('f()'), { return: '7' }), true); michael@0: assertEq(log, "eeeeeeeee(((((((((ddddddddd)r1)r2)t3)r4)x)t5)t6)x)x"); michael@0: michael@0: dbg0.log += '.'; michael@0: }; michael@0: michael@0: dbg0.log = ''; michael@0: g.eval('eval'); michael@0: assertEq(dbg0.log, '(.'); michael@0: michael@0: // Check that all Debugger.Frame instances we ran into are now marked as dead. michael@0: for (var i = 0; i < frames.length; i++) michael@0: assertEq(frames[i].live, false);