async-chains.js 2.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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 69 70 71 72 73 74 75 76 77
// Copyright 2017 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.

let {session, contextGroup, Protocol} = InspectorTest.start(
  'Tests different combinations of async stacks in chains.');

contextGroup.addScript(`
function runWithRegular(f, name) {
  inspector.scheduleWithAsyncStack(f, name, false);
}

function runWithEmptyName(f) {
  inspector.scheduleWithAsyncStack(f, '', false);
}

function runWithEmptyStack(f, name) {
  inspector.scheduleWithAsyncStack(f, name, true);
}

function runWithEmptyNameEmptyStack(f) {
  inspector.scheduleWithAsyncStack(f, '', true);
}

function runWithExternal(f) {
  const id = inspector.storeCurrentStackTrace('external');
  runWithRegular(() => {
    inspector.externalAsyncTaskStarted(id);
    f();
    inspector.externalAsyncTaskFinished(id);
  }, 'not-used-async');
}

function runWithNone(f) {
  f();
}
//# sourceURL=utils.js`);

session.setupScriptMap();
(async function test() {
  Protocol.Debugger.enable();
  Protocol.Debugger.setAsyncCallStackDepth({maxDepth: 128});

  const first = ['Regular', 'EmptyName', 'EmptyStack', 'EmptyNameEmptyStack', 'External']
  const second = ['None', 'Regular', 'EmptyName', 'EmptyStack', 'EmptyNameEmptyStack', 'External']

  for (const stack1 of first) {
    for (const stack2 of second) {
      if (stack1 === 'External' && stack2 !== 'None') continue;

      InspectorTest.log(stack2 === 'None' ? stack1 : `${stack1} - ${stack2}`);
      Protocol.Runtime.evaluate({
        expression: `
          var userFunction = () => {debugger};
          var inner = () => runWith${stack1}(userFunction, 'inner async');
          runWith${stack2}(inner, 'outer async');
          //# sourceURL=test.js`
      });
      await pauseAndDumpStack();
    }
  }

  await Protocol.Debugger.disable();
  InspectorTest.completeTest();
})();

async function pauseAndDumpStack() {
  const {params:{callFrames, asyncStackTrace, asyncStackTraceId}}
      = await Protocol.Debugger.oncePaused();
  session.logCallFrames(callFrames);
  if (asyncStackTrace)
    session.logAsyncStackTrace(asyncStackTrace);
  if (asyncStackTraceId)
    InspectorTest.log('  <external stack>');
  InspectorTest.log('');
  return Protocol.Debugger.resume();
}