async-instrumentation.js 1.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

print('Checks async instrumentation enabled in the middle.');

InspectorTest.addScript(`
function foo() {
  // asyncTaskStarted
  debugger;
  // asyncTaskFinished
  debugger;
}

function test() {
16
  debugger;
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  var resolve1;
  var p1 = new Promise(resolve => resolve1 = resolve);
  var p2 = p1.then(foo);
  resolve1(); // asyncTaskScheduled
  debugger;
  return p2;
}

//# sourceURL=test.js`, 7, 26);

InspectorTest.setupScriptMap();
Protocol.Debugger.onPaused(message => {
  if (enableOnPause-- === 0)
    Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 128 });
  InspectorTest.logCallFrames(message.params.callFrames);
  var asyncStackTrace = message.params.asyncStackTrace;
  while (asyncStackTrace) {
    InspectorTest.log(`-- ${asyncStackTrace.description} --`);
    InspectorTest.logCallFrames(asyncStackTrace.callFrames);
    asyncStackTrace = asyncStackTrace.parent;
  }
  InspectorTest.log('');
  Protocol.Debugger.resume();
});

Protocol.Debugger.enable();
var enableOnPause = 0;
InspectorTest.runTestSuite([
  function beforeAsyncTaskScheduled(next) {
    enableOnPause = 0;
    Protocol.Runtime.evaluate({ expression: 'test()//# sourceURL=expr1.js',
        awaitPromise: true })
      .then(() => Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 0 }))
      .then(next);
  },

  function afterAsyncTaskScheduled(next) {
    enableOnPause = 2;
    Protocol.Runtime.evaluate({ expression: 'test()//# sourceURL=expr1.js',
        awaitPromise: true })
      .then(() => Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 0 }))
      .then(next);
  },

  function afterAsyncTaskStarted(next) {
    enableOnPause = 3;
    Protocol.Runtime.evaluate({ expression: 'test()//# sourceURL=expr1.js',
        awaitPromise: true })
      .then(() => Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 0 }))
      .then(next);
  }
]);