Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Multiple debuggers all get their onPop handlers called, and see each others' effects. |
michael@0 | 2 | |
michael@0 | 3 | function completionsEqual(c1, c2) { |
michael@0 | 4 | if (c1 && c2) { |
michael@0 | 5 | if (c1.throw) |
michael@0 | 6 | return c1.throw === c2.throw; |
michael@0 | 7 | else |
michael@0 | 8 | return c1.return === c2.return; |
michael@0 | 9 | } |
michael@0 | 10 | return c1 === c2; |
michael@0 | 11 | } |
michael@0 | 12 | |
michael@0 | 13 | function completionString(c) { |
michael@0 | 14 | if (c == null) |
michael@0 | 15 | return 'x'; |
michael@0 | 16 | if (c.return) |
michael@0 | 17 | return 'r' + c.return; |
michael@0 | 18 | if (c.throw) |
michael@0 | 19 | return 't' + c.throw; |
michael@0 | 20 | return '?'; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | var g = newGlobal(); // poor thing |
michael@0 | 24 | g.eval('function f() { debugger; return "1"; }'); |
michael@0 | 25 | |
michael@0 | 26 | // We create a bunch of debuggers, but they all consult this global variable |
michael@0 | 27 | // for expectations and responses, so the order in which events get |
michael@0 | 28 | // reported to the debuggers doesn't matter. |
michael@0 | 29 | // |
michael@0 | 30 | // This list includes every pair of transitions, and is of minimal length. |
michael@0 | 31 | // As if opportunity cost were just some theoretical concern. |
michael@0 | 32 | var sequence = [{ expect: { return: '1' }, resume: { return: '2'} }, |
michael@0 | 33 | { expect: { return: '2' }, resume: { throw: '3'} }, |
michael@0 | 34 | { expect: { throw: '3' }, resume: { return: '4'} }, |
michael@0 | 35 | { expect: { return: '4' }, resume: null }, |
michael@0 | 36 | { expect: null, resume: { throw: '5'} }, |
michael@0 | 37 | { expect: { throw: '5' }, resume: { throw: '6'} }, |
michael@0 | 38 | { expect: { throw: '6' }, resume: null }, |
michael@0 | 39 | { expect: null, resume: null }, |
michael@0 | 40 | { expect: null, resume: { return: '7'} }]; |
michael@0 | 41 | |
michael@0 | 42 | // A list of the debuggers' Debugger.Frame instances. When it's all over, |
michael@0 | 43 | // we test that they are all marked as no longer live. |
michael@0 | 44 | var frames = []; |
michael@0 | 45 | |
michael@0 | 46 | // We start off the test via Debugger.Frame.prototype.eval, so if we end |
michael@0 | 47 | // with a termination, we still catch it, instead of aborting the whole |
michael@0 | 48 | // test. (Debugger.Object.prototype.evalInGlobal would simplify this...) |
michael@0 | 49 | var dbg0 = new Debugger(g); |
michael@0 | 50 | dbg0.onEnterFrame = function handleOriginalEnter(frame) { |
michael@0 | 51 | dbg0.log += '('; |
michael@0 | 52 | dbg0.onEnterFrame = undefined; |
michael@0 | 53 | |
michael@0 | 54 | assertEq(frame.live, true); |
michael@0 | 55 | frames.push(frame); |
michael@0 | 56 | |
michael@0 | 57 | var dbgs = []; |
michael@0 | 58 | var log; |
michael@0 | 59 | |
michael@0 | 60 | // Create a separate debugger to carry out each item in sequence. |
michael@0 | 61 | for (s in sequence) { |
michael@0 | 62 | // Each debugger's handlers close over a distinct 'dbg', but |
michael@0 | 63 | // that's the only distinction between them. Otherwise, they're |
michael@0 | 64 | // driven entirely by global data, so the order in which events are |
michael@0 | 65 | // dispatched to them shouldn't matter. |
michael@0 | 66 | let dbg = new Debugger(g); |
michael@0 | 67 | dbgs.push(dbg); |
michael@0 | 68 | |
michael@0 | 69 | dbg.onDebuggerStatement = function handleDebuggerStatement(f) { |
michael@0 | 70 | log += 'd'; |
michael@0 | 71 | assertEq(f.live, true); |
michael@0 | 72 | frames.push(f); |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | // First expect the 'eval'... |
michael@0 | 76 | dbg.onEnterFrame = function handleEnterEval(f) { |
michael@0 | 77 | log += 'e'; |
michael@0 | 78 | assertEq(f.type, 'eval'); |
michael@0 | 79 | assertEq(f.live, true); |
michael@0 | 80 | frames.push(f); |
michael@0 | 81 | |
michael@0 | 82 | // Then expect the call. |
michael@0 | 83 | dbg.onEnterFrame = function handleEnterCall(f) { |
michael@0 | 84 | log += '('; |
michael@0 | 85 | assertEq(f.type, 'call'); |
michael@0 | 86 | assertEq(f.live, true); |
michael@0 | 87 | frames.push(f); |
michael@0 | 88 | |
michael@0 | 89 | // Don't expect any further frames. |
michael@0 | 90 | dbg.onEnterFrame = function handleExtraEnter(f) { |
michael@0 | 91 | log += 'z'; |
michael@0 | 92 | }; |
michael@0 | 93 | |
michael@0 | 94 | f.onPop = function handlePop(c) { |
michael@0 | 95 | log += ')' + completionString(c); |
michael@0 | 96 | assertEq(this.live, true); |
michael@0 | 97 | frames.push(this); |
michael@0 | 98 | |
michael@0 | 99 | // Check that this debugger is in the list, and then remove it. |
michael@0 | 100 | var i = dbgs.indexOf(dbg); |
michael@0 | 101 | assertEq(i != -1, true); |
michael@0 | 102 | dbgs.splice(i,1); |
michael@0 | 103 | |
michael@0 | 104 | // Check the frame's completion value against 'sequence'. |
michael@0 | 105 | assertEq(completionsEqual(c, sequence[0].expect), true); |
michael@0 | 106 | |
michael@0 | 107 | // Provide the next resumption value from 'sequence'. |
michael@0 | 108 | return sequence.shift().resume; |
michael@0 | 109 | }; |
michael@0 | 110 | }; |
michael@0 | 111 | }; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | log = ''; |
michael@0 | 115 | assertEq(completionsEqual(frame.eval('f()'), { return: '7' }), true); |
michael@0 | 116 | assertEq(log, "eeeeeeeee(((((((((ddddddddd)r1)r2)t3)r4)x)t5)t6)x)x"); |
michael@0 | 117 | |
michael@0 | 118 | dbg0.log += '.'; |
michael@0 | 119 | }; |
michael@0 | 120 | |
michael@0 | 121 | dbg0.log = ''; |
michael@0 | 122 | g.eval('eval'); |
michael@0 | 123 | assertEq(dbg0.log, '(.'); |
michael@0 | 124 | |
michael@0 | 125 | // Check that all Debugger.Frame instances we ran into are now marked as dead. |
michael@0 | 126 | for (var i = 0; i < frames.length; i++) |
michael@0 | 127 | assertEq(frames[i].live, false); |