• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3common.skipIfInspectorDisabled();
4common.skipIf32Bits();
5const { NodeInstance } = require('../common/inspector-helper.js');
6const assert = require('assert');
7
8// Even with --inspect, the default async call stack depth is 0. We need a
9// chance to call Debugger.setAsyncCallStackDepth *before* activating the timer
10// for async stack traces to work.
11const script = `
12process._rawDebug('Waiting until the inspector is activated...');
13const waiting = setInterval(() => { debugger; }, 50);
14
15// This function is called by the inspector client (session)
16function setupTimeoutWithBreak() {
17  clearInterval(waiting);
18  process._rawDebug('Debugger ready, setting up timeout with a break');
19  setTimeout(() => { debugger; }, 50);
20}
21`;
22
23async function waitForInitialSetup(session) {
24  console.error('[test]', 'Waiting for initial setup');
25  await session.waitForBreakOnLine(2, '[eval]');
26}
27
28async function setupTimeoutForStackTrace(session) {
29  console.error('[test]', 'Setting up timeout for async stack trace');
30  await session.send([
31    { 'method': 'Runtime.evaluate',
32      'params': { expression: 'setupTimeoutWithBreak()' } },
33    { 'method': 'Debugger.resume' },
34  ]);
35}
36
37async function checkAsyncStackTrace(session) {
38  console.error('[test]', 'Verify basic properties of asyncStackTrace');
39  const paused = await session.waitForBreakOnLine(8, '[eval]');
40  assert(paused.params.asyncStackTrace,
41         `${Object.keys(paused.params)} contains "asyncStackTrace" property`);
42  assert(paused.params.asyncStackTrace.description, 'Timeout');
43  assert(paused.params.asyncStackTrace.callFrames
44           .some((frame) => frame.functionName === 'setupTimeoutWithBreak'));
45}
46
47async function runTests() {
48  const instance = new NodeInstance(['--inspect=0'], script);
49  const session = await instance.connectInspectorSession();
50  await session.send([
51    { 'method': 'Runtime.enable' },
52    { 'method': 'Debugger.enable' },
53    { 'method': 'Debugger.setAsyncCallStackDepth',
54      'params': { 'maxDepth': 10 } },
55    { 'method': 'Debugger.setBlackboxPatterns',
56      'params': { 'patterns': [] } },
57    { 'method': 'Runtime.runIfWaitingForDebugger' },
58  ]);
59
60  await waitForInitialSetup(session);
61  await setupTimeoutForStackTrace(session);
62  await checkAsyncStackTrace(session);
63
64  console.error('[test]', 'Stopping child instance');
65  session.disconnect();
66  instance.kill();
67}
68
69runTests();
70