summaryrefslogtreecommitdiff
path: root/lib/internal/util/inspector.js
blob: 3dd73415ded862687f308c5c97bb9991fc13f5ff (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
26
27
'use strict';

// TODO(addaleax): Figure out how to integrate the inspector with workers.
const hasInspector = process.config.variables.v8_enable_inspector === 1 &&
  require('internal/worker').isMainThread;
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
};