js/src/jit-test/tests/debug/Frame-onPop-multiple-01.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial