node/lib/internal/util/inspector.js
Michaël Zasso 416c0ec952 repl: show lexically scoped vars in tab completion
Use the V8 inspector protocol, if available, to query the list of
lexically scoped variables (defined with `let`, `const` or `class`).

PR-URL: https://github.com/nodejs/node/pull/16591
Fixes: https://github.com/nodejs/node/issues/983
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2017-12-21 14:47:29 +01:00

26 lines
525 B
JavaScript

'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
};