• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3common.skipIfInspectorDisabled();
4const assert = require('assert');
5const { NodeInstance } = require('../common/inspector-helper.js');
6const fixtures = require('../common/fixtures');
7const { pathToFileURL } = require('url');
8
9const script = fixtures.path('inspector-global-function.js');
10
11async function setupDebugger(session) {
12  console.log('[test]', 'Setting up a debugger');
13  const commands = [
14    { 'method': 'Runtime.enable' },
15    { 'method': 'Debugger.enable' },
16    { 'method': 'Debugger.setAsyncCallStackDepth',
17      'params': { 'maxDepth': 0 } },
18    { 'method': 'Runtime.runIfWaitingForDebugger' },
19  ];
20  session.send(commands);
21
22  await session.waitForNotification('Debugger.paused', 'Initial pause');
23
24  // NOTE(mmarchini): We wait for the second console.log to ensure we loaded
25  // every internal module before pausing. See
26  // https://bugs.chromium.org/p/v8/issues/detail?id=10287.
27  const waitForReady = session.waitForConsoleOutput('log', 'Ready!');
28  session.send({ 'method': 'Debugger.resume' });
29  await waitForReady;
30}
31
32async function breakOnLine(session) {
33  console.log('[test]', 'Breaking in the code');
34  const commands = [
35    { 'method': 'Debugger.setBreakpointByUrl',
36      'params': { 'lineNumber': 9,
37                  'url': pathToFileURL(script).toString(),
38                  'columnNumber': 0,
39                  'condition': ''
40      }
41    },
42    { 'method': 'Runtime.evaluate',
43      'params': { 'expression': 'sum()',
44                  'objectGroup': 'console',
45                  'includeCommandLineAPI': true,
46                  'silent': false,
47                  'contextId': 1,
48                  'returnByValue': false,
49                  'generatePreview': true,
50                  'userGesture': true,
51                  'awaitPromise': false
52      }
53    }
54  ];
55  session.send(commands);
56  await session.waitForBreakOnLine(9, pathToFileURL(script).toString());
57}
58
59async function stepOverConsoleStatement(session) {
60  console.log('[test]', 'Step over console statement and test output');
61  session.send({ 'method': 'Debugger.stepOver' });
62  await session.waitForConsoleOutput('log', [0, 3]);
63  await session.waitForNotification('Debugger.paused');
64}
65
66async function runTests() {
67  // NOTE(mmarchini): Use --inspect-brk to improve avoid undeterministic
68  // behavior.
69  const child = new NodeInstance(['--inspect-brk=0'], undefined, script);
70  const session = await child.connectInspectorSession();
71  await setupDebugger(session);
72  await breakOnLine(session);
73  await stepOverConsoleStatement(session);
74  await session.runToCompletion();
75  assert.strictEqual((await child.expectShutdown()).exitCode, 0);
76}
77
78runTests().then(common.mustCall());
79