summaryrefslogtreecommitdiff
path: root/lib/internal/util/inspector.js
blob: 634d330233358491c5a7f17c19fe96ab1547f3d6 (plain)
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
'use strict';

const hasInspector = process.config.variables.v8_enable_inspector === 1;
const inspector = hasInspector ? require('inspector') : undefined;

let session;

function sendInspectorCommand(cb, onError) {
  if (!hasInspector) return onError();
  if (session === undefined) session = new inspector.Session();
  try {
    session.connect();
    try {
      return cb(session);
    } finally {
      session.disconnect();
    }
  } catch (e) {
    return onError();
  }
}

module.exports = {
  sendInspectorCommand
};